diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/AreaAlarm.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/AreaAlarm.java index 6641fe37a89..ce7b6dacf01 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/AreaAlarm.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/AreaAlarm.java @@ -47,10 +47,6 @@ public enum AreaAlarm { return alarmBits.testBit(bit); } - public boolean isSet(int alarmBits) { - return isSet(BigInteger.valueOf(alarmBits)); - } - public String getChannelUID() { return channelUID; } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java index 45c776c55fe..1cc08682bd1 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/OmnilinkBindingConstants.java @@ -162,7 +162,6 @@ public class OmnilinkBindingConstants { public static final String TRIGGER_CHANNEL_DCM_EVENT = "dcm_event"; public static final String TRIGGER_CHANNEL_ENERGY_COST_EVENT = "energy_cost_event"; public static final String TRIGGER_CHANNEL_CAMERA_TRIGGER_EVENT = "camera_trigger_event"; - public static final String TRIGGER_CHANNEL_ACCESS_CONTROL_READER_EVENT = "access_control_reader_event"; public static final String TRIGGER_CHANNEL_AREA_ALL_ON_OFF_EVENT = "all_on_off_event"; public static final String TRIGGER_CHANNEL_SWITCH_PRESS_EVENT = "switch_press_event"; public static final String TRIGGER_CHANNEL_UPB_LINK_ACTIVATED_EVENT = "upb_link_activated_event"; diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/TemperatureFormat.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/TemperatureFormat.java index 68d6daf9221..e297b65b82f 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/TemperatureFormat.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/TemperatureFormat.java @@ -51,7 +51,7 @@ public enum TemperatureFormat { private final int formatNumber; - private TemperatureFormat(int formatNumber) { + TemperatureFormat(int formatNumber) { this.formatNumber = formatNumber; } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/action/OmnilinkActions.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/action/OmnilinkActions.java index 1fa3223957c..ac7595d296d 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/action/OmnilinkActions.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/action/OmnilinkActions.java @@ -67,11 +67,8 @@ public class OmnilinkActions implements ThingActions { zdt = ZonedDateTime.now(ZoneId.of(zone)); } else { logger.debug("Time zone provided invalid, using system default!"); - if (timeZoneProvider.isPresent()) { - zdt = ZonedDateTime.now(timeZoneProvider.get().getTimeZone()); - } else { - zdt = ZonedDateTime.now(ZoneId.systemDefault()); - } + zdt = timeZoneProvider.map(zoneProvider -> ZonedDateTime.now(zoneProvider.getTimeZone())) + .orElseGet(() -> ZonedDateTime.now(ZoneId.systemDefault())); } actionsHandler.synchronizeControllerTime(zdt); } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/discovery/OmnilinkDiscoveryService.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/discovery/OmnilinkDiscoveryService.java index 0d52fa05c06..780f6495324 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/discovery/OmnilinkDiscoveryService.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/discovery/OmnilinkDiscoveryService.java @@ -99,9 +99,9 @@ public class OmnilinkDiscoveryService extends AbstractThingHandlerDiscoveryServi } /** - * Calculate the area filter the a supplied area + * Calculate the area filter of a supplied area * - * @param area Area to calculate filter for. + * @param areaProperties Area to calculate filter for. * @return Calculated Bit Filter for the supplied area. Bit 0 is area 1, bit 2 is area 2 and so on. */ private static int bitFilterForArea(AreaProperties areaProperties) { @@ -328,7 +328,7 @@ public class OmnilinkDiscoveryService extends AbstractThingHandlerDiscoveryServi /** * Discovers OmniLink areas */ - private @Nullable List discoverAreas() { + private List discoverAreas() { final ThingUID bridgeUID = thingHandler.getThing().getUID(); List areas = new LinkedList<>(); @@ -356,22 +356,18 @@ public class OmnilinkDiscoveryService extends AbstractThingHandlerDiscoveryServi final String name = thingName; systemType.ifPresentOrElse(t -> { - ThingUID thingUID = null; - switch (t) { - case LUMINA: - thingUID = new ThingUID(THING_TYPE_LUMINA_AREA, bridgeUID, thingID); - break; - default: - thingUID = new ThingUID(THING_TYPE_OMNI_AREA, bridgeUID, thingID); + ThingUID thingUID; + if (t == SystemType.LUMINA) { + thingUID = new ThingUID(THING_TYPE_LUMINA_AREA, bridgeUID, thingID); + } else { + thingUID = new ThingUID(THING_TYPE_OMNI_AREA, bridgeUID, thingID); } DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties) .withProperty(THING_PROPERTIES_NUMBER, thingID) .withRepresentationProperty(THING_PROPERTIES_NUMBER).withBridge(bridgeUID).withLabel(name) .build(); thingDiscovered(discoveryResult); - }, () -> { - logger.warn("Unknown System Type"); - }); + }, () -> logger.warn("Unknown System Type")); areas.add(areaProperties); } @@ -397,7 +393,7 @@ public class OmnilinkDiscoveryService extends AbstractThingHandlerDiscoveryServi int thingType = unitProperties.getUnitType(); String thingName = unitProperties.getName(); String thingID = Integer.toString(unitProperties.getNumber()); - ThingUID thingUID = null; + ThingUID thingUID; Map properties = new HashMap<>(); properties.put(THING_PROPERTIES_NAME, thingName); diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/exceptions/BridgeOfflineException.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/exceptions/BridgeOfflineException.java index 6112a0bc636..6db90a4ca38 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/exceptions/BridgeOfflineException.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/exceptions/BridgeOfflineException.java @@ -21,8 +21,9 @@ import org.eclipse.jdt.annotation.NonNullByDefault; * @author Craig Hamilton - Initial contribution */ @NonNullByDefault -@SuppressWarnings("serial") public class BridgeOfflineException extends Exception { + private static final long serialVersionUID = 1L; + public BridgeOfflineException(Exception e) { super(e); } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractAreaHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractAreaHandler.java index 1768f6e55e6..fdd121ffdcd 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractAreaHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractAreaHandler.java @@ -67,14 +67,14 @@ public abstract class AbstractAreaHandler extends AbstractOmnilinkStatusHandler< super.initialize(); if (bridgeHandler != null) { - updateAreaProperties(bridgeHandler); + updateAreaProperties(); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, "Received null bridge while initializing Area!"); } } - private void updateAreaProperties(OmnilinkBridgeHandler bridgeHandler) { + private void updateAreaProperties() { final List areas = getAreaProperties(); if (areas != null) { for (AreaProperties areaProperties : areas) { @@ -99,13 +99,10 @@ public abstract class AbstractAreaHandler extends AbstractOmnilinkStatusHandler< return; } - switch (channelUID.getId()) { - case CHANNEL_AREA_ACTIVATE_KEYPAD_EMERGENCY: - handleKeypadEmergency(channelUID, command); - break; - default: - handleSecurityMode(channelUID, command); - break; + if (channelUID.getId().equals(CHANNEL_AREA_ACTIVATE_KEYPAD_EMERGENCY)) { + handleKeypadEmergency(command); + } else { + handleSecurityMode(channelUID, command); } } @@ -176,7 +173,7 @@ public abstract class AbstractAreaHandler extends AbstractOmnilinkStatusHandler< */ protected abstract EnumSet getAlarms(); - private void handleKeypadEmergency(ChannelUID channelUID, Command command) { + private void handleKeypadEmergency(Command command) { if (command instanceof DecimalType decimalCommand) { try { final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler(); diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java index 73ddf7c8989..2c092fe45f1 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java @@ -71,7 +71,7 @@ public abstract class AbstractOmnilinkHandler extends BaseThingHandler { } /** - * Calculate the area filter the a supplied area + * Calculate the area filter of a supplied area * * @param areaProperties Area to calculate filter for. * @return Calculated Bit Filter for the supplied area. Bit 0 is area 1, bit 2 is area 2 and so on. @@ -120,7 +120,7 @@ public abstract class AbstractOmnilinkHandler extends BaseThingHandler { protected int getAreaNumber() { String areaNumber = getThing().getProperties().get(THING_PROPERTIES_AREA); if (areaNumber != null) { - return Integer.valueOf(areaNumber); + return Integer.parseInt(areaNumber); } else { return -1; } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkStatusHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkStatusHandler.java index 386043f028d..5738f3ef32a 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkStatusHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkStatusHandler.java @@ -25,7 +25,7 @@ import com.digitaldan.jomnilinkII.MessageTypes.statuses.Status; /** * The {@link AbstractOmnilinkStatusHandler} defines some methods that can be used across - * the many different units exposed by the OmniLink protocol to retrive updated status information. + * the many different units exposed by the OmniLink protocol to retrieve updated status information. * * @author Craig Hamilton - Initial contribution * @author Ethan Dye - openHAB3 rewrite diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java index a60baec227f..ba0aab34dc2 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java @@ -50,7 +50,6 @@ import com.digitaldan.jomnilinkII.OmniUnknownMessageTypeException; @NonNullByDefault public class AudioSourceHandler extends AbstractOmnilinkHandler { private final Logger logger = LoggerFactory.getLogger(AudioSourceHandler.class); - private final int pollDelaySeconds = 5; private final int thingID = getThingNumber(); private @Nullable ScheduledFuture scheduledPolling = null; public @Nullable String number; @@ -64,7 +63,7 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler { final OmnilinkBridgeHandler bridgeHandler = getOmnilinkBridgeHandler(); if (bridgeHandler != null) { updateStatus(ThingStatus.ONLINE); - if (((Boolean) getThing().getConfiguration().get(THING_PROPERTIES_AUTOSTART)).booleanValue()) { + if ((Boolean) getThing().getConfiguration().get(THING_PROPERTIES_AUTOSTART)) { logger.debug("Autostart enabled, scheduling polling for Audio Source: {}", thingID); schedulePolling(); } else { @@ -104,6 +103,7 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler { private synchronized void schedulePolling() { cancelPolling(); logger.debug("Scheduling polling for Audio Source: {}", thingID); + int pollDelaySeconds = 5; scheduledPolling = super.scheduler.scheduleWithFixedDelay(this::pollAudioSource, 0, pollDelaySeconds, TimeUnit.SECONDS); } @@ -113,19 +113,17 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler { logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command); final ScheduledFuture scheduledPolling = this.scheduledPolling; - switch (channelUID.getId()) { - case CHANNEL_AUDIO_SOURCE_POLLING: - if (command instanceof RefreshType) { - updateState(CHANNEL_AUDIO_SOURCE_POLLING, - OnOffType.from((scheduledPolling != null && !scheduledPolling.isDone()))); - } else if (command instanceof OnOffType onOffCommand) { - handlePolling(channelUID, onOffCommand); - } else { - logger.debug("Invalid command: {}, must be RefreshType or OnOffType", command); - } - break; - default: - logger.warn("Unknown channel for Audio Source thing: {}", channelUID); + if (CHANNEL_AUDIO_SOURCE_POLLING.equals(channelUID.getId())) { + if (command instanceof RefreshType) { + updateState(CHANNEL_AUDIO_SOURCE_POLLING, + OnOffType.from((scheduledPolling != null && !scheduledPolling.isDone()))); + } else if (command instanceof OnOffType onOffCommand) { + handlePolling(channelUID, onOffCommand); + } else { + logger.debug("Invalid command: {}, must be RefreshType or OnOffType", command); + } + } else { + logger.warn("Unknown channel for Audio Source thing: {}", channelUID); } } @@ -174,7 +172,7 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler { logger.debug("Received null bridge while polling Audio Source statuses!"); } } catch (OmniInvalidResponseException | OmniUnknownMessageTypeException | BridgeOfflineException e) { - logger.debug("Exception recieved while polling for Audio Source statuses: {}", e.getMessage()); + logger.debug("Exception received while polling for Audio Source statuses: {}", e.getMessage()); } } } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ButtonHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ButtonHandler.java index a2e7cc1c64c..511b7024465 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ButtonHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ButtonHandler.java @@ -95,17 +95,15 @@ public class ButtonHandler extends AbstractOmnilinkHandler { return; } - switch (channelUID.getId()) { - case CHANNEL_BUTTON_PRESS: - if (command instanceof OnOffType) { - sendOmnilinkCommand(CommandMessage.CMD_BUTTON, 0, thingID); - updateChannels(); - } else { - logger.debug("Invalid command: {}, must be OnOffType", command); - } - break; - default: - logger.warn("Unknown channel for Button thing: {}", channelUID); + if (CHANNEL_BUTTON_PRESS.equals(channelUID.getId())) { + if (command instanceof OnOffType) { + sendOmnilinkCommand(CommandMessage.CMD_BUTTON, 0, thingID); + updateChannels(); + } else { + logger.debug("Invalid command: {}, must be OnOffType", command); + } + } else { + logger.warn("Unknown channel for Button thing: {}", channelUID); } } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/HumiditySensorHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/HumiditySensorHandler.java index d9e2ad6bcf2..c4f08bca306 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/HumiditySensorHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/HumiditySensorHandler.java @@ -125,7 +125,7 @@ public class HumiditySensorHandler extends AbstractOmnilinkStatusHandler CommandMessage.CMD_SECURITY_LUMINA_HOME_MODE; + case CHANNEL_AREA_SECURITY_MODE_SLEEP -> CommandMessage.CMD_SECURITY_LUMINA_SLEEP_MODE; + case CHANNEL_AREA_SECURITY_MODE_AWAY -> CommandMessage.CMD_SECURITY_LUMINA_AWAY_MODE; + case CHANNEL_AREA_SECURITY_MODE_VACATION -> CommandMessage.CMD_SECURITY_LUMINA_VACATION_MODE; + case CHANNEL_AREA_SECURITY_MODE_PARTY -> CommandMessage.CMD_SECURITY_LUMINA_PARTY_MODE; + case CHANNEL_AREA_SECURITY_MODE_SPECIAL -> CommandMessage.CMD_SECURITY_LUMINA_SPECIAL_MODE; + default -> throw new IllegalStateException("Unknown channel for area thing " + channelUID); + }; } @Override diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmniAreaHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmniAreaHandler.java index c83c3f15c4e..7bdfc82b980 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmniAreaHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmniAreaHandler.java @@ -45,24 +45,16 @@ public class OmniAreaHandler extends AbstractAreaHandler { @Override protected int getMode(ChannelUID channelUID) { - switch (channelUID.getId()) { - case CHANNEL_AREA_SECURITY_MODE_DISARM: - return CommandMessage.CMD_SECURITY_OMNI_DISARM; - case CHANNEL_AREA_SECURITY_MODE_DAY: - return CommandMessage.CMD_SECURITY_OMNI_DAY_MODE; - case CHANNEL_AREA_SECURITY_MODE_NIGHT: - return CommandMessage.CMD_SECURITY_OMNI_NIGHT_MODE; - case CHANNEL_AREA_SECURITY_MODE_AWAY: - return CommandMessage.CMD_SECURITY_OMNI_AWAY_MODE; - case CHANNEL_AREA_SECURITY_MODE_VACATION: - return CommandMessage.CMD_SECURITY_OMNI_VACATION_MODE; - case CHANNEL_AREA_SECURITY_MODE_DAY_INSTANT: - return CommandMessage.CMD_SECURITY_OMNI_DAY_INSTANT_MODE; - case CHANNEL_AREA_SECURITY_MODE_NIGHT_DELAYED: - return CommandMessage.CMD_SECURITY_OMNI_NIGHT_DELAYED_MODE; - default: - throw new IllegalStateException("Unknown channel for area thing " + channelUID); - } + return switch (channelUID.getId()) { + case CHANNEL_AREA_SECURITY_MODE_DISARM -> CommandMessage.CMD_SECURITY_OMNI_DISARM; + case CHANNEL_AREA_SECURITY_MODE_DAY -> CommandMessage.CMD_SECURITY_OMNI_DAY_MODE; + case CHANNEL_AREA_SECURITY_MODE_NIGHT -> CommandMessage.CMD_SECURITY_OMNI_NIGHT_MODE; + case CHANNEL_AREA_SECURITY_MODE_AWAY -> CommandMessage.CMD_SECURITY_OMNI_AWAY_MODE; + case CHANNEL_AREA_SECURITY_MODE_VACATION -> CommandMessage.CMD_SECURITY_OMNI_VACATION_MODE; + case CHANNEL_AREA_SECURITY_MODE_DAY_INSTANT -> CommandMessage.CMD_SECURITY_OMNI_DAY_INSTANT_MODE; + case CHANNEL_AREA_SECURITY_MODE_NIGHT_DELAYED -> CommandMessage.CMD_SECURITY_OMNI_NIGHT_DELAYED_MODE; + default -> throw new IllegalStateException("Unknown channel for area thing " + channelUID); + }; } @Override diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java index 57d6588deac..5c10b2cfb94 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java @@ -95,7 +95,6 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica private @Nullable Connection omniConnection = null; private @Nullable ScheduledFuture connectJob; private @Nullable ScheduledFuture eventPollingJob; - private final int autoReconnectPeriod = 60; private Optional audioPlayer = Optional.empty(); private Optional systemType = Optional.empty(); private final Gson gson = new Gson(); @@ -240,9 +239,9 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica * HAI only supports one audio player - cycle through features until we find a feature that is an audio * player. */ - audioPlayer = Objects.requireNonNull(reqSystemFeatures().getFeatures().stream() - .map(featureCode -> AudioPlayer.getAudioPlayerForFeatureCode(featureCode)) - .filter(Optional::isPresent).findFirst().orElse(Optional.empty())); + audioPlayer = Objects.requireNonNull( + reqSystemFeatures().getFeatures().stream().map(AudioPlayer::getAudioPlayerForFeatureCode) + .filter(Optional::isPresent).findFirst().orElse(Optional.empty())); systemType = SystemType.getType(reqSystemInformation().getModel()); @@ -288,80 +287,83 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica if (objectStatus != null) { Status[] statuses = objectStatus.getStatuses(); for (Status status : statuses) { - if (status instanceof ExtendedUnitStatus unitStatus) { - int unitNumber = unitStatus.getNumber(); + switch (status) { + case ExtendedUnitStatus unitStatus -> { + int unitNumber = unitStatus.getNumber(); - logger.debug("Received status update for Unit: {}, status: {}", unitNumber, unitStatus); - Optional theThing = getUnitThing(unitNumber); - theThing.map(Thing::getHandler) - .ifPresent(theHandler -> ((UnitHandler) theHandler).handleStatus(unitStatus)); - } else if (status instanceof ExtendedZoneStatus zoneStatus) { - int zoneNumber = zoneStatus.getNumber(); - - logger.debug("Received status update for Zone: {}, status: {}", zoneNumber, zoneStatus); - Optional theThing = getChildThing(THING_TYPE_ZONE, zoneNumber); - theThing.map(Thing::getHandler) - .ifPresent(theHandler -> ((ZoneHandler) theHandler).handleStatus(zoneStatus)); - } else if (status instanceof ExtendedAreaStatus areaStatus) { - int areaNumber = areaStatus.getNumber(); - - logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus); - systemType.ifPresent(t -> { - Optional theThing = Optional.empty(); - switch (t) { - case LUMINA: - theThing = getChildThing(THING_TYPE_LUMINA_AREA, areaNumber); - break; - case OMNI: - theThing = getChildThing(THING_TYPE_OMNI_AREA, areaNumber); - break; - } + logger.debug("Received status update for Unit: {}, status: {}", unitNumber, unitStatus); + Optional theThing = getUnitThing(unitNumber); theThing.map(Thing::getHandler) - .ifPresent(theHandler -> ((AbstractAreaHandler) theHandler).handleStatus(areaStatus)); - }); - } else if (status instanceof ExtendedAccessControlReaderLockStatus lockStatus) { - int lockNumber = lockStatus.getNumber(); - - logger.debug("Received status update for Lock: {}, status: {}", lockNumber, lockStatus); - Optional theThing = getChildThing(THING_TYPE_LOCK, lockNumber); - theThing.map(Thing::getHandler) - .ifPresent(theHandler -> ((LockHandler) theHandler).handleStatus(lockStatus)); - } else if (status instanceof ExtendedThermostatStatus thermostatStatus) { - int thermostatNumber = thermostatStatus.getNumber(); - - logger.debug("Received status update for Thermostat: {}, status: {}", thermostatNumber, - thermostatStatus); - Optional theThing = getChildThing(THING_TYPE_THERMOSTAT, thermostatNumber); - theThing.map(Thing::getHandler) - .ifPresent(theHandler -> ((ThermostatHandler) theHandler).handleStatus(thermostatStatus)); - } else if (status instanceof ExtendedAudioZoneStatus audioZoneStatus) { - int audioZoneNumber = audioZoneStatus.getNumber(); - - logger.debug("Received status update for Audio Zone: {}, status: {}", audioZoneNumber, - audioZoneStatus); - Optional theThing = getChildThing(THING_TYPE_AUDIO_ZONE, audioZoneNumber); - theThing.map(Thing::getHandler) - .ifPresent(theHandler -> ((AudioZoneHandler) theHandler).handleStatus(audioZoneStatus)); - } else if (status instanceof ExtendedAuxSensorStatus auxSensorStatus) { - int auxSensorNumber = auxSensorStatus.getNumber(); - - // Aux Sensors can be either temperature or humidity, need to check both. - Optional tempThing = getChildThing(THING_TYPE_TEMP_SENSOR, auxSensorNumber); - Optional humidityThing = getChildThing(THING_TYPE_HUMIDITY_SENSOR, auxSensorNumber); - if (tempThing.isPresent()) { - logger.debug("Received status update for Temperature Sensor: {}, status: {}", auxSensorNumber, - auxSensorStatus); - tempThing.map(Thing::getHandler).ifPresent( - theHandler -> ((TempSensorHandler) theHandler).handleStatus(auxSensorStatus)); + .ifPresent(theHandler -> ((UnitHandler) theHandler).handleStatus(unitStatus)); } - if (humidityThing.isPresent()) { - logger.debug("Received status update for Humidity Sensor: {}, status: {}", auxSensorNumber, - auxSensorStatus); - humidityThing.map(Thing::getHandler).ifPresent( - theHandler -> ((HumiditySensorHandler) theHandler).handleStatus(auxSensorStatus)); + case ExtendedZoneStatus zoneStatus -> { + int zoneNumber = zoneStatus.getNumber(); + + logger.debug("Received status update for Zone: {}, status: {}", zoneNumber, zoneStatus); + Optional theThing = getChildThing(THING_TYPE_ZONE, zoneNumber); + theThing.map(Thing::getHandler) + .ifPresent(theHandler -> ((ZoneHandler) theHandler).handleStatus(zoneStatus)); } - } else { - logger.debug("Received Object Status Notification that was not processed: {}", objectStatus); + case ExtendedAreaStatus areaStatus -> { + int areaNumber = areaStatus.getNumber(); + + logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus); + systemType.ifPresent(t -> { + Optional theThing = switch (t) { + case LUMINA -> getChildThing(THING_TYPE_LUMINA_AREA, areaNumber); + case OMNI -> getChildThing(THING_TYPE_OMNI_AREA, areaNumber); + }; + theThing.map(Thing::getHandler).ifPresent( + theHandler -> ((AbstractAreaHandler) theHandler).handleStatus(areaStatus)); + }); + } + case ExtendedAccessControlReaderLockStatus lockStatus -> { + int lockNumber = lockStatus.getNumber(); + + logger.debug("Received status update for Lock: {}, status: {}", lockNumber, lockStatus); + Optional theThing = getChildThing(THING_TYPE_LOCK, lockNumber); + theThing.map(Thing::getHandler) + .ifPresent(theHandler -> ((LockHandler) theHandler).handleStatus(lockStatus)); + } + case ExtendedThermostatStatus thermostatStatus -> { + int thermostatNumber = thermostatStatus.getNumber(); + + logger.debug("Received status update for Thermostat: {}, status: {}", thermostatNumber, + thermostatStatus); + Optional theThing = getChildThing(THING_TYPE_THERMOSTAT, thermostatNumber); + theThing.map(Thing::getHandler).ifPresent( + theHandler -> ((ThermostatHandler) theHandler).handleStatus(thermostatStatus)); + } + case ExtendedAudioZoneStatus audioZoneStatus -> { + int audioZoneNumber = audioZoneStatus.getNumber(); + + logger.debug("Received status update for Audio Zone: {}, status: {}", audioZoneNumber, + audioZoneStatus); + Optional theThing = getChildThing(THING_TYPE_AUDIO_ZONE, audioZoneNumber); + theThing.map(Thing::getHandler) + .ifPresent(theHandler -> ((AudioZoneHandler) theHandler).handleStatus(audioZoneStatus)); + } + case ExtendedAuxSensorStatus auxSensorStatus -> { + int auxSensorNumber = auxSensorStatus.getNumber(); + + // Aux Sensors can be either temperature or humidity, need to check both. + Optional tempThing = getChildThing(THING_TYPE_TEMP_SENSOR, auxSensorNumber); + Optional humidityThing = getChildThing(THING_TYPE_HUMIDITY_SENSOR, auxSensorNumber); + if (tempThing.isPresent()) { + logger.debug("Received status update for Temperature Sensor: {}, status: {}", + auxSensorNumber, auxSensorStatus); + tempThing.map(Thing::getHandler).ifPresent( + theHandler -> ((TempSensorHandler) theHandler).handleStatus(auxSensorStatus)); + } + if (humidityThing.isPresent()) { + logger.debug("Received status update for Humidity Sensor: {}, status: {}", auxSensorNumber, + auxSensorStatus); + humidityThing.map(Thing::getHandler).ifPresent( + theHandler -> ((HumiditySensorHandler) theHandler).handleStatus(auxSensorStatus)); + } + } + case null, default -> + logger.debug("Received Object Status Notification that was not processed: {}", objectStatus); } } } else { @@ -476,12 +478,9 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica SystemStatus status = getOmniConnection().reqSystemStatus(); logger.debug("Received system status: {}", status); // Update controller's reported time - String dateString = new StringBuilder().append(2000 + status.getYear()).append("-") - .append(String.format("%02d", status.getMonth())).append("-") - .append(String.format("%02d", status.getDay())).append("T") - .append(String.format("%02d", status.getHour())).append(":") - .append(String.format("%02d", status.getMinute())).append(":") - .append(String.format("%02d", status.getSecond())).toString(); + String dateString = (2000 + status.getYear()) + "-" + String.format("%02d", status.getMonth()) + "-" + + String.format("%02d", status.getDay()) + "T" + String.format("%02d", status.getHour()) + ":" + + String.format("%02d", status.getMinute()) + ":" + String.format("%02d", status.getSecond()); updateState(CHANNEL_SYSTEM_DATE, new DateTimeType(dateString)); } @@ -578,10 +577,8 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica SystemInformation systemInformation = reqSystemInformation(); Map properties = editProperties(); properties.put(Thing.PROPERTY_MODEL_ID, Integer.toString(systemInformation.getModel())); - properties.put(Thing.PROPERTY_FIRMWARE_VERSION, - Integer.toString(systemInformation.getMajor()) + "." - + Integer.toString(systemInformation.getMinor()) + "." - + Integer.toString(systemInformation.getRevision())); + properties.put(Thing.PROPERTY_FIRMWARE_VERSION, systemInformation.getMajor() + "." + + systemInformation.getMinor() + "." + systemInformation.getRevision()); properties.put(THING_PROPERTIES_PHONE_NUMBER, systemInformation.getPhone()); updateProperties(properties); } catch (OmniInvalidResponseException | OmniUnknownMessageTypeException | BridgeOfflineException e) { @@ -597,8 +594,7 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica private void scheduleReconnectJob() { ScheduledFuture currentReconnectJob = connectJob; if (currentReconnectJob == null || currentReconnectJob.isDone()) { - connectJob = super.scheduler.scheduleWithFixedDelay(this::makeOmnilinkConnection, 0, autoReconnectPeriod, - TimeUnit.SECONDS); + connectJob = super.scheduler.scheduleWithFixedDelay(this::makeOmnilinkConnection, 0, 60, TimeUnit.SECONDS); } } @@ -647,13 +643,13 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica logger.debug("Processing event log message number: {}", logData.getEventNumber()); eventLogNumber = logData.getEventNumber(); String json = gson.toJson(logData); - logger.debug("Receieved event log message: {}", json); + logger.debug("Received event log message: {}", json); updateState(CHANNEL_EVENT_LOG, new StringType(json)); } } while (message.getMessageType() != Message.MESG_TYPE_END_OF_DATA); } catch (OmniInvalidResponseException | OmniUnknownMessageTypeException | BridgeOfflineException e) { - logger.debug("Exception recieved while polling for event log messages: {}", e.getMessage()); + logger.debug("Exception received while polling for event log messages: {}", e.getMessage()); } } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TempSensorHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TempSensorHandler.java index b18a155b062..103cea497f4 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TempSensorHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TempSensorHandler.java @@ -103,7 +103,7 @@ public class TempSensorHandler extends AbstractOmnilinkStatusHandler temperatureFormat = Optional.empty(); + Optional temperatureFormat; if (command instanceof RefreshType) { retrieveStatus().ifPresentOrElse(this::updateChannels, () -> updateStatus(ThingStatus.OFFLINE, @@ -118,7 +118,7 @@ public class TempSensorHandler extends AbstractOmnilinkStatusHandler temperatureFormat = Optional.empty(); + Optional temperatureFormat; if (command instanceof RefreshType) { retrieveStatus().ifPresentOrElse(this::updateChannels, () -> updateStatus(ThingStatus.OFFLINE, @@ -137,7 +137,7 @@ public class ThermostatHandler extends AbstractOmnilinkStatusHandler= Status.UNIT_SCENE_A) && (unitStatus <= Status.UNIT_SCENE_L)) { level = 100; @@ -206,7 +204,7 @@ public class UnitHandler extends AbstractOmnilinkStatusHandler areas = super.getAreaProperties(); if (areas != null) { for (AreaProperties areaProperties : areas) { - int areaFilter = super.bitFilterForArea(areaProperties); + int areaFilter = bitFilterForArea(areaProperties); ObjectPropertyRequest objectPropertyRequest = ObjectPropertyRequest .builder(bridgeHandler, ObjectPropertyRequests.ZONE, getThingNumber(), 0).selectNamed() @@ -115,16 +115,11 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler CommandMessage.CMD_SECURITY_BYPASS_ZONE; + case CHANNEL_ZONE_RESTORE -> CommandMessage.CMD_SECURITY_RESTORE_ZONE; + default -> -1; + }; logger.debug("mode {} on zone {} with code {}", mode, thingID, command.toFullString()); char[] code = command.toFullString().toCharArray(); if (code.length != 4) { @@ -174,7 +169,7 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler> 0) & 0x03); + int current = ((zoneStatus.getStatus()) & 0x03); // 0 Secure, 1 Tripped, 2 Reset, but previously tripped int latched = ((zoneStatus.getStatus() >> 2) & 0x03); // 0 Disarmed, 1 Armed, 2 Bypass user, 3 Bypass system diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/DimmableUnitHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/DimmableUnitHandler.java index 11274ff707d..ca3c9e55906 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/DimmableUnitHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/DimmableUnitHandler.java @@ -49,13 +49,11 @@ public class DimmableUnitHandler extends UnitHandler { @Override public void handleCommand(ChannelUID channelUID, Command command) { logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command); - switch (channelUID.getId()) { - case CHANNEL_UNIT_LEVEL: - handleUnitLevel(channelUID, command); - break; - default: - logger.debug("Unknown channel for Dimmable Unit thing: {}", channelUID); - super.handleCommand(channelUID, command); + if (CHANNEL_UNIT_LEVEL.equals(channelUID.getId())) { + handleUnitLevel(channelUID, command); + } else { + logger.debug("Unknown channel for Dimmable Unit thing: {}", channelUID); + super.handleCommand(channelUID, command); } } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/UpbRoomHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/UpbRoomHandler.java index 03636bd12da..92c4ca26e28 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/UpbRoomHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/UpbRoomHandler.java @@ -146,7 +146,7 @@ public class UpbRoomHandler extends UnitHandler { param2 = ((roomNum * 6) - 3) + cmdValue - 2; break; default: - logger.warn("Unexpected UPB Room state: {}", Integer.toString(cmdValue)); + logger.warn("Unexpected UPB Room state: {}", cmdValue); return; } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/dimmable/UpbUnitHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/dimmable/UpbUnitHandler.java index 9e3c76a625c..e65423618b1 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/dimmable/UpbUnitHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/units/dimmable/UpbUnitHandler.java @@ -55,18 +55,16 @@ public class UpbUnitHandler extends DimmableUnitHandler { return; } - switch (channelUID.getId()) { - case CHANNEL_UPB_STATUS: - if (command instanceof StringType) { - sendOmnilinkCommand(CommandMessage.CMD_UNIT_UPB_REQ_STATUS, 0, thingID); - updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF); - } else { - logger.debug("Invalid command: {}, must be StringType", command); - } - break; - default: - logger.debug("Unknown channel for UPB Unit thing: {}", channelUID); - super.handleCommand(channelUID, command); + if (CHANNEL_UPB_STATUS.equals(channelUID.getId())) { + if (command instanceof StringType) { + sendOmnilinkCommand(CommandMessage.CMD_UNIT_UPB_REQ_STATUS, 0, thingID); + updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF); + } else { + logger.debug("Invalid command: {}, must be StringType", command); + } + } else { + logger.debug("Unknown channel for UPB Unit thing: {}", channelUID); + super.handleCommand(channelUID, command); } } }