[omnilink] Improve code quality (#18017)

* Fix minor spelling errors
* Reduce code complexity

Signed-off-by: Ethan Dye <mrtops03@gmail.com>
This commit is contained in:
Ethan Dye 2025-01-03 00:46:47 -07:00 committed by GitHub
parent 6af04fc31f
commit 705feffd54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 195 additions and 244 deletions

View File

@ -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;
}

View File

@ -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";

View File

@ -51,7 +51,7 @@ public enum TemperatureFormat {
private final int formatNumber;
private TemperatureFormat(int formatNumber) {
TemperatureFormat(int formatNumber) {
this.formatNumber = formatNumber;
}

View File

@ -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);
}

View File

@ -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<AreaProperties> discoverAreas() {
private List<AreaProperties> discoverAreas() {
final ThingUID bridgeUID = thingHandler.getThing().getUID();
List<AreaProperties> areas = new LinkedList<>();
@ -356,12 +356,10 @@ public class OmnilinkDiscoveryService extends AbstractThingHandlerDiscoveryServi
final String name = thingName;
systemType.ifPresentOrElse(t -> {
ThingUID thingUID = null;
switch (t) {
case LUMINA:
ThingUID thingUID;
if (t == SystemType.LUMINA) {
thingUID = new ThingUID(THING_TYPE_LUMINA_AREA, bridgeUID, thingID);
break;
default:
} else {
thingUID = new ThingUID(THING_TYPE_OMNI_AREA, bridgeUID, thingID);
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties)
@ -369,9 +367,7 @@ public class OmnilinkDiscoveryService extends AbstractThingHandlerDiscoveryServi
.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<String, Object> properties = new HashMap<>();
properties.put(THING_PROPERTIES_NAME, thingName);

View File

@ -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);
}

View File

@ -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<AreaProperties> 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:
if (channelUID.getId().equals(CHANNEL_AREA_ACTIVATE_KEYPAD_EMERGENCY)) {
handleKeypadEmergency(command);
} else {
handleSecurityMode(channelUID, command);
break;
}
}
@ -176,7 +173,7 @@ public abstract class AbstractAreaHandler extends AbstractOmnilinkStatusHandler<
*/
protected abstract EnumSet<AreaAlarm> getAlarms();
private void handleKeypadEmergency(ChannelUID channelUID, Command command) {
private void handleKeypadEmergency(Command command) {
if (command instanceof DecimalType decimalCommand) {
try {
final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler();

View File

@ -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;
}

View File

@ -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

View File

@ -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,8 +113,7 @@ 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 (CHANNEL_AUDIO_SOURCE_POLLING.equals(channelUID.getId())) {
if (command instanceof RefreshType) {
updateState(CHANNEL_AUDIO_SOURCE_POLLING,
OnOffType.from((scheduledPolling != null && !scheduledPolling.isDone())));
@ -123,8 +122,7 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler {
} else {
logger.debug("Invalid command: {}, must be RefreshType or OnOffType", command);
}
break;
default:
} 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());
}
}
}

View File

@ -95,16 +95,14 @@ public class ButtonHandler extends AbstractOmnilinkHandler {
return;
}
switch (channelUID.getId()) {
case CHANNEL_BUTTON_PRESS:
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);
}
break;
default:
} else {
logger.warn("Unknown channel for Button thing: {}", channelUID);
}
}

View File

@ -125,7 +125,7 @@ public class HumiditySensorHandler extends AbstractOmnilinkStatusHandler<Extende
thingID);
break;
default:
logger.warn("Unknown channel for Humdity Sensor thing: {}", channelUID);
logger.warn("Unknown channel for Humidity Sensor thing: {}", channelUID);
}
}

View File

@ -88,16 +88,15 @@ public class LockHandler extends AbstractOmnilinkStatusHandler<ExtendedAccessCon
return;
}
switch (channelUID.getId()) {
case CHANNEL_LOCK_SWITCH:
if (CHANNEL_LOCK_SWITCH.equals(channelUID.getId())) {
if (command instanceof OnOffType) {
sendOmnilinkCommand(OnOffType.OFF.equals(command) ? CommandMessage.CMD_UNLOCK_DOOR
: CommandMessage.CMD_LOCK_DOOR, 0, thingID);
sendOmnilinkCommand(
OnOffType.OFF.equals(command) ? CommandMessage.CMD_UNLOCK_DOOR : CommandMessage.CMD_LOCK_DOOR,
0, thingID);
} else {
logger.debug("Invalid command {}, must be OnOffType", command);
}
break;
default:
} else {
logger.warn("Unknown channel for Lock thing: {}", channelUID);
}
}

View File

@ -44,22 +44,15 @@ public class LuminaAreaHandler extends AbstractAreaHandler {
@Override
protected int getMode(ChannelUID channelUID) {
switch (channelUID.getId()) {
case CHANNEL_AREA_SECURITY_MODE_HOME:
return CommandMessage.CMD_SECURITY_LUMINA_HOME_MODE;
case CHANNEL_AREA_SECURITY_MODE_SLEEP:
return CommandMessage.CMD_SECURITY_LUMINA_SLEEP_MODE;
case CHANNEL_AREA_SECURITY_MODE_AWAY:
return CommandMessage.CMD_SECURITY_LUMINA_AWAY_MODE;
case CHANNEL_AREA_SECURITY_MODE_VACATION:
return CommandMessage.CMD_SECURITY_LUMINA_VACATION_MODE;
case CHANNEL_AREA_SECURITY_MODE_PARTY:
return CommandMessage.CMD_SECURITY_LUMINA_PARTY_MODE;
case CHANNEL_AREA_SECURITY_MODE_SPECIAL:
return CommandMessage.CMD_SECURITY_LUMINA_SPECIAL_MODE;
default:
throw new IllegalStateException("Unknown channel for area thing " + channelUID);
}
return switch (channelUID.getId()) {
case CHANNEL_AREA_SECURITY_MODE_HOME -> 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

View File

@ -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

View File

@ -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> audioPlayer = Optional.empty();
private Optional<SystemType> systemType = Optional.empty();
private final Gson gson = new Gson();
@ -240,8 +239,8 @@ 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))
audioPlayer = Objects.requireNonNull(
reqSystemFeatures().getFeatures().stream().map(AudioPlayer::getAudioPlayerForFeatureCode)
.filter(Optional::isPresent).findFirst().orElse(Optional.empty()));
systemType = SystemType.getType(reqSystemInformation().getModel());
@ -288,53 +287,54 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
if (objectStatus != null) {
Status[] statuses = objectStatus.getStatuses();
for (Status status : statuses) {
if (status instanceof ExtendedUnitStatus unitStatus) {
switch (status) {
case ExtendedUnitStatus unitStatus -> {
int unitNumber = unitStatus.getNumber();
logger.debug("Received status update for Unit: {}, status: {}", unitNumber, unitStatus);
Optional<Thing> theThing = getUnitThing(unitNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((UnitHandler) theHandler).handleStatus(unitStatus));
} else if (status instanceof ExtendedZoneStatus zoneStatus) {
}
case ExtendedZoneStatus zoneStatus -> {
int zoneNumber = zoneStatus.getNumber();
logger.debug("Received status update for Zone: {}, status: {}", zoneNumber, zoneStatus);
Optional<Thing> theThing = getChildThing(THING_TYPE_ZONE, zoneNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((ZoneHandler) theHandler).handleStatus(zoneStatus));
} else if (status instanceof ExtendedAreaStatus areaStatus) {
}
case ExtendedAreaStatus areaStatus -> {
int areaNumber = areaStatus.getNumber();
logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus);
systemType.ifPresent(t -> {
Optional<Thing> 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;
}
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((AbstractAreaHandler) theHandler).handleStatus(areaStatus));
Optional<Thing> 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));
});
} else if (status instanceof ExtendedAccessControlReaderLockStatus lockStatus) {
}
case ExtendedAccessControlReaderLockStatus lockStatus -> {
int lockNumber = lockStatus.getNumber();
logger.debug("Received status update for Lock: {}, status: {}", lockNumber, lockStatus);
Optional<Thing> theThing = getChildThing(THING_TYPE_LOCK, lockNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((LockHandler) theHandler).handleStatus(lockStatus));
} else if (status instanceof ExtendedThermostatStatus thermostatStatus) {
}
case ExtendedThermostatStatus thermostatStatus -> {
int thermostatNumber = thermostatStatus.getNumber();
logger.debug("Received status update for Thermostat: {}, status: {}", thermostatNumber,
thermostatStatus);
Optional<Thing> theThing = getChildThing(THING_TYPE_THERMOSTAT, thermostatNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((ThermostatHandler) theHandler).handleStatus(thermostatStatus));
} else if (status instanceof ExtendedAudioZoneStatus audioZoneStatus) {
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,
@ -342,15 +342,16 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
Optional<Thing> theThing = getChildThing(THING_TYPE_AUDIO_ZONE, audioZoneNumber);
theThing.map(Thing::getHandler)
.ifPresent(theHandler -> ((AudioZoneHandler) theHandler).handleStatus(audioZoneStatus));
} else if (status instanceof ExtendedAuxSensorStatus auxSensorStatus) {
}
case ExtendedAuxSensorStatus auxSensorStatus -> {
int auxSensorNumber = auxSensorStatus.getNumber();
// Aux Sensors can be either temperature or humidity, need to check both.
Optional<Thing> tempThing = getChildThing(THING_TYPE_TEMP_SENSOR, auxSensorNumber);
Optional<Thing> humidityThing = getChildThing(THING_TYPE_HUMIDITY_SENSOR, auxSensorNumber);
if (tempThing.isPresent()) {
logger.debug("Received status update for Temperature Sensor: {}, status: {}", auxSensorNumber,
auxSensorStatus);
logger.debug("Received status update for Temperature Sensor: {}, status: {}",
auxSensorNumber, auxSensorStatus);
tempThing.map(Thing::getHandler).ifPresent(
theHandler -> ((TempSensorHandler) theHandler).handleStatus(auxSensorStatus));
}
@ -360,7 +361,8 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
humidityThing.map(Thing::getHandler).ifPresent(
theHandler -> ((HumiditySensorHandler) theHandler).handleStatus(auxSensorStatus));
}
} else {
}
case null, default ->
logger.debug("Received Object Status Notification that was not processed: {}", objectStatus);
}
}
@ -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<String, String> 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());
}
}

View File

@ -103,7 +103,7 @@ public class TempSensorHandler extends AbstractOmnilinkStatusHandler<ExtendedAux
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
final OmnilinkBridgeHandler bridgeHandler = getOmnilinkBridgeHandler();
Optional<TemperatureFormat> temperatureFormat = Optional.empty();
Optional<TemperatureFormat> temperatureFormat;
if (command instanceof RefreshType) {
retrieveStatus().ifPresentOrElse(this::updateChannels, () -> updateStatus(ThingStatus.OFFLINE,
@ -118,7 +118,7 @@ public class TempSensorHandler extends AbstractOmnilinkStatusHandler<ExtendedAux
if (bridgeHandler != null) {
temperatureFormat = bridgeHandler.getTemperatureFormat();
if (temperatureFormat.isEmpty()) {
logger.warn("Receieved null temperature format!");
logger.warn("Received null temperature format!");
return;
}
} else {
@ -158,7 +158,7 @@ public class TempSensorHandler extends AbstractOmnilinkStatusHandler<ExtendedAux
temperatureFormat.get().omniToFormat(status.getHeatSetpoint()),
temperatureFormat.get().getFormatNumber() == 1 ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS));
} else {
logger.warn("Receieved null temperature format, could not update Temperature Sensor channels!");
logger.warn("Received null temperature format, could not update Temperature Sensor channels!");
}
} else {
logger.debug("Received null bridge while updating Temperature Sensor channels!");

View File

@ -75,7 +75,7 @@ public class ThermostatHandler extends AbstractOmnilinkStatusHandler<ExtendedThe
private final int bit;
private final int modeValue;
private ThermostatStatus(int bit, int modeValue) {
ThermostatStatus(int bit, int modeValue) {
this.bit = bit;
this.modeValue = modeValue;
}
@ -122,7 +122,7 @@ public class ThermostatHandler extends AbstractOmnilinkStatusHandler<ExtendedThe
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
final OmnilinkBridgeHandler bridgeHandler = getOmnilinkBridgeHandler();
Optional<TemperatureFormat> temperatureFormat = Optional.empty();
Optional<TemperatureFormat> temperatureFormat;
if (command instanceof RefreshType) {
retrieveStatus().ifPresentOrElse(this::updateChannels, () -> updateStatus(ThingStatus.OFFLINE,
@ -137,7 +137,7 @@ public class ThermostatHandler extends AbstractOmnilinkStatusHandler<ExtendedThe
if (bridgeHandler != null) {
temperatureFormat = bridgeHandler.getTemperatureFormat();
if (temperatureFormat.isEmpty()) {
logger.warn("Receieved null temperature format!");
logger.warn("Received null temperature format!");
return;
}
} else {
@ -226,7 +226,7 @@ public class ThermostatHandler extends AbstractOmnilinkStatusHandler<ExtendedThe
temperatureFormat.get().omniToFormat(status.getHeatSetpoint()),
temperatureFormat.get().getFormatNumber() == 1 ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS));
} else {
logger.warn("Receieved null temperature format, could not update Thermostat channels!");
logger.warn("Received null temperature format, could not update Thermostat channels!");
}
} else {
logger.warn("Could not connect to Bridge, failed to get temperature format!");

View File

@ -160,11 +160,9 @@ public class UnitHandler extends AbstractOmnilinkStatusHandler<ExtendedUnitStatu
public void updateChannels(ExtendedUnitStatus status) {
logger.debug("updateChannels called for Unit status: {}", status);
int unitStatus = status.getStatus();
int level = 0;
int level = Status.UNIT_OFF;
if (unitStatus == Status.UNIT_OFF) {
level = 0;
} else if (unitStatus == Status.UNIT_ON) {
if (unitStatus == Status.UNIT_ON) {
level = 100;
} else if ((unitStatus >= Status.UNIT_SCENE_A) && (unitStatus <= Status.UNIT_SCENE_L)) {
level = 100;
@ -206,7 +204,7 @@ public class UnitHandler extends AbstractOmnilinkStatusHandler<ExtendedUnitStatu
/**
* Handle a switch press event by triggering the appropriate channel.
*
* @param switchPressEvent
* @param switchPressEvent A switch press event to handle.
*/
public void handleSwitchPressEvent(SwitchPressEvent switchPressEvent) {
ChannelUID activateChannel = new ChannelUID(getThing().getUID(), TRIGGER_CHANNEL_SWITCH_PRESS_EVENT);

View File

@ -81,7 +81,7 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
final List<AreaProperties> areas = super.getAreaProperties();
if (areas != null) {
for (AreaProperties areaProperties : areas) {
int areaFilter = super.bitFilterForArea(areaProperties);
int areaFilter = bitFilterForArea(areaProperties);
ObjectPropertyRequest<ZoneProperties> objectPropertyRequest = ObjectPropertyRequest
.builder(bridgeHandler, ObjectPropertyRequests.ZONE, getThingNumber(), 0).selectNamed()
@ -115,16 +115,11 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
return;
}
switch (channelUID.getId()) {
case CHANNEL_ZONE_BYPASS:
mode = CommandMessage.CMD_SECURITY_BYPASS_ZONE;
break;
case CHANNEL_ZONE_RESTORE:
mode = CommandMessage.CMD_SECURITY_RESTORE_ZONE;
break;
default:
mode = -1;
}
mode = switch (channelUID.getId()) {
case CHANNEL_ZONE_BYPASS -> 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<ExtendedZoneStatu
@Override
protected void updateChannels(ExtendedZoneStatus zoneStatus) {
// 0 Secure. 1 Not ready, 3 Trouble
int current = ((zoneStatus.getStatus() >> 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

View File

@ -49,11 +49,9 @@ 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:
if (CHANNEL_UNIT_LEVEL.equals(channelUID.getId())) {
handleUnitLevel(channelUID, command);
break;
default:
} else {
logger.debug("Unknown channel for Dimmable Unit thing: {}", channelUID);
super.handleCommand(channelUID, command);
}

View File

@ -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;
}

View File

@ -55,16 +55,14 @@ public class UpbUnitHandler extends DimmableUnitHandler {
return;
}
switch (channelUID.getId()) {
case CHANNEL_UPB_STATUS:
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);
}
break;
default:
} else {
logger.debug("Unknown channel for UPB Unit thing: {}", channelUID);
super.handleCommand(channelUID, command);
}