]> git.basschouten.com Git - openhab-addons.git/commitdiff
Various small enhancements (#11874)
authorKai Kreuzer <kai@openhab.org>
Tue, 28 Dec 2021 18:27:45 +0000 (19:27 +0100)
committerGitHub <noreply@github.com>
Tue, 28 Dec 2021 18:27:45 +0000 (19:27 +0100)
- do not go from INITIALIZING to OFFLINE and then ONLINE, but skip OFFLINE for panels, if the controller is ONLINE
- reduce logging to debug when receiving trigger events
- only update Thing configuration if necessary to avoid Thing updated events
- fix description of model types, which was outdated due to new models being available by now

Signed-off-by: Kai Kreuzer <kai.kreuzer@telekom.de>
bundles/org.openhab.binding.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/handler/NanoleafControllerHandler.java
bundles/org.openhab.binding.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/handler/NanoleafPanelHandler.java
bundles/org.openhab.binding.nanoleaf/src/main/resources/OH-INF/i18n/nanoleaf.properties
bundles/org.openhab.binding.nanoleaf/src/main/resources/OH-INF/i18n/nanoleaf_de.properties

index 0ab54cc9a41adb7d48443f46fb72a4f05f261c37..f72ff5ba8305f8ecad3ea6919f7b545d38f2017c 100644 (file)
@@ -144,6 +144,7 @@ public class NanoleafControllerHandler extends BaseBridgeHandler {
         logger.debug("Using long SSE httpClient={} for {}}", httpClientSSETouchEvent, httpClientName);
     }
 
+    @Override
     public void initialize() {
         logger.debug("Initializing the controller (bridge)");
         updateStatus(ThingStatus.UNKNOWN);
@@ -199,6 +200,7 @@ public class NanoleafControllerHandler extends BaseBridgeHandler {
         }
     }
 
+    @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
         logger.debug("Received command {} for channel {}", command, channelUID);
         if (!ThingStatus.ONLINE.equals(getThing().getStatusInfo().getStatus())) {
@@ -565,7 +567,7 @@ public class NanoleafControllerHandler extends BaseBridgeHandler {
 
     private void handleTouchEvents(TouchEvents touchEvents) {
         touchEvents.getEvents().forEach((event) -> {
-            logger.info("panel: {} gesture id: {}", event.getPanelId(), event.getGesture());
+            logger.debug("panel: {} gesture id: {}", event.getPanelId(), event.getGesture());
             // Swipes go to the controller, taps go to the individual panel
             if (event.getPanelId().equals(CONTROLLER_PANEL_ID)) {
                 logger.debug("Triggering controller {} with gesture {}.", thing.getUID(), event.getGesture());
@@ -628,8 +630,8 @@ public class NanoleafControllerHandler extends BaseBridgeHandler {
             hue = min == null ? 0 : min;
             Integer max = colorTemperature.getMax();
             saturation = max == null ? 0 : max;
-            colorTempPercent = (float) ((colorTemperature.getValue() - hue) / (saturation - hue)
-                    * PercentType.HUNDRED.intValue());
+            colorTempPercent = (colorTemperature.getValue() - hue) / (saturation - hue)
+                    * PercentType.HUNDRED.intValue();
         }
 
         updateState(CHANNEL_COLOR_TEMPERATURE, new PercentType(Float.toString(colorTempPercent)));
@@ -650,30 +652,6 @@ public class NanoleafControllerHandler extends BaseBridgeHandler {
         updateState(CHANNEL_RHYTHM_MODE, new DecimalType(controllerInfo.getRhythm().getRhythmMode()));
         updateState(CHANNEL_RHYTHM_STATE,
                 controllerInfo.getRhythm().getRhythmConnected() ? OnOffType.ON : OnOffType.OFF);
-        // update bridge properties which may have changed, or are not present during discovery
-        Map<String, String> properties = editProperties();
-        properties.put(Thing.PROPERTY_SERIAL_NUMBER, controllerInfo.getSerialNo());
-        properties.put(Thing.PROPERTY_FIRMWARE_VERSION, controllerInfo.getFirmwareVersion());
-        properties.put(Thing.PROPERTY_MODEL_ID, controllerInfo.getModel());
-        properties.put(Thing.PROPERTY_VENDOR, controllerInfo.getManufacturer());
-        updateProperties(properties);
-        Configuration config = editConfiguration();
-        if (hasTouchSupport(controllerInfo.getModel())) {
-            config.put(NanoleafControllerConfig.DEVICE_TYPE, DEVICE_TYPE_TOUCHSUPPORT);
-            logger.debug("Set to device type {}", DEVICE_TYPE_TOUCHSUPPORT);
-        } else {
-            config.put(NanoleafControllerConfig.DEVICE_TYPE, DEVICE_TYPE_LIGHTPANELS);
-            logger.debug("Set to device type {}", DEVICE_TYPE_LIGHTPANELS);
-        }
-        updateConfiguration(config);
-
-        getConfig().getProperties().forEach((key, value) -> {
-            logger.trace("Configuration property: key {} value {}", key, value);
-        });
-
-        getThing().getProperties().forEach((key, value) -> {
-            logger.debug("Thing property:  key {} value {}", key, value);
-        });
 
         // update the color channels of each panel
         getThing().getThings().forEach(child -> {
@@ -684,11 +662,49 @@ public class NanoleafControllerHandler extends BaseBridgeHandler {
             }
         });
 
+        updateProperties();
+        updateConfiguration();
+
         for (NanoleafControllerListener controllerListener : controllerListeners) {
             controllerListener.onControllerInfoFetched(getThing().getUID(), controllerInfo);
         }
     }
 
+    private void updateConfiguration() {
+        // only update the Thing config if value isn't set yet
+        if (getConfig().get(NanoleafControllerConfig.DEVICE_TYPE) == null) {
+            Configuration config = editConfiguration();
+            if (hasTouchSupport(controllerInfo.getModel())) {
+                config.put(NanoleafControllerConfig.DEVICE_TYPE, DEVICE_TYPE_TOUCHSUPPORT);
+                logger.debug("Set to device type {}", DEVICE_TYPE_TOUCHSUPPORT);
+            } else {
+                config.put(NanoleafControllerConfig.DEVICE_TYPE, DEVICE_TYPE_LIGHTPANELS);
+                logger.debug("Set to device type {}", DEVICE_TYPE_LIGHTPANELS);
+            }
+            updateConfiguration(config);
+            if (logger.isTraceEnabled()) {
+                getConfig().getProperties().forEach((key, value) -> {
+                    logger.trace("Configuration property: key {} value {}", key, value);
+                });
+            }
+        }
+    }
+
+    private void updateProperties() {
+        // update bridge properties which may have changed, or are not present during discovery
+        Map<String, String> properties = editProperties();
+        properties.put(Thing.PROPERTY_SERIAL_NUMBER, controllerInfo.getSerialNo());
+        properties.put(Thing.PROPERTY_FIRMWARE_VERSION, controllerInfo.getFirmwareVersion());
+        properties.put(Thing.PROPERTY_MODEL_ID, controllerInfo.getModel());
+        properties.put(Thing.PROPERTY_VENDOR, controllerInfo.getManufacturer());
+        updateProperties(properties);
+        if (logger.isTraceEnabled()) {
+            getThing().getProperties().forEach((key, value) -> {
+                logger.trace("Thing property: key {} value {}", key, value);
+            });
+        }
+    }
+
     private ControllerInfo receiveControllerInfo() throws NanoleafException, NanoleafUnauthorizedException {
         ContentResponse controllerlInfoJSON = OpenAPIUtils.sendOpenAPIRequest(OpenAPIUtils.requestBuilder(httpClient,
                 getControllerConfig(), API_GET_CONTROLLER_INFO, HttpMethod.GET));
index 020f55f57b7b2bd472c8719f4dd359ee2415069b..37dffd6159d8e175ff38328c100d3fc932be4221 100644 (file)
@@ -90,7 +90,6 @@ public class NanoleafPanelHandler extends BaseThingHandler {
     @Override
     public void initialize() {
         logger.debug("Initializing handler for panel {}", getThing().getUID());
-        updateStatus(ThingStatus.OFFLINE);
         Bridge controller = getBridge();
         if (controller == null) {
             initializePanel(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, ""));
index bbd4ea80963b1965bbc2ad3cc1419cd3c8b629e0..01abe9afac3ed5f694d6a7360915ad2d4ec6276c 100644 (file)
@@ -17,8 +17,8 @@ thing-type.config.nanoleaf.controller.authToken.description = Authorization toke
 thing-type.config.nanoleaf.controller.refreshInterval.label = Refresh Interval
 thing-type.config.nanoleaf.controller.refreshInterval.description = Interval (in seconds) to refresh the controller channels status
 thing-type.config.nanoleaf.controller.deviceType.label = Nanoleaf Device Type
-thing-type.config.nanoleaf.controller.deviceType.description = Light Panels (triangles) or Canvas (squares)
-thing-type.config.nanoleaf.lightpanel.id.label = ID Of The Panel
+thing-type.config.nanoleaf.controller.deviceType.description = Light Panels (older triangle models) or Canvas/Shapes (newer models as squares, triangles, hexagons, etc.)
+thing-type.config.nanoleaf.lightpanel.id.label = Panel ID
 thing-type.config.nanoleaf.lightpanel.id.description = The ID of the panel assigned by the controller
 
 # channel types
index 3612a5858b4bc0037a7be3dbf98084cdfebdd73e..37da0e06e1fbf5a8203adfd97024018b9ec26622 100644 (file)
@@ -17,8 +17,8 @@ thing-type.config.nanoleaf.controller.authToken.description = Token zur Authenti
 thing-type.config.nanoleaf.controller.refreshInterval.label = Aktualisierungsintervall
 thing-type.config.nanoleaf.controller.refreshInterval.description = Intervall (in Sekunden) in dem die Kanäle aktualisiert werden
 thing-type.config.nanoleaf.controller.deviceType.label = Nanoleaf Gerätetyp
-thing-type.config.nanoleaf.controller.deviceType.description = Light Panels (Dreiecke) oder Canvas (Quadrate)
-thing-type.config.nanoleaf.lightpanel.id.label = Paneel ID
+thing-type.config.nanoleaf.controller.deviceType.description = Light Panels (alte Dreieck-Modelle) oder Canvas/Shapes (neue Modelle als Quadrat, Dreieck, Hexagon, etc.)
+thing-type.config.nanoleaf.lightpanel.id.label = Panel ID
 thing-type.config.nanoleaf.lightpanel.id.description = Vom Controller vergebene ID eines Paneels
 
 # channel types