diff --git a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/PowermaxHandlerFactory.java b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/PowermaxHandlerFactory.java index b8f66c7d73819..0c17458af4162 100644 --- a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/PowermaxHandlerFactory.java +++ b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/PowermaxHandlerFactory.java @@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.core.Configuration; import org.eclipse.smarthome.config.discovery.DiscoveryService; +import org.eclipse.smarthome.core.i18n.TimeZoneProvider; import org.eclipse.smarthome.core.thing.Bridge; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingTypeUID; @@ -48,13 +49,16 @@ @Component(service = ThingHandlerFactory.class, configurationPid = "binding.powermax") public class PowermaxHandlerFactory extends BaseThingHandlerFactory { - private final Map> discoveryServiceRegs = new HashMap<>(); + private final Map> discoveryServiceRegs = new HashMap<>(); private final SerialPortManager serialPortManager; + private final TimeZoneProvider timeZoneProvider; @Activate - public PowermaxHandlerFactory(final @Reference SerialPortManager serialPortManager) { + public PowermaxHandlerFactory(final @Reference SerialPortManager serialPortManager, + final @Reference TimeZoneProvider timeZoneProvider) { this.serialPortManager = serialPortManager; + this.timeZoneProvider = timeZoneProvider; } @Override @@ -89,7 +93,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { registerDiscoveryService(handler); return handler; } else if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) { - return new PowermaxThingHandler(thing); + return new PowermaxThingHandler(thing, timeZoneProvider.getTimeZone()); } return null; diff --git a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/discovery/PowermaxDiscoveryService.java b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/discovery/PowermaxDiscoveryService.java index 44da260ca715a..2ddec0f1f7346 100644 --- a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/discovery/PowermaxDiscoveryService.java +++ b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/discovery/PowermaxDiscoveryService.java @@ -21,6 +21,7 @@ import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingUID; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; import org.openhab.binding.powermax.internal.PowermaxBindingConstants; import org.openhab.binding.powermax.internal.config.PowermaxX10Configuration; import org.openhab.binding.powermax.internal.config.PowermaxZoneConfiguration; @@ -112,10 +113,10 @@ private void updateFromZoneSettings(int zoneNumber, PowermaxZoneSettings zoneSet if (zoneSettings != null) { // Prevent for adding already known zone for (Thing thing : bridgeHandler.getThing().getThings()) { + ThingHandler thingHandler = thing.getHandler(); if (thing.getThingTypeUID().equals(PowermaxBindingConstants.THING_TYPE_ZONE) - && thing.getHandler() != null) { - PowermaxZoneConfiguration config = ((PowermaxThingHandler) thing.getHandler()) - .getZoneConfiguration(); + && thingHandler instanceof PowermaxThingHandler) { + PowermaxZoneConfiguration config = ((PowermaxThingHandler) thingHandler).getZoneConfiguration(); if (config.zoneNumber == zoneNumber) { return; } @@ -147,9 +148,10 @@ private void updateFromDeviceSettings(int deviceNumber, PowermaxX10Settings devi if (deviceSettings != null && deviceSettings.isEnabled()) { // Prevent for adding already known X10 device for (Thing thing : bridgeHandler.getThing().getThings()) { + ThingHandler thingHandler = thing.getHandler(); if (thing.getThingTypeUID().equals(PowermaxBindingConstants.THING_TYPE_X10) - && thing.getHandler() != null) { - PowermaxX10Configuration config = ((PowermaxThingHandler) thing.getHandler()).getX10Configuration(); + && thingHandler instanceof PowermaxThingHandler) { + PowermaxX10Configuration config = ((PowermaxThingHandler) thingHandler).getX10Configuration(); if (config.deviceNumber == deviceNumber) { return; } diff --git a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/handler/PowermaxThingHandler.java b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/handler/PowermaxThingHandler.java index 2c3bdac54a2ea..57a3ae82a231f 100644 --- a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/handler/PowermaxThingHandler.java +++ b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/handler/PowermaxThingHandler.java @@ -15,8 +15,8 @@ import static org.openhab.binding.powermax.internal.PowermaxBindingConstants.*; import java.time.Instant; +import java.time.ZoneId; import java.time.ZonedDateTime; -import java.util.TimeZone; import org.eclipse.smarthome.core.library.types.DateTimeType; import org.eclipse.smarthome.core.library.types.OnOffType; @@ -56,10 +56,13 @@ public class PowermaxThingHandler extends BaseThingHandler implements PowermaxPa private static final int X10_NR_MIN = 1; private static final int X10_NR_MAX = 16; + private final ZoneId zoneId; + private PowermaxBridgeHandler bridgeHandler; - public PowermaxThingHandler(Thing thing) { + public PowermaxThingHandler(Thing thing, ZoneId zoneId) { super(thing); + this.zoneId = zoneId; } @Override @@ -76,7 +79,8 @@ public void initialize() { @Override public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) { logger.debug("Bridge status changed to {} for thing {}", bridgeStatusInfo, getThing().getUID()); - initializeThingState((getBridge() == null) ? null : getBridge().getHandler(), bridgeStatusInfo.getStatus()); + Bridge bridge = getBridge(); + initializeThingState((bridge == null) ? null : bridge.getHandler(), bridgeStatusInfo.getStatus()); } private void initializeThingState(ThingHandler bridgeHandler, ThingStatus bridgeStatus) { @@ -180,7 +184,7 @@ public void updateChannelFromAlarmState(String channel, PowermaxState state) { updateState(TRIPPED, state.isSensorTripped(num) ? OpenClosedType.OPEN : OpenClosedType.CLOSED); } else if (channel.equals(LAST_TRIP) && (state.getSensorLastTripped(num) != null)) { ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(state.getSensorLastTripped(num)), - TimeZone.getDefault().toZoneId()); + zoneId); updateState(LAST_TRIP, new DateTimeType(zoned)); } else if (channel.equals(BYPASSED) && (state.isSensorBypassed(num) != null)) { updateState(BYPASSED, state.isSensorBypassed(num) ? OnOffType.ON : OnOffType.OFF);