From 65be60036ed4adecae52d62b58a06e59a46f5bb8 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Tue, 28 Sep 2021 15:26:06 +0200 Subject: [PATCH 1/8] Externalize strings to support translation Signed-off-by: Mark Herwege --- .../handler/NikoHomeControlActionHandler.java | 26 ++- .../handler/NikoHomeControlBridgeHandler.java | 2 +- .../NikoHomeControlBridgeHandler1.java | 4 +- .../NikoHomeControlBridgeHandler2.java | 7 +- .../NikoHomeControlEnergyMeterHandler.java | 25 ++- .../NikoHomeControlThermostatHandler.java | 24 +-- .../nhc1/NikoHomeControlCommunication1.java | 4 +- .../nhc2/NikoHomeControlCommunication2.java | 11 +- .../main/resources/OH-INF/binding/binding.xml | 4 +- .../OH-INF/i18n/nikohomecontrol.properties | 120 ++++++++++++++ .../resources/OH-INF/thing/thing-types.xml | 156 +++++++++--------- 11 files changed, 243 insertions(+), 140 deletions(-) create mode 100644 bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/i18n/nikohomecontrol.properties diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java index 3cd76e9da2d16..183f03fc31b28 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java @@ -66,8 +66,8 @@ public NikoHomeControlActionHandler(Thing thing) { public void handleCommand(ChannelUID channelUID, Command command) { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Bridge communication not initialized when trying to execute action command " + actionId); + updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); return; } @@ -107,15 +107,10 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) { handleBrightnessCommand(command); updateStatus(ThingStatus.ONLINE); break; - case CHANNEL_ROLLERSHUTTER: handleRollershutterCommand(command); updateStatus(ThingStatus.ONLINE); break; - - default: - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Channel unknown " + channelUID.getId()); } } @@ -217,8 +212,6 @@ public void initialize() { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Connection with controller not started yet, could not initialize action " + actionId); return; } @@ -226,14 +219,14 @@ public void initialize() { scheduler.submit(() -> { if (!nhcComm.communicationActive()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No connection with controller, could not initialize action " + actionId); + "@text/offline.communication-error"); return; } NhcAction nhcAction = nhcComm.getActions().get(actionId); if (nhcAction == null) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Action " + actionId + " does not match an action in the controller"); + "@text/offline.configuration-error.actionId"); return; } @@ -313,7 +306,7 @@ public void actionEvent(int actionState) { break; default: updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Unknown action type " + actionType); + "@text/offline.configuration-error.actionType " + actionType); } } @@ -328,7 +321,7 @@ public void actionInitialized() { @Override public void actionRemoved() { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Action " + actionId + " has been removed from the controller"); + "@text/offline.configuration-error.actionRemoved"); } private void restartCommunication(NikoHomeControlCommunication nhcComm) { @@ -337,7 +330,8 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { nhcComm.restartCommunication(); // If still not active, take thing offline and return. if (!nhcComm.communicationActive()) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication error"); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.communication-error"); return; } // Also put the bridge back online @@ -351,7 +345,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler == null) { updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "No bridge initialized for action " + actionId); + "@text/offline.bridge-unitialized"); return null; } NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication(); @@ -362,7 +356,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { Bridge nhcBridge = getBridge(); if (nhcBridge == null) { updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "No bridge initialized for action " + actionId); + "@text/offline.bridge-unitialized"); return null; } NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler(); diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java index b7e4472ff5071..72708bb09d58e 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java @@ -141,7 +141,7 @@ private void setupRefreshTimer(int refreshInterval) { */ protected void bridgeOffline() { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, - "Error with bridge connection"); + "@text/offline.communication-error"); } /** diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java index e0938e1a2cdb1..74afecdf6d7d2 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java @@ -53,8 +53,8 @@ public void initialize() { nhcComm = new NikoHomeControlCommunication1(this, scheduler); startCommunication(); } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, - "Cannot resolve bridge IP with hostname " + config.addr); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, + "@text/offline.configuration-error.ip"); } } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java index e6687926e96a2..e0063f2065410 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler2.java @@ -69,14 +69,15 @@ public void initialize() { // advanced configuration, skipping token validation. // This behavior would allow the same logic to be used (with profile UUID) as before token validation // was introduced. - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, "Token is empty"); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, + "@text/offline.configuration-error.tokenEmpty"); return; } } else { Date now = new Date(); if (expiryDate.before(now)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, - "Hobby api token has expired"); + "@text/offline.configuration-error.tokenExpired"); return; } } @@ -90,7 +91,7 @@ public void initialize() { } catch (CertificateException e) { // this should not happen unless there is a programming error updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, - "Not able to set SSL context"); + "@text/offline.communication-error"); return; } } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java index 637f065f5af01..e5e9c7fca2eef 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java @@ -64,7 +64,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { return; } - if (command == REFRESH) { + if (REFRESH.equals(command)) { energyMeterEvent(nhcEnergyMeter.getPower()); } } @@ -77,8 +77,6 @@ public void initialize() { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Connection with controller not started yet, could not initialize energy meter " + energyMeterId); return; } @@ -87,14 +85,14 @@ public void initialize() { scheduler.submit(() -> { if (!nhcComm.communicationActive()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No connection with controller, could not initialize energy meter " + energyMeterId); + "@text/offline.communication-error"); return; } NhcEnergyMeter nhcEnergyMeter = nhcComm.getEnergyMeters().get(energyMeterId); if (nhcEnergyMeter == null) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Energy meter " + energyMeterId + " does not match a energy meter in the controller"); + "@text/offline.configuration-error.energyMeterId"); return; } @@ -163,7 +161,7 @@ public void energyMeterInitialized() { @Override public void energyMeterRemoved() { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Energy meter " + energyMeterId + " has been removed from the controller"); + "@text/offline.configuration-error.energyMeterRemoved"); } @Override @@ -172,8 +170,8 @@ public void energyMeterRemoved() { public void channelLinked(ChannelUID channelUID) { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Bridge communication not initialized when trying to start energy meter " + energyMeterId); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.communication-error"); return; } @@ -194,8 +192,8 @@ public void channelLinked(ChannelUID channelUID) { public void channelUnlinked(ChannelUID channelUID) { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Bridge communication not initialized when trying to stop energy meter " + energyMeterId); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.communication-error"); return; } @@ -220,7 +218,8 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { nhcComm.restartCommunication(); // If still not active, take thing offline and return. if (!nhcComm.communicationActive()) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication error"); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.communication-error"); return; } // Also put the bridge back online @@ -234,7 +233,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler == null) { updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "No bridge initialized for energy meter " + energyMeterId); + "@text/offline.bridge-unitialized"); return null; } NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication(); @@ -245,7 +244,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { Bridge nhcBridge = getBridge(); if (nhcBridge == null) { updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "No bridge initialized for energy meter " + energyMeterId); + "@text/offline.bridge-unitialized"); return null; } NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler(); diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java index d852f07ade143..27390708e993a 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java @@ -68,9 +68,8 @@ public NikoHomeControlThermostatHandler(Thing thing) { public void handleCommand(ChannelUID channelUID, Command command) { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Bridge communication not initialized when trying to execute thermostat command on " - + thermostatId); + updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); return; } @@ -143,10 +142,6 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) { } updateStatus(ThingStatus.ONLINE); break; - - default: - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Channel unknown " + channelUID.getId()); } } @@ -159,8 +154,6 @@ public void initialize() { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Connection with controller not started yet, could not initialize thermostat " + thermostatId); return; } @@ -169,14 +162,14 @@ public void initialize() { scheduler.submit(() -> { if (!nhcComm.communicationActive()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No connection with controller, could not initialize thermostat " + thermostatId); + "@text/offline.communication-error"); return; } NhcThermostat nhcThermostat = nhcComm.getThermostats().get(thermostatId); if (nhcThermostat == null) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Thermostat " + thermostatId + " does not match a thermostat in the controller"); + "@text/offline.configuration-error.thermostatId"); return; } @@ -288,7 +281,7 @@ public void thermostatInitialized() { @Override public void thermostatRemoved() { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Thermostat " + thermostatId + " has been removed from the controller"); + "@text/offline.configuration-error.thermostatRemoved"); } private void restartCommunication(NikoHomeControlCommunication nhcComm) { @@ -297,7 +290,8 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { nhcComm.restartCommunication(); // If still not active, take thing offline and return. if (!nhcComm.communicationActive()) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication error"); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.communication-error"); return; } // Also put the bridge back online @@ -311,7 +305,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler == null) { updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "No bridge initialized for thermostat " + thermostatId); + "@text/offline.bridge-unitialized"); return null; } NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication(); @@ -322,7 +316,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { Bridge nhcBridge = getBridge(); if (nhcBridge == null) { updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "No bridge initialized for thermostat " + thermostatId); + "@text/offline.bridge-unitialized"); return null; } NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler(); diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java index a2c8b7bd40908..3274eba2193f2 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java @@ -117,7 +117,7 @@ public synchronized void startCommunication() { } catch (IOException | InterruptedException e) { stopCommunication(); - handler.controllerOffline("Error initializing communication"); + handler.controllerOffline("@text/offline.communication-error"); } } @@ -227,7 +227,7 @@ private synchronized void sendMessage(Object nhcMessage) { logger.debug("resend json {}", json); nhcOut.println(json); if (nhcOut.checkError()) { - handler.controllerOffline("Error resending message"); + handler.controllerOffline("@text/offline.communication-error"); } } } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java index d77caa49ba861..722346fcd74c5 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java @@ -778,8 +778,7 @@ private void sendDeviceMessage(String topic, String gsonMessage) { mqttConnection.connectionPublish(topic, gsonMessage); } catch (MqttException e) { - String message = e.getMessage(); - message = (message != null) ? message : "Communication error"; + String message = e.getLocalizedMessage(); logger.debug("sending command failed, trying to restart communication"); restartCommunication(); @@ -791,12 +790,12 @@ private void sendDeviceMessage(String topic, String gsonMessage) { logger.debug("failed to restart communication"); } } catch (MqttException e1) { - message = e1.getMessage(); - message = (message != null) ? message : "Communication error"; + message = e1.getLocalizedMessage(); logger.debug("error resending device command"); } if (!communicationActive()) { + message = (message != null) ? message : "@text/offline.communication-error"; connectionLost(message); } } @@ -862,8 +861,8 @@ public String getServices() { public void connectionStateChanged(MqttConnectionState state, @Nullable Throwable error) { if (error != null) { logger.debug("Connection state: {}", state, error); - String message = error.getMessage(); - message = (message != null) ? message : "Error communicating with the controller"; + String message = error.getLocalizedMessage(); + message = (message != null) ? message : "@text/offline.communication-error"; if (!MqttConnectionState.CONNECTING.equals(state)) { // This is a connection loss, try to restart restartCommunication(); diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/binding/binding.xml index fb1a80c26819e..e83e74d10aeda 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/binding/binding.xml @@ -3,6 +3,6 @@ xmlns:binding="https://openhab.org/schemas/binding/v1.0.0" xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd"> - Niko Home Control Binding - This is the binding for the Niko Home Control system + @text/bindingName + @text/bindingDescription diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/i18n/nikohomecontrol.properties b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/i18n/nikohomecontrol.properties new file mode 100644 index 0000000000000..e7c7a4ce0b8da --- /dev/null +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/i18n/nikohomecontrol.properties @@ -0,0 +1,120 @@ +# binding +bindingName = Niko Home Control Binding +bindingDescription = This is the binding for the Niko Home Control system + +# bridge types +bridgeLabel = Niko Home Control I Bridge +bridgeDescription = This bridge represents a Niko Home Control I IP-interface + +bridge2Label = Niko Home Control II Bridge +bridge2Description = This bridge represents a Niko Home Control II Connected Controller or Wireless Smart Hub + +bridgeConfigAddressLabel = IP or Host Name +bridgeConfigAddressDescription = IP Address of Niko Home Control IP-interface +bridge2ConfigAddressDescription = IP Address of Connected Controller or Wireless Smart Hub + +bridgeConfigPortLabel = Bridge Port +bridgeConfigPortDescription = Port to communicate with Niko Home Control IP-interface, default 8000 +bridge2ConfigPortDescription = Port for secure MQTT communication with Connected Controller or Wireless Smart Hub, default 8884 + +bridge2ConfigProfileLabel = Profile +bridge2ConfigProfileDescription = Profile used in Niko Home Control II for hobby API + +bridge2ConfigPasswordLabel = API Token +bridge2ConfigPasswordDescription = Token for Niko Home Control II hobby API, should not be empty. This token will have to be renewed after expiration (1 year after creation) + +bridgeConfigRefreshLabel = Refresh Interval +bridgeConfigRefreshDescription = Refresh interval for connection with Niko Home Control IP-interface (min), default 300. If set to 0 or left empty, no refresh will be scheduled +bridge2ConfigRefreshDescription = Refresh interval for connection with Connected Controller or Wireless Smart Hub (min), default 300. If set to 0 or left empty, no refresh will be scheduled + +# thing types +pushButtonLabel = Pushbutton +pushButtonDescription = Pushbutton type action in Niko Home Control + +onOffLabel = Switch +onOffDescription = On/Off type action in Niko Home Control + +dimmerLabel = Dimmer +dimmerDescription = Dimmer type action in Niko Home Control + +blindLabel = Shutter +blindDescription = Rollershutter type action in Niko Home Control + +thermostatLabel = Thermostat +thermostatDescription = Thermostat in the Niko Home Control system + +energyMeterLabel = Energy Meter +energyMeterDescription = Energy meter in the Niko Home Control system + +actionConfigActionIdLabel = Action ID +actionConfigActionIdDescription = Niko Home Control action ID + +dimmerConfigStepLabel = Step Value +dimmerConfigStepDescription = Step value used for increase/decrease of dimmer brightness, default 10% + +blindConfigInvertLabel = Invert Direction +blindConfigInvertDescription = Invert rollershutter direction + +thermostatConfigThermostatIdLabel = Thermostat ID +thermostatConfigThermostatIdDescription = Niko Home Control Thermostat ID + +thermostatConfigOverruleTimeLabel = Overrule Time +thermostatConfigOverruleTimeDescription = Default overrule duration in minutes when an overrule temperature is set without providing overrule \ + time, 60 minutes by default + +energyMeterConfigEnergyMeterIdLabel = Energy Meter ID +energyMeterConfigEnergyMeterIdDescription = Niko Home Control Energy Meter ID + +#channel types +channelButtonLabel = Button +channelButtonDescription = Pushbutton control for action in Niko Home Control + +channelRollershutterLabel = Rollershutter +channelRollershutterDescription = Rollershutter control for rollershutter action in Niko Home Control + +channelMeasuredLabel = Measured +channelMeasuredDescription = Temperature measured by thermostat + +channelSetpointLabel = Setpoint +channelSetpointDescription = Setpoint temperature of thermostat + +channelOverruletimeLabel = Overrule Time +channelOverruletimeDescription = Time duration for overruling thermostat target temperature in min. + +channelModeLabel = Mode +channelModeDescription = Thermostat mode +channelModeOption0 = day +channelModeOption1 = night +channelModeOption2 = eco +channelModeOption3 = off +channelModeOption4 = cool +channelModeOption5 = prog 1 +channelModeOption6 = prog 2 +channelModeOption7 = prog 3 + +channelPowerLabel = Power +channelPowerDescription = Momentary power consumption/production (positive is consumption) + +channelAlarmLabel = Alarm +channelAlarmDescription = Alarm from Niko Home Control + +channelNoticeLabel = Notice +channelNoticeDescription = Notice from Niko Home Control + +# thing status messages +offline.configuration-error.ip = Cannot resolve bridge IP with given host name +offline.configuration-error.tokenEmpty = Hobby API token is empty +offline.configuration-error.tokenExpired = Hobby API token has expired + +offline.configuration-error.actionId = Configured action ID does not match an action in controller +offline.configuration-error.actionType = Unsupported action type +offline.configuration-error.actionRemoved = Action has been removed from controller + +offline.configuration-error.energyMeterId = Configured energy meter ID does not match an energy meter in controller +offline.configuration-error.energyMeterRemoved = Energy meter has been removed from controller + +offline.configuration-error.thermostatId = Configured thermostat ID does not match an thermostat in controller +offline.configuration-error.thermostatRemoved = Thermostat has been removed from controller + +offline.communication-error = Error communicating with controller +offline.bridge-unitialized = Bridge not initialized diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml index 362b08fd33abd..22d82ca18f01e 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml @@ -5,70 +5,67 @@ xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> - - This bridge represents a Niko Home Control I IP-interface + + @text/bridgeDescription - - IP Address of Niko Home Control IP-interface + + @text/bridgeConfigAddressDescription false network-address - - Port to communicate with Niko Home Control IP-interface, default 8000 + + @text/bridgeConfigPortDescription 8000 true - - Refresh interval for connection with Niko Home Control IP-interface (min), default 300. If set to 0 or - left empty, no refresh will be scheduled + + @text/bridgeConfigRefreshDescription 300 true - - This bridge represents a Niko Home Control II Connected Controller + + @text/bridge2Description - - IP Address of Connected Controller + + @text/bridge2ConfigAddressDescription false network-address - - Port for secure MQTT communication with Connected Controller, default 8884 + + @text/bridge2ConfigPortDescription 8884 true - - Profile used in Niko Home Control II for hobby API + + @text/bridge2ConfigProfileDescription hobby true - - Token for Niko Home Control II hobby API, should not be empty. This token will have to be renewed after - expiration (1 year after creation) + + @text/bridge2ConfigPasswordDescription password - - Refresh interval for connection with Connected Controller (min), default 300. If set to 0 or left - empty, no refresh will be scheduled + + @text/bridge2ConfigRefreshDescription 300 true @@ -80,15 +77,15 @@ - - Pushbutton type action in Niko Home Control + + @text/pushButtonDescription - - Niko Home Control action ID + + @text/actionConfigActionIdDescription false @@ -98,15 +95,15 @@ - - On/Off type action in Niko Home Control + + @text/onOffDescription - - Niko Home Control action ID + + @text/actionConfigActionIdDescription false @@ -116,20 +113,20 @@ - - Dimmer type action in Niko Home Control + + @text/dimmerDescription - - Niko Home Control action ID + + @text/actionConfigActionIdDescription false - - Step value used for increase/decrease of dimmer brightness, default 10% + + @text/dimmerConfigStepValue 10 true @@ -140,20 +137,20 @@ - - Rollershutter type action in Niko Home Control + + @text/blindDescription - - Niko Home Control action ID + + @text/actionConfigActionIdDescription false - - Invert rollershutter direction + + @text/blindConfigInvertDescription false true @@ -164,8 +161,8 @@ - - Thermostat in the Niko Home Control system + + @textThermostatDescription @@ -174,14 +171,13 @@ - - Niko Home Control Thermostat ID + + @text/thermostatConfigThermostatIdDescription false - - Default overrule duration in minutes when an overrule temperature is set without providing overrule - time, 60 minutes by default + + @text/thermostatConfigOverruleTimeDescription 60 true @@ -191,15 +187,15 @@ - - Energy meter in the Niko Home Control system + + @text/energyMeterDescription - - Niko Home Control Energy Meter ID + + @text/energyMeterConfigEnergyMeterIdDescription false @@ -207,22 +203,22 @@ Switch - - Pushbutton control for action in Niko Home Control + + @text/channelButtonDescription Switch veto Rollershutter - - Rollershutter control for rollershutter action in Niko Home Control + + @text/channelRollershutterDescription Blinds Number:Temperature - - Temperature measured by thermostat + + @text/channelMeasuredDescription Temperature Measurement @@ -232,8 +228,8 @@ Number:Temperature - - Setpoint temperature of thermostat + + @text/channelSetpointDescription Temperature Setpoint @@ -243,33 +239,33 @@ Number - - Time duration for overruling thermostat target temperature in min. + + @text/channelOverruletimeDescription Number Number - - Thermostat mode + + @text/channelModeDescription Number - - - - - - - - + + + + + + + + Number:Power - - Momentary power consumption/production (positive is consumption) + + @text/channelPowerDescription Number @@ -277,13 +273,13 @@ trigger - - Alarm from Niko Home Control + + @text/channelAlarmDescription trigger - - Notice from Niko Home Control + + @text/channelNoticeDescription From 370af8bb2b2d6f2e466cefd593f50873c6dd20e7 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Tue, 28 Sep 2021 15:50:57 +0200 Subject: [PATCH 2/8] Name events thread. Signed-off-by: Mark Herwege --- .../internal/NikoHomeControlBindingConstants.java | 3 +++ .../handler/NikoHomeControlBridgeHandler1.java | 5 ++++- .../protocol/nhc1/NikoHomeControlCommunication1.java | 10 ++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java index d140f2a12fa51..ebf2810822989 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java @@ -31,6 +31,9 @@ public class NikoHomeControlBindingConstants { public static final String BINDING_ID = "nikohomecontrol"; + // Listener threadname prefix + public static final String THREAD_NAME_PREFIX = "OH-" + BINDING_ID + "-"; + // List of all Thing Type UIDs // bridge diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java index 74afecdf6d7d2..8a7de65a62b18 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler1.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.nikohomecontrol.internal.handler; +import static org.openhab.binding.nikohomecontrol.internal.NikoHomeControlBindingConstants.THREAD_NAME_PREFIX; + import java.net.InetAddress; import java.util.HashMap; import java.util.Map; @@ -50,7 +52,8 @@ public void initialize() { logger.debug("bridge handler host {}, port {}", addr, port); if (addr != null) { - nhcComm = new NikoHomeControlCommunication1(this, scheduler); + String eventThreadName = THREAD_NAME_PREFIX + thing.getUID().getAsString(); + nhcComm = new NikoHomeControlCommunication1(this, scheduler, eventThreadName); startCommunication(); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java index 3274eba2193f2..abf3e9ae0524e 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.nikohomecontrol.internal.protocol.nhc1; +import static org.openhab.binding.nikohomecontrol.internal.NikoHomeControlBindingConstants.THREAD_NAME_PREFIX; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -56,6 +58,8 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication private Logger logger = LoggerFactory.getLogger(NikoHomeControlCommunication1.class); + private String eventThreadName = THREAD_NAME_PREFIX + ""; + private final NhcSystemInfo1 systemInfo = new NhcSystemInfo1(); private final Map locations = new ConcurrentHashMap<>(); @@ -77,9 +81,11 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication * Niko Home Control IP-interface. * */ - public NikoHomeControlCommunication1(NhcControllerEvent handler, ScheduledExecutorService scheduler) { + public NikoHomeControlCommunication1(NhcControllerEvent handler, ScheduledExecutorService scheduler, + String eventThreadName) { super(handler); this.scheduler = scheduler; + this.eventThreadName = eventThreadName; // When we set up this object, we want to get the proper gson adapter set up once GsonBuilder gsonBuilder = new GsonBuilder(); @@ -113,7 +119,7 @@ public synchronized void startCommunication() { // Start Niko Home Control event listener. This listener will act on all messages coming from // IP-interface. - (new Thread(this::runNhcEvents)).start(); + (new Thread(this::runNhcEvents, eventThreadName)).start(); } catch (IOException | InterruptedException e) { stopCommunication(); From eda9ca3805f962dcbab970ccc48eefdf7c804960 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Wed, 29 Sep 2021 09:05:05 +0200 Subject: [PATCH 3/8] Fix formatting Signed-off-by: Mark Herwege --- .../src/main/resources/OH-INF/thing/thing-types.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml index 22d82ca18f01e..e75e3a666f7be 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml @@ -102,8 +102,8 @@ - - @text/actionConfigActionIdDescription + + @text/actionConfigActionIdDescription false @@ -120,8 +120,8 @@ - - @text/actionConfigActionIdDescription + + @text/actionConfigActionIdDescription false @@ -144,8 +144,8 @@ - - @text/actionConfigActionIdDescription + + @text/actionConfigActionIdDescription false From bad007432e3fed427f771ac528616cc749073f3f Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Wed, 29 Sep 2021 09:12:26 +0200 Subject: [PATCH 4/8] Fix SAT warning Signed-off-by: Mark Herwege --- .../internal/protocol/NikoHomeControlDiscover.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlDiscover.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlDiscover.java index 708e399929f54..5b75ab8359fa0 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlDiscover.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlDiscover.java @@ -105,10 +105,7 @@ public String getNhcBridgeId() { */ private boolean isNhc(DatagramPacket packet) { byte[] packetData = packet.getData(); - if ((packet.getLength() > 2) && (packetData[0] == 0x44)) { - return true; - } - return false; + return ((packet.getLength() > 2) && (packetData[0] == 0x44)); } /** From b34569b0c05f08ba04340c7ad857942d4b37307a Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Mon, 4 Oct 2021 08:51:36 +0200 Subject: [PATCH 5/8] Fix threadname Signed-off-by: Mark Herwege --- .../internal/NikoHomeControlBindingConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java index ebf2810822989..a411f5c3c2a11 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/NikoHomeControlBindingConstants.java @@ -32,7 +32,7 @@ public class NikoHomeControlBindingConstants { public static final String BINDING_ID = "nikohomecontrol"; // Listener threadname prefix - public static final String THREAD_NAME_PREFIX = "OH-" + BINDING_ID + "-"; + public static final String THREAD_NAME_PREFIX = "OH-binding-"; // List of all Thing Type UIDs From 2de47777cbdd416b980c094a63c44d53eda6e01d Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Mon, 11 Oct 2021 09:04:59 +0200 Subject: [PATCH 6/8] Fix thing lifecycle. Signed-off-by: Mark Herwege --- .../handler/NikoHomeControlActionHandler.java | 12 +++++++++--- .../handler/NikoHomeControlBridgeHandler.java | 2 ++ .../handler/NikoHomeControlEnergyMeterHandler.java | 8 ++++++-- .../handler/NikoHomeControlThermostatHandler.java | 12 +++++++++--- .../protocol/nhc1/NikoHomeControlCommunication1.java | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java index 183f03fc31b28..ffa50b9326a86 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java @@ -66,7 +66,7 @@ public NikoHomeControlActionHandler(Thing thing) { public void handleCommand(ChannelUID channelUID, Command command) { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return; } @@ -111,6 +111,8 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) { handleRollershutterCommand(command); updateStatus(ThingStatus.ONLINE); break; + default: + logger.debug("channel unknown {}", channelUID.getId()); } } @@ -212,7 +214,11 @@ public void initialize() { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); return; + } else { + updateStatus(ThingStatus.UNKNOWN); } // We need to do this in a separate thread because we may have to wait for the communication to become active @@ -344,7 +350,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { private @Nullable NikoHomeControlCommunication getCommunication() { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return null; } @@ -355,7 +361,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { private @Nullable NikoHomeControlBridgeHandler getBridgeHandler() { Bridge nhcBridge = getBridge(); if (nhcBridge == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return null; } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java index 72708bb09d58e..d035c9d543565 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlBridgeHandler.java @@ -77,6 +77,8 @@ protected void startCommunication() { return; } + updateStatus(ThingStatus.UNKNOWN); + scheduler.submit(() -> { comm.startCommunication(); if (!comm.communicationActive()) { diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java index e5e9c7fca2eef..a6d84ee88409c 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java @@ -77,7 +77,11 @@ public void initialize() { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); return; + } else { + updateStatus(ThingStatus.UNKNOWN); } // We need to do this in a separate thread because we may have to wait for the @@ -232,7 +236,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { private @Nullable NikoHomeControlCommunication getCommunication() { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return null; } @@ -243,7 +247,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { private @Nullable NikoHomeControlBridgeHandler getBridgeHandler() { Bridge nhcBridge = getBridge(); if (nhcBridge == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return null; } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java index 27390708e993a..4fa20d7cd0794 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java @@ -68,7 +68,7 @@ public NikoHomeControlThermostatHandler(Thing thing) { public void handleCommand(ChannelUID channelUID, Command command) { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return; } @@ -142,6 +142,8 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) { } updateStatus(ThingStatus.ONLINE); break; + default: + logger.debug("channel unknown {}", channelUID.getId()); } } @@ -154,7 +156,11 @@ public void initialize() { NikoHomeControlCommunication nhcComm = getCommunication(); if (nhcComm == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); return; + } else { + updateStatus(ThingStatus.UNKNOWN); } // We need to do this in a separate thread because we may have to wait for the @@ -304,7 +310,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { private @Nullable NikoHomeControlCommunication getCommunication() { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return null; } @@ -315,7 +321,7 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { private @Nullable NikoHomeControlBridgeHandler getBridgeHandler() { Bridge nhcBridge = getBridge(); if (nhcBridge == null) { - updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.BRIDGE_UNINITIALIZED, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "@text/offline.bridge-unitialized"); return null; } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java index abf3e9ae0524e..c1f1c6b445dd5 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc1/NikoHomeControlCommunication1.java @@ -58,7 +58,7 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication private Logger logger = LoggerFactory.getLogger(NikoHomeControlCommunication1.class); - private String eventThreadName = THREAD_NAME_PREFIX + ""; + private String eventThreadName = THREAD_NAME_PREFIX; private final NhcSystemInfo1 systemInfo = new NhcSystemInfo1(); private final Map locations = new ConcurrentHashMap<>(); From 3bf9864d71a8e0582b6a52c763eb4b6a43fcaff1 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Fri, 22 Oct 2021 17:44:58 +0200 Subject: [PATCH 7/8] Adjustments from review. Signed-off-by: Mark Herwege --- .../handler/NikoHomeControlActionHandler.java | 23 ++---- .../NikoHomeControlEnergyMeterHandler.java | 80 ++++++++----------- .../NikoHomeControlThermostatHandler.java | 21 ++--- 3 files changed, 45 insertions(+), 79 deletions(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java index ffa50b9326a86..476a944ce47ba 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java @@ -92,7 +92,7 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) { logger.debug("handle command {} for {}", command, channelUID); - if (command == REFRESH) { + if (REFRESH.equals(command)) { actionEvent(nhcAction.getState()); return; } @@ -112,7 +112,7 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) { updateStatus(ThingStatus.ONLINE); break; default: - logger.debug("channel unknown {}", channelUID.getId()); + logger.debug("unexpected command for channel {}", channelUID.getId()); } } @@ -344,28 +344,19 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler != null) { nhcBridgeHandler.bridgeOnline(); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); } } private @Nullable NikoHomeControlCommunication getCommunication() { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); - if (nhcBridgeHandler == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "@text/offline.bridge-unitialized"); - return null; - } - NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication(); - return nhcComm; + return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null; } private @Nullable NikoHomeControlBridgeHandler getBridgeHandler() { Bridge nhcBridge = getBridge(); - if (nhcBridge == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "@text/offline.bridge-unitialized"); - return null; - } - NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler(); - return nhcBridgeHandler; + return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null; } } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java index a6d84ee88409c..96b1ef5c85e09 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlEnergyMeterHandler.java @@ -173,47 +173,40 @@ public void energyMeterRemoved() { // the channel public void channelLinked(ChannelUID channelUID) { NikoHomeControlCommunication nhcComm = getCommunication(); - if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error"); - return; + if (nhcComm != null) { + // This can be expensive, therefore do it in a job. + scheduler.submit(() -> { + if (!nhcComm.communicationActive()) { + restartCommunication(nhcComm); + } + + if (nhcComm.communicationActive()) { + nhcComm.startEnergyMeter(energyMeterId); + updateStatus(ThingStatus.ONLINE); + } + }); } - - // This can be expensive, therefore do it in a job. - scheduler.submit(() -> { - if (!nhcComm.communicationActive()) { - restartCommunication(nhcComm); - } - - if (nhcComm.communicationActive()) { - nhcComm.startEnergyMeter(energyMeterId); - updateStatus(ThingStatus.ONLINE); - } - }); } @Override public void channelUnlinked(ChannelUID channelUID) { NikoHomeControlCommunication nhcComm = getCommunication(); - if (nhcComm == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error"); - return; + if (nhcComm != null) { + // This can be expensive, therefore do it in a job. + scheduler.submit(() -> { + if (!nhcComm.communicationActive()) { + restartCommunication(nhcComm); + } + + if (nhcComm.communicationActive()) { + nhcComm.stopEnergyMeter(energyMeterId); + // as this is momentary power production/consumption, we set it UNDEF as we do not get readings + // anymore + updateState(CHANNEL_POWER, UnDefType.UNDEF); + updateStatus(ThingStatus.ONLINE); + } + }); } - - // This can be expensive, therefore do it in a job. - scheduler.submit(() -> { - if (!nhcComm.communicationActive()) { - restartCommunication(nhcComm); - } - - if (nhcComm.communicationActive()) { - nhcComm.stopEnergyMeter(energyMeterId); - // as this is momentary power production/consumption, we set it UNDEF as we do not get readings anymore - updateState(CHANNEL_POWER, UnDefType.UNDEF); - updateStatus(ThingStatus.ONLINE); - } - }); } private void restartCommunication(NikoHomeControlCommunication nhcComm) { @@ -230,28 +223,19 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler != null) { nhcBridgeHandler.bridgeOnline(); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); } } private @Nullable NikoHomeControlCommunication getCommunication() { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); - if (nhcBridgeHandler == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "@text/offline.bridge-unitialized"); - return null; - } - NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication(); - return nhcComm; + return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null; } private @Nullable NikoHomeControlBridgeHandler getBridgeHandler() { Bridge nhcBridge = getBridge(); - if (nhcBridge == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "@text/offline.bridge-unitialized"); - return null; - } - NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler(); - return nhcBridgeHandler; + return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null; } } diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java index 4fa20d7cd0794..4b71fa2760c95 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java @@ -143,7 +143,7 @@ private void handleCommandSelection(ChannelUID channelUID, Command command) { updateStatus(ThingStatus.ONLINE); break; default: - logger.debug("channel unknown {}", channelUID.getId()); + logger.debug("unexpected command for channel {}", channelUID.getId()); } } @@ -304,28 +304,19 @@ private void restartCommunication(NikoHomeControlCommunication nhcComm) { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); if (nhcBridgeHandler != null) { nhcBridgeHandler.bridgeOnline(); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, + "@text/offline.bridge-unitialized"); } } private @Nullable NikoHomeControlCommunication getCommunication() { NikoHomeControlBridgeHandler nhcBridgeHandler = getBridgeHandler(); - if (nhcBridgeHandler == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "@text/offline.bridge-unitialized"); - return null; - } - NikoHomeControlCommunication nhcComm = nhcBridgeHandler.getCommunication(); - return nhcComm; + return nhcBridgeHandler != null ? nhcBridgeHandler.getCommunication() : null; } private @Nullable NikoHomeControlBridgeHandler getBridgeHandler() { Bridge nhcBridge = getBridge(); - if (nhcBridge == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, - "@text/offline.bridge-unitialized"); - return null; - } - NikoHomeControlBridgeHandler nhcBridgeHandler = (NikoHomeControlBridgeHandler) nhcBridge.getHandler(); - return nhcBridgeHandler; + return nhcBridge != null ? (NikoHomeControlBridgeHandler) nhcBridge.getHandler() : null; } } From 98bd4eb9d2f96b26b3dadc525147a9f3da939072 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Sat, 23 Oct 2021 09:12:11 +0200 Subject: [PATCH 8/8] Adjustment from review. Signed-off-by: Mark Herwege --- .../internal/handler/NikoHomeControlActionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java index 476a944ce47ba..9003d502253e6 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java @@ -312,7 +312,7 @@ public void actionEvent(int actionState) { break; default: updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "@text/offline.configuration-error.actionType " + actionType); + "@text/offline.configuration-error.actionType"); } }