[netatmo] Improve channel helpers (#12851)

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2022-06-11 20:08:10 +02:00 committed by GitHub
parent bf6d508c61
commit 8339faad47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 303 additions and 496 deletions

View File

@ -112,13 +112,8 @@ public class NetatmoHandlerFactory extends BaseThingHandlerFactory {
CommonInterface handler = moduleType.isABridge() ? new DeviceHandler((Bridge) thing) : new ModuleHandler(thing);
List<ChannelHelper> helpers = new ArrayList<>();
moduleType.channelHelpers.forEach(helperClass -> {
try {
helpers.add(helperClass.getConstructor().newInstance());
} catch (ReflectiveOperationException e) {
logger.warn("Error creating or initializing helper class : {}", e.getMessage());
}
});
moduleType.channelGroups
.forEach(channelGroup -> channelGroup.getHelperInstance().ifPresent(helper -> helpers.add(helper)));
moduleType.capabilities.forEach(capability -> {
Capability newCap = null;

View File

@ -0,0 +1,97 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.api.data;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
import org.openhab.binding.netatmo.internal.handler.channelhelper.AirQualityChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.BatteryChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.EventChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.HumidityChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.LocationChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.MeasuresChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.NoiseChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.SignalChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.TemperatureChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.TimestampChannelHelper;
import org.openhab.binding.netatmo.internal.providers.NetatmoThingTypeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link ChannelGroup} makes the link between a channel helper and some group types. It also
* defines some standard and common channel groups used by more than one thing.
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class ChannelGroup {
public static final ChannelGroup SIGNAL = new ChannelGroup(SignalChannelHelper.class, GROUP_SIGNAL);
public static final ChannelGroup EVENT = new ChannelGroup(EventChannelHelper.class, GROUP_LAST_EVENT);
public static final ChannelGroup MEASURE = new ChannelGroup(MeasuresChannelHelper.class);
public static final ChannelGroup BATTERY = new ChannelGroup(BatteryChannelHelper.class, GROUP_BATTERY);
public static final ChannelGroup LOCATION = new ChannelGroup(LocationChannelHelper.class, GROUP_LOCATION);
public static final ChannelGroup BATTERY_EXT = new ChannelGroup(BatteryChannelHelper.class,
GROUP_TYPE_BATTERY_EXTENDED);
public static final ChannelGroup TSTAMP_EXT = new ChannelGroup(TimestampChannelHelper.class,
GROUP_TYPE_TIMESTAMP_EXTENDED);
public static final ChannelGroup TEMP_OUTSIDE_EXT = new ChannelGroup(TemperatureChannelHelper.class,
MeasureClass.OUTSIDE_TEMPERATURE, GROUP_TYPE_TEMPERATURE_OUTSIDE);
public static final ChannelGroup TEMP_INSIDE_EXT = new ChannelGroup(TemperatureChannelHelper.class,
MeasureClass.INSIDE_TEMPERATURE, GROUP_TYPE_TEMPERATURE_EXTENDED);
public static final ChannelGroup TEMP_INSIDE = new ChannelGroup(TemperatureChannelHelper.class,
MeasureClass.INSIDE_TEMPERATURE, GROUP_TEMPERATURE);
public static final ChannelGroup AIR_QUALITY = new ChannelGroup(AirQualityChannelHelper.class, MeasureClass.CO2,
GROUP_AIR_QUALITY);
public static final ChannelGroup NOISE = new ChannelGroup(NoiseChannelHelper.class, MeasureClass.NOISE,
GROUP_NOISE);
public static final ChannelGroup HUMIDITY = new ChannelGroup(HumidityChannelHelper.class, MeasureClass.HUMIDITY,
GROUP_HUMIDITY);
private final Logger logger = LoggerFactory.getLogger(ChannelGroup.class);
private final Class<? extends ChannelHelper> helper;
public final Set<String> groupTypes;
public final Set<String> extensions;
ChannelGroup(Class<? extends ChannelHelper> helper, String... groupTypes) {
this(helper, Set.of(), groupTypes);
}
ChannelGroup(Class<? extends ChannelHelper> helper, MeasureClass measureClass, String... groupTypes) {
this(helper, measureClass.channels.keySet(), groupTypes);
}
private ChannelGroup(Class<? extends ChannelHelper> helper, Set<String> extensions, String... groupTypes) {
this.helper = helper;
this.groupTypes = Set.of(groupTypes);
this.extensions = extensions;
}
public Optional<ChannelHelper> getHelperInstance() {
try {
return Optional.of(helper.getConstructor(Set.class).newInstance(
groupTypes.stream().map(NetatmoThingTypeProvider::toGroupName).collect(Collectors.toSet())));
} catch (ReflectiveOperationException e) {
logger.warn("Error creating or initializing helper class : {}", e.getMessage());
}
return Optional.empty();
}
}

View File

@ -12,17 +12,19 @@
*/
package org.openhab.binding.netatmo.internal.api.data;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.BINDING_ID;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.*;
import java.net.URI;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
import org.openhab.binding.netatmo.internal.handler.capability.AirCareCapability;
import org.openhab.binding.netatmo.internal.handler.capability.CameraCapability;
import org.openhab.binding.netatmo.internal.handler.capability.Capability;
@ -36,36 +38,20 @@ import org.openhab.binding.netatmo.internal.handler.capability.PresenceCapabilit
import org.openhab.binding.netatmo.internal.handler.capability.RoomCapability;
import org.openhab.binding.netatmo.internal.handler.capability.WeatherCapability;
import org.openhab.binding.netatmo.internal.handler.channelhelper.AirQualityChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.AirQualityExtChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.BatteryChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.BatteryExtChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.CameraChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.DoorbellChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.EventChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.EnergyChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.EventDoorbellChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.EventPersonChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.HomeEnergyChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.HomeSecurityChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.HumidityChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.LocationChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.MeasuresChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.NoiseChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.PersonChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.PresenceChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.PressureChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.PressureExtChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.RainChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.RoomChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.SecurityChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.SetpointChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.SignalChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.SirenChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.TemperatureChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.TemperatureExtChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.TemperatureOutChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.Therm1ChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.TimestampChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.TimestampExtChannelHelper;
import org.openhab.binding.netatmo.internal.handler.channelhelper.WindChannelHelper;
import org.openhab.core.thing.ThingTypeUID;
@ -76,111 +62,102 @@ import org.openhab.core.thing.ThingTypeUID;
*/
@NonNullByDefault
public enum ModuleType {
UNKNOWN(FeatureArea.NONE, "", null, List.of(), List.of()),
ACCOUNT(FeatureArea.NONE, "", null, List.of(), List.of()),
UNKNOWN(FeatureArea.NONE, "", null, Set.of()),
ACCOUNT(FeatureArea.NONE, "", null, Set.of()),
HOME(FeatureArea.NONE, "NAHome", ACCOUNT,
List.of(DeviceCapability.class, EventCapability.class, HomeCapability.class, ChannelHelperCapability.class),
List.of(HomeSecurityChannelHelper.class, HomeEnergyChannelHelper.class)),
Set.of(DeviceCapability.class, EventCapability.class, HomeCapability.class, ChannelHelperCapability.class),
new ChannelGroup(SecurityChannelHelper.class, GROUP_SECURITY),
new ChannelGroup(EnergyChannelHelper.class, GROUP_ENERGY)),
PERSON(FeatureArea.SECURITY, "NAPerson", HOME,
List.of(EventCapability.class, PersonCapability.class, ChannelHelperCapability.class),
List.of(PersonChannelHelper.class, EventPersonChannelHelper.class)),
Set.of(EventCapability.class, PersonCapability.class, ChannelHelperCapability.class),
new ChannelGroup(PersonChannelHelper.class, GROUP_PERSON),
new ChannelGroup(EventPersonChannelHelper.class, GROUP_PERSON_LAST_EVENT)),
WELCOME(FeatureArea.SECURITY, "NACamera", HOME,
List.of(EventCapability.class, CameraCapability.class, ChannelHelperCapability.class),
List.of(CameraChannelHelper.class, SignalChannelHelper.class, EventChannelHelper.class)),
Set.of(EventCapability.class, CameraCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.EVENT, new ChannelGroup(CameraChannelHelper.class, GROUP_CAM_STATUS, GROUP_CAM_LIVE)),
SIREN(FeatureArea.SECURITY, "NIS", WELCOME, List.of(ChannelHelperCapability.class),
List.of(SirenChannelHelper.class, BatteryChannelHelper.class, TimestampChannelHelper.class,
SignalChannelHelper.class)),
SIREN(FeatureArea.SECURITY, "NIS", WELCOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY, new ChannelGroup(TimestampChannelHelper.class, GROUP_TIMESTAMP),
new ChannelGroup(SirenChannelHelper.class, GROUP_SIREN)),
PRESENCE(FeatureArea.SECURITY, "NOC", HOME,
List.of(EventCapability.class, PresenceCapability.class, ChannelHelperCapability.class),
List.of(PresenceChannelHelper.class, SignalChannelHelper.class, EventChannelHelper.class)),
Set.of(EventCapability.class, PresenceCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.EVENT,
new ChannelGroup(PresenceChannelHelper.class, GROUP_CAM_STATUS, GROUP_CAM_LIVE, GROUP_PRESENCE)),
DOORBELL(FeatureArea.SECURITY, "NDB", HOME,
List.of(EventCapability.class, CameraCapability.class, ChannelHelperCapability.class),
List.of(DoorbellChannelHelper.class, SignalChannelHelper.class, EventDoorbellChannelHelper.class)),
Set.of(EventCapability.class, CameraCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
new ChannelGroup(CameraChannelHelper.class, GROUP_DOORBELL_STATUS, GROUP_DOORBELL_LIVE),
new ChannelGroup(EventDoorbellChannelHelper.class, GROUP_DOORBELL_LAST_EVENT, GROUP_DOORBELL_SUB_EVENT)),
WEATHER_STATION(FeatureArea.WEATHER, "NAMain", ACCOUNT,
List.of(DeviceCapability.class, WeatherCapability.class, MeasureCapability.class,
Set.of(DeviceCapability.class, WeatherCapability.class, MeasureCapability.class,
ChannelHelperCapability.class),
List.of(PressureExtChannelHelper.class, NoiseChannelHelper.class, HumidityChannelHelper.class,
TemperatureExtChannelHelper.class, AirQualityChannelHelper.class, LocationChannelHelper.class,
TimestampExtChannelHelper.class, MeasuresChannelHelper.class, SignalChannelHelper.class)),
ChannelGroup.SIGNAL, ChannelGroup.HUMIDITY, ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE,
ChannelGroup.AIR_QUALITY, ChannelGroup.LOCATION, ChannelGroup.NOISE, ChannelGroup.TEMP_INSIDE_EXT,
new ChannelGroup(PressureChannelHelper.class, MeasureClass.PRESSURE, GROUP_TYPE_PRESSURE_EXTENDED)),
OUTDOOR(FeatureArea.WEATHER, "NAModule1", WEATHER_STATION,
List.of(MeasureCapability.class, ChannelHelperCapability.class),
List.of(HumidityChannelHelper.class, TemperatureOutChannelHelper.class, BatteryChannelHelper.class,
MeasuresChannelHelper.class, TimestampExtChannelHelper.class, SignalChannelHelper.class)),
Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL, ChannelGroup.HUMIDITY,
ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY, ChannelGroup.TEMP_OUTSIDE_EXT),
WIND(FeatureArea.WEATHER, "NAModule2", WEATHER_STATION, List.of(ChannelHelperCapability.class),
List.of(WindChannelHelper.class, BatteryChannelHelper.class, TimestampExtChannelHelper.class,
SignalChannelHelper.class)),
WIND(FeatureArea.WEATHER, "NAModule2", WEATHER_STATION, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.TSTAMP_EXT, ChannelGroup.BATTERY, new ChannelGroup(WindChannelHelper.class, GROUP_WIND)),
RAIN(FeatureArea.WEATHER, "NAModule3", WEATHER_STATION,
List.of(MeasureCapability.class, ChannelHelperCapability.class),
List.of(RainChannelHelper.class, BatteryChannelHelper.class, MeasuresChannelHelper.class,
TimestampExtChannelHelper.class, SignalChannelHelper.class)),
Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY,
new ChannelGroup(RainChannelHelper.class, MeasureClass.RAIN_QUANTITY, GROUP_RAIN)),
INDOOR(FeatureArea.WEATHER, "NAModule4", WEATHER_STATION,
List.of(MeasureCapability.class, ChannelHelperCapability.class),
List.of(HumidityChannelHelper.class, TemperatureExtChannelHelper.class, AirQualityChannelHelper.class,
BatteryChannelHelper.class, MeasuresChannelHelper.class, TimestampExtChannelHelper.class,
SignalChannelHelper.class)),
Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY, ChannelGroup.HUMIDITY,
ChannelGroup.TEMP_INSIDE_EXT, ChannelGroup.AIR_QUALITY),
HOME_COACH(FeatureArea.AIR_CARE, "NHC", ACCOUNT,
List.of(DeviceCapability.class, AirCareCapability.class, MeasureCapability.class,
Set.of(DeviceCapability.class, AirCareCapability.class, MeasureCapability.class,
ChannelHelperCapability.class),
List.of(NoiseChannelHelper.class, HumidityChannelHelper.class, AirQualityExtChannelHelper.class,
TemperatureChannelHelper.class, PressureChannelHelper.class, TimestampExtChannelHelper.class,
SignalChannelHelper.class, MeasuresChannelHelper.class, LocationChannelHelper.class)),
ChannelGroup.LOCATION, ChannelGroup.SIGNAL, ChannelGroup.NOISE, ChannelGroup.HUMIDITY,
ChannelGroup.TEMP_INSIDE, ChannelGroup.MEASURE, ChannelGroup.TSTAMP_EXT,
new ChannelGroup(AirQualityChannelHelper.class, GROUP_TYPE_AIR_QUALITY_EXTENDED),
new ChannelGroup(PressureChannelHelper.class, MeasureClass.PRESSURE, GROUP_PRESSURE)),
PLUG(FeatureArea.ENERGY, "NAPlug", HOME, List.of(ChannelHelperCapability.class),
List.of(SignalChannelHelper.class)),
PLUG(FeatureArea.ENERGY, "NAPlug", HOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL),
VALVE(FeatureArea.ENERGY, "NRV", PLUG, List.of(ChannelHelperCapability.class),
List.of(BatteryExtChannelHelper.class, SignalChannelHelper.class)),
VALVE(FeatureArea.ENERGY, "NRV", PLUG, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY_EXT),
THERMOSTAT(FeatureArea.ENERGY, "NATherm1", PLUG, List.of(ChannelHelperCapability.class),
List.of(Therm1ChannelHelper.class, BatteryExtChannelHelper.class, SignalChannelHelper.class)),
THERMOSTAT(FeatureArea.ENERGY, "NATherm1", PLUG, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY_EXT, new ChannelGroup(Therm1ChannelHelper.class, GROUP_TYPE_TH_PROPERTIES)),
ROOM(FeatureArea.ENERGY, "NARoom", HOME, List.of(RoomCapability.class, ChannelHelperCapability.class),
List.of(RoomChannelHelper.class, SetpointChannelHelper.class));
ROOM(FeatureArea.ENERGY, "NARoom", HOME, Set.of(RoomCapability.class, ChannelHelperCapability.class),
new ChannelGroup(RoomChannelHelper.class, GROUP_TYPE_ROOM_PROPERTIES, GROUP_TYPE_ROOM_TEMPERATURE),
new ChannelGroup(SetpointChannelHelper.class, GROUP_SETPOINT));
public static final EnumSet<ModuleType> AS_SET = EnumSet.allOf(ModuleType.class);
private final @Nullable ModuleType bridgeType;
public final List<String> groupTypes = new LinkedList<>();
public final List<String> extensions = new LinkedList<>();
public final List<Class<? extends ChannelHelper>> channelHelpers;
public final List<Class<? extends Capability>> capabilities;
public final Set<ChannelGroup> channelGroups;
public final Set<Class<? extends Capability>> capabilities;
public final ThingTypeUID thingTypeUID;
public final FeatureArea feature;
public final String apiName;
ModuleType(FeatureArea feature, String apiName, @Nullable ModuleType bridge,
List<Class<? extends Capability>> capabilities, List<Class<? extends ChannelHelper>> helpers) {
this.channelHelpers = helpers;
Set<Class<? extends Capability>> capabilities, ChannelGroup... channelGroups) {
this.bridgeType = bridge;
this.feature = feature;
this.capabilities = capabilities;
this.apiName = apiName;
thingTypeUID = new ThingTypeUID(BINDING_ID, name().toLowerCase().replace("_", "-"));
try {
for (Class<? extends ChannelHelper> helperClass : helpers) {
ChannelHelper helper = helperClass.getConstructor().newInstance();
groupTypes.addAll(helper.getChannelGroupTypes());
extensions.addAll(helper.getExtensibleChannels());
}
} catch (RuntimeException | ReflectiveOperationException e) {
throw new IllegalArgumentException(e);
}
this.channelGroups = Set.of(channelGroups);
this.thingTypeUID = new ThingTypeUID(BINDING_ID, name().toLowerCase().replace("_", "-"));
}
public boolean isLogical() {
return !channelHelpers.contains(SignalChannelHelper.class);
return !channelGroups.contains(ChannelGroup.SIGNAL);
}
public boolean isABridge() {
@ -192,11 +169,19 @@ public enum ModuleType {
return false;
}
public List<String> getExtensions() {
return channelGroups.stream().map(cg -> cg.extensions).flatMap(Set::stream).collect(Collectors.toList());
}
public Set<String> getGroupTypes() {
return channelGroups.stream().map(cg -> cg.groupTypes).flatMap(Set::stream).collect(Collectors.toSet());
}
public int[] getSignalLevels() {
if (!isLogical()) {
return (channelHelpers.contains(BatteryChannelHelper.class)
|| channelHelpers.contains(BatteryExtChannelHelper.class)) ? RADIO_SIGNAL_LEVELS
: WIFI_SIGNAL_LEVELS;
return (channelGroups.contains(ChannelGroup.BATTERY) || channelGroups.contains(ChannelGroup.BATTERY_EXT))
? RADIO_SIGNAL_LEVELS
: WIFI_SIGNAL_LEVELS;
}
throw new IllegalArgumentException(
"This should not be called for module type : " + name() + ", please file a bug report.");

View File

@ -15,10 +15,13 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toQuantityType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.types.State;
/**
@ -30,16 +33,18 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class AirQualityChannelHelper extends ChannelHelper {
public AirQualityChannelHelper() {
this(GROUP_AIR_QUALITY);
}
protected AirQualityChannelHelper(String groupName) {
super(groupName, MeasureClass.CO2);
public AirQualityChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
return CHANNEL_CO2.equals(channelId) ? toQuantityType(dashboard.getCo2(), MeasureClass.CO2) : null;
switch (channelId) {
case CHANNEL_CO2:
return toQuantityType(dashboard.getCo2(), MeasureClass.CO2);
case CHANNEL_HEALTH_INDEX:
return new DecimalType(dashboard.getHealthIdx());
}
return null;
}
}

View File

@ -1,41 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.types.State;
/**
* The {@link AirQualityExtChannelHelper} handles specific channels of NHC thing.
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class AirQualityExtChannelHelper extends AirQualityChannelHelper {
public AirQualityExtChannelHelper() {
super(GROUP_TYPE_AIR_QUALITY_EXTENDED);
}
@Override
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
return CHANNEL_HEALTH_INDEX.equals(channelId) ? new DecimalType(dashboard.getHealthIdx())
: super.internalGetDashboard(channelId, dashboard);
}
}

View File

@ -13,9 +13,13 @@
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.BatteryState;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
import org.openhab.binding.netatmo.internal.api.dto.Module;
import org.openhab.binding.netatmo.internal.api.dto.NAThing;
@ -33,22 +37,22 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class BatteryChannelHelper extends ChannelHelper {
public BatteryChannelHelper() {
super(GROUP_BATTERY);
}
protected BatteryChannelHelper(String groupName) {
super(groupName);
public BatteryChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override
protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
int percent = -1;
BatteryState batteryState = BatteryState.UNKNOWN;
if (naThing instanceof Module) {
percent = ((Module) naThing).getBatteryPercent();
}
if (naThing instanceof HomeStatusModule) {
batteryState = ((Module) naThing).getBatteryState();
} else if (naThing instanceof HomeStatusModule) {
percent = ((HomeStatusModule) naThing).getBatteryState().level;
batteryState = ((HomeStatusModule) naThing).getBatteryState();
} else {
return null;
}
switch (channelId) {
case CHANNEL_VALUE:
@ -59,6 +63,8 @@ public class BatteryChannelHelper extends ChannelHelper {
if (percent >= 0) {
return OnOffType.from(percent < 20);
}
case CHANNEL_BATTERY_STATUS:
return toStringType(batteryState);
}
return null;
}

View File

@ -1,52 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
import org.openhab.binding.netatmo.internal.api.dto.Module;
import org.openhab.binding.netatmo.internal.api.dto.NAThing;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.types.State;
/**
* The {@link BatteryExtChannelHelper} handles specific channels of modules using batteries
* having battery status information available on top of standard information
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class BatteryExtChannelHelper extends BatteryChannelHelper {
public BatteryExtChannelHelper() {
super(GROUP_TYPE_BATTERY_EXTENDED);
}
@Override
protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
if (CHANNEL_BATTERY_STATUS.equals(channelId)) {
if (naThing instanceof Module) {
return toStringType(((Module) naThing).getBatteryState());
}
if (naThing instanceof HomeStatusModule) {
return toStringType(((HomeStatusModule) naThing).getBatteryState());
}
}
return super.internalGetProperty(channelId, naThing, config);
}
}

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
@ -38,11 +40,7 @@ public class CameraChannelHelper extends ChannelHelper {
private @Nullable String vpnUrl;
private @Nullable String localUrl;
public CameraChannelHelper() {
this(GROUP_CAM_STATUS, GROUP_CAM_LIVE);
}
protected CameraChannelHelper(String... providedGroups) {
public CameraChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}

View File

@ -12,18 +12,15 @@
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.binding.netatmo.internal.api.dto.Event;
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
import org.openhab.binding.netatmo.internal.api.dto.NAThing;
import org.openhab.binding.netatmo.internal.providers.NetatmoThingTypeProvider;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.types.State;
@ -35,19 +32,12 @@ import org.openhab.core.types.State;
*/
@NonNullByDefault
public abstract class ChannelHelper {
private final Set<String> channelGroups;
private @Nullable NAObject data;
private final Set<String> channelGroupTypes;
private final Set<String> channelGroups = new HashSet<>();
private Set<String> extensibleChannels = Set.of();
ChannelHelper(String... providedGroups) {
this.channelGroupTypes = Set.of(providedGroups);
channelGroupTypes.forEach(groupType -> channelGroups.add(NetatmoThingTypeProvider.toGroupName(groupType)));
}
ChannelHelper(String providedGroup, MeasureClass measureClass) {
this(providedGroup);
this.extensibleChannels = measureClass.channels.keySet();
public ChannelHelper(Set<String> providedGroups) {
channelGroups = providedGroups;
}
public void setNewData(@Nullable NAObject data) {
@ -118,12 +108,4 @@ public abstract class ChannelHelper {
protected @Nullable State internalGetHomeEvent(String channelId, @Nullable String groupId, HomeEvent event) {
return null;
}
public Set<String> getChannelGroupTypes() {
return channelGroupTypes;
}
public Set<String> getExtensibleChannels() {
return extensibleChannels;
}
}

View File

@ -1,31 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link DoorbellChannelHelper} handles specific channels of doorbells
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class DoorbellChannelHelper extends CameraChannelHelper {
public DoorbellChannelHelper() {
super(GROUP_DOORBELL_STATUS, GROUP_DOORBELL_LIVE);
}
}

View File

@ -19,6 +19,7 @@ import java.time.DayOfWeek;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -35,16 +36,16 @@ import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
/**
* The {@link HomeEnergyChannelHelper} handles specific channels of thermostat settings at home level.
* The {@link EnergyChannelHelper} handles specific channels of thermostat settings at home level.
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class HomeEnergyChannelHelper extends ChannelHelper {
public class EnergyChannelHelper extends ChannelHelper {
public HomeEnergyChannelHelper() {
super(GROUP_ENERGY);
public EnergyChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.ModuleType;
@ -38,11 +40,7 @@ public class EventChannelHelper extends ChannelHelper {
private @Nullable String vpnUrl, localUrl;
protected ModuleType moduleType = ModuleType.UNKNOWN;
public EventChannelHelper() {
this(GROUP_LAST_EVENT);
}
protected EventChannelHelper(String... providedGroups) {
public EventChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
@ -30,8 +32,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class EventDoorbellChannelHelper extends EventChannelHelper {
public EventDoorbellChannelHelper() {
super(GROUP_DOORBELL_LAST_EVENT, GROUP_DOORBELL_SUB_EVENT);
public EventDoorbellChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_PERSON_AT_HOME;
import java.util.Set;
@ -32,8 +32,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class EventPersonChannelHelper extends EventChannelHelper {
public EventPersonChannelHelper() {
super(GROUP_PERSON_LAST_EVENT);
public EventPersonChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -16,6 +16,8 @@ import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toQuantityType;
import static org.openhab.binding.netatmo.internal.utils.WeatherUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
@ -32,8 +34,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class HumidityChannelHelper extends ChannelHelper {
public HumidityChannelHelper() {
super(GROUP_HUMIDITY, MeasureClass.HUMIDITY);
public HumidityChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -12,7 +12,9 @@
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_VALUE;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -32,8 +34,8 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class LocationChannelHelper extends ChannelHelper {
public LocationChannelHelper() {
super(GROUP_LOCATION);
public LocationChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -13,6 +13,7 @@
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -29,6 +30,10 @@ import org.openhab.core.types.State;
public class MeasuresChannelHelper extends ChannelHelper {
private @Nullable Map<String, State> measures;
public MeasuresChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
public void setMeasures(Map<String, State> measures) {
this.measures = measures;
}

View File

@ -12,9 +12,11 @@
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_VALUE;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toQuantityType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
@ -30,8 +32,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class NoiseChannelHelper extends ChannelHelper {
public NoiseChannelHelper() {
super(GROUP_NOISE, MeasureClass.NOISE);
public NoiseChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.HomeDataPerson;
@ -33,8 +35,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class PersonChannelHelper extends ChannelHelper {
public PersonChannelHelper() {
super(GROUP_PERSON);
public PersonChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -12,9 +12,11 @@
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_FLOODLIGHT;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
@ -31,8 +33,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class PresenceChannelHelper extends CameraChannelHelper {
public PresenceChannelHelper() {
super(GROUP_CAM_STATUS, GROUP_CAM_LIVE, GROUP_PRESENCE);
public PresenceChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -13,7 +13,9 @@
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toQuantityType;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -30,12 +32,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class PressureChannelHelper extends ChannelHelper {
public PressureChannelHelper() {
this(GROUP_PRESSURE);
}
protected PressureChannelHelper(String groupName) {
super(groupName, MeasureClass.PRESSURE);
public PressureChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override
@ -45,6 +43,8 @@ public class PressureChannelHelper extends ChannelHelper {
return toQuantityType(dashboard.getPressure(), MeasureClass.PRESSURE);
case CHANNEL_ABSOLUTE_PRESSURE:
return toQuantityType(dashboard.getAbsolutePressure(), MeasureClass.PRESSURE);
case CHANNEL_TREND:
return toStringType(dashboard.getPressureTrend());
}
return null;
}

View File

@ -1,42 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.core.types.State;
/**
* The {@link PressureExtChannelHelper} handles specific behavior of modules measuring pressure
* with pressure trend capability
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class PressureExtChannelHelper extends PressureChannelHelper {
public PressureExtChannelHelper() {
super(GROUP_TYPE_PRESSURE_EXTENDED);
}
@Override
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
return channelId.equals(CHANNEL_TREND) ? toStringType(dashboard.getPressureTrend())
: super.internalGetDashboard(channelId, dashboard);
}
}

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toQuantityType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
@ -30,8 +32,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class RainChannelHelper extends ChannelHelper {
public RainChannelHelper() {
super(GROUP_RAIN, MeasureClass.RAIN_QUANTITY);
public RainChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toQuantityType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
@ -32,8 +34,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class RoomChannelHelper extends ChannelHelper {
public RoomChannelHelper() {
super(GROUP_TYPE_ROOM_TEMPERATURE, GROUP_TYPE_ROOM_PROPERTIES);
public RoomChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -16,6 +16,7 @@ import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toRawType;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -30,20 +31,20 @@ import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
/**
* The {@link HomeSecurityChannelHelper} handles specific information for security purpose.
* The {@link SecurityChannelHelper} handles specific information for security purpose.
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class HomeSecurityChannelHelper extends ChannelHelper {
public class SecurityChannelHelper extends ChannelHelper {
private long persons = -1;
private long unknowns = -1;
private @Nullable String unknownSnapshot;
private List<String> knownIds = List.of();
public HomeSecurityChannelHelper() {
super(GROUP_SECURITY);
public SecurityChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
@ -32,8 +34,8 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class SetpointChannelHelper extends ChannelHelper {
public SetpointChannelHelper() {
super(GROUP_SETPOINT);
public SetpointChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toQuantityType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.NAThing;
@ -32,8 +34,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class SignalChannelHelper extends ChannelHelper {
public SignalChannelHelper() {
super(GROUP_SIGNAL);
public SignalChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
@ -32,8 +34,8 @@ import org.openhab.core.types.UnDefType;
@NonNullByDefault
public class SirenChannelHelper extends ChannelHelper {
public SirenChannelHelper() {
super(GROUP_SIREN);
public SirenChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -16,6 +16,8 @@ import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import static org.openhab.binding.netatmo.internal.utils.WeatherUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
@ -30,17 +32,9 @@ import org.openhab.core.types.State;
*/
@NonNullByDefault
public class TemperatureChannelHelper extends ChannelHelper {
/*
* TemperatureChannelHelper may be used by indoor or outdoor modules. There is no easy way here to decide what is
* the handler owning the channelHelper. The usage of OUTSIDE_TEMPERATURE instead of INSIDE_TEMPERATURE is by design
* because OUTSIDE_TEMPERATURE has wide value range than INSIDE_TEMPERATURE.
*/
public TemperatureChannelHelper() {
this(GROUP_TEMPERATURE, MeasureClass.OUTSIDE_TEMPERATURE);
}
protected TemperatureChannelHelper(String groupName, MeasureClass measureClass) {
super(groupName, measureClass);
public TemperatureChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override
@ -66,6 +60,8 @@ public class TemperatureChannelHelper extends ChannelHelper {
double dewPoint = dewPoint(dashboard.getTemperature(), dashboard.getHumidity());
return toQuantityType(dewPointDep(dashboard.getTemperature(), dewPoint),
MeasureClass.OUTSIDE_TEMPERATURE);
case CHANNEL_TREND:
return toStringType(dashboard.getTempTrend());
}
return null;
}

View File

@ -1,42 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.core.types.State;
/**
* The {@link TemperatureExtChannelHelper} handles specific channels of modules measuring temperature
* with temp trend capability
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class TemperatureExtChannelHelper extends TemperatureChannelHelper {
public TemperatureExtChannelHelper() {
super(GROUP_TYPE_TEMPERATURE_EXTENDED, MeasureClass.INSIDE_TEMPERATURE);
}
@Override
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
return CHANNEL_TREND.equals(channelId) ? toStringType(dashboard.getTempTrend())
: super.internalGetDashboard(channelId, dashboard);
}
}

View File

@ -1,42 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.core.types.State;
/**
* The {@link TemperatureOutChannelHelper} handles specific channels of modules measuring temperature
* with temp trend capability
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class TemperatureOutChannelHelper extends TemperatureChannelHelper {
public TemperatureOutChannelHelper() {
super(GROUP_TYPE_TEMPERATURE_OUTSIDE, MeasureClass.OUTSIDE_TEMPERATURE);
}
@Override
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
return CHANNEL_TREND.equals(channelId) ? toStringType(dashboard.getTempTrend())
: super.internalGetDashboard(channelId, dashboard);
}
}

View File

@ -12,7 +12,9 @@
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_THERM_RELAY;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -30,8 +32,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class Therm1ChannelHelper extends ChannelHelper {
public Therm1ChannelHelper() {
super(GROUP_TYPE_TH_PROPERTIES);
public Therm1ChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -17,9 +17,11 @@ import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toDate
import java.time.ZonedDateTime;
import java.util.Optional;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.binding.netatmo.internal.api.dto.NAThing;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.types.State;
@ -34,12 +36,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class TimestampChannelHelper extends ChannelHelper {
public TimestampChannelHelper() {
this(GROUP_TIMESTAMP);
}
protected TimestampChannelHelper(String groupName) {
super(groupName);
public TimestampChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override
@ -47,4 +45,9 @@ public class TimestampChannelHelper extends ChannelHelper {
Optional<ZonedDateTime> lastSeen = naThing.getLastSeen();
return CHANNEL_LAST_SEEN.equals(channelId) && lastSeen.isPresent() ? toDateTimeType(lastSeen) : null;
}
@Override
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
return CHANNEL_MEASURES_TIMESTAMP.equals(channelId) ? toDateTimeType(dashboard.getTimeUtc()) : null;
}
}

View File

@ -1,41 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toDateTimeType;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
import org.openhab.core.types.State;
/**
* The {@link TimestampExtChannelHelper} handles specific behavior
* of modules reporting measurement timestamp in dashboard
*
* @author Gaël L'hopital - Initial contribution
*
*/
@NonNullByDefault
public class TimestampExtChannelHelper extends TimestampChannelHelper {
public TimestampExtChannelHelper() {
super(GROUP_TYPE_TIMESTAMP_EXTENDED);
}
@Override
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
return CHANNEL_MEASURES_TIMESTAMP.equals(channelId) ? toDateTimeType(dashboard.getTimeUtc()) : null;
}
}

View File

@ -15,6 +15,8 @@ package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
@ -30,8 +32,8 @@ import org.openhab.core.types.State;
@NonNullByDefault
public class WindChannelHelper extends ChannelHelper {
public WindChannelHelper() {
super(GROUP_WIND);
public WindChannelHelper(Set<String> providedGroups) {
super(providedGroups);
}
@Override

View File

@ -75,7 +75,7 @@ public class NetatmoThingTypeProvider implements ThingTypeProvider {
ThingTypeBuilder thingTypeBuilder = ThingTypeBuilder.instance(thingTypeUID, thingTypeUID.toString())
.withRepresentationProperty(NAThingConfiguration.ID)
.withExtensibleChannelTypeIds(moduleType.extensions)
.withExtensibleChannelTypeIds(moduleType.getExtensions())
.withChannelGroupDefinitions(getGroupDefinitions(moduleType))
.withConfigDescriptionURI(moduleType.getConfigDescription());
@ -94,8 +94,8 @@ public class NetatmoThingTypeProvider implements ThingTypeProvider {
}
private List<ChannelGroupDefinition> getGroupDefinitions(ModuleType thingType) {
return thingType.groupTypes.stream().map(groupTypeName -> new ChannelGroupDefinition(toGroupName(groupTypeName),
new ChannelGroupTypeUID(BINDING_ID, groupTypeName))).collect(Collectors.toList());
return thingType.getGroupTypes().stream().map(groupType -> new ChannelGroupDefinition(toGroupName(groupType),
new ChannelGroupTypeUID(BINDING_ID, groupType))).collect(Collectors.toList());
}
public static String toGroupName(String groupeTypeName) {