]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hue] Removed internal vendor Map and minor additional improvements (#10137)
authorChristoph Weitkamp <github@christophweitkamp.de>
Sat, 13 Feb 2021 21:48:40 +0000 (22:48 +0100)
committerGitHub <noreply@github.com>
Sat, 13 Feb 2021 21:48:40 +0000 (13:48 -0800)
* Removed internal vendor Map and minor additional improvements
* Incorporated comments from review

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/console/HueCommandExtension.java
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueGroupHandler.java
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueLightHandler.java
bundles/org.openhab.binding.hue/src/main/resources/OH-INF/i18n/hue_de.properties
bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/handler/HueLightHandlerTest.java
bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/handler/HueLightState.java

index 3c695720ea36e51f3f6ef65970e118364d8926f4..ce5aef384cb494fa0959b92bc226caf0f58db4fe 100644 (file)
@@ -75,10 +75,10 @@ public class HueCommandExtension extends AbstractConsoleCommandExtension {
                 console.println("Bad thing id '" + args[0] + "'");
                 printUsage(console);
             } else if (thingHandler == null) {
-                console.println("No handler initialized for the thing id '" + args[0] + "'");
+                console.println("No handler initialized for the thingUID '" + args[0] + "'");
                 printUsage(console);
             } else if (bridgeHandler == null && groupHandler == null) {
-                console.println("'" + args[0] + "' is neither a hue bridge id nor a hue group thing id");
+                console.println("'" + args[0] + "' is neither a Hue bridgeUID nor a Hue groupThingUID");
                 printUsage(console);
             } else {
                 switch (args[1]) {
@@ -87,7 +87,7 @@ public class HueCommandExtension extends AbstractConsoleCommandExtension {
                             String userName = bridgeHandler.getUserName();
                             console.println("Your user name is " + (userName != null ? userName : "undefined"));
                         } else {
-                            console.println("'" + args[0] + "' is not a hue bridge id");
+                            console.println("'" + args[0] + "' is not a Hue bridgeUID");
                             printUsage(console);
                         }
                         break;
index a8e87730afe9b50958c9e97235a8d87cc6516e1a..27cdb5f0af72e3c1f7abf9e5d7704b918cf15c5d 100644 (file)
@@ -16,6 +16,7 @@ import static org.openhab.binding.hue.internal.HueBindingConstants.*;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ScheduledFuture;
@@ -60,6 +61,7 @@ import org.slf4j.LoggerFactory;
 @NonNullByDefault
 public class HueGroupHandler extends BaseThingHandler implements GroupStatusListener {
     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_GROUP);
+    public static final String PROPERTY_MEMBERS = "members";
 
     private final Logger logger = LoggerFactory.getLogger(HueGroupHandler.class);
     private final HueStateDescriptionOptionProvider stateDescriptionOptionProvider;
@@ -123,6 +125,14 @@ public class HueGroupHandler extends BaseThingHandler implements GroupStatusList
         }
     }
 
+    private synchronized void initializeProperties(@Nullable FullGroup fullGroup) {
+        if (fullGroup != null) {
+            Map<String, String> properties = editProperties();
+            properties.put(PROPERTY_MEMBERS, fullGroup.getLightIds().stream().collect(Collectors.joining(",")));
+            updateProperties(properties);
+        }
+    }
+
     @Override
     public void dispose() {
         logger.debug("Hue group handler disposes. Unregistering listener.");
@@ -379,6 +389,8 @@ public class HueGroupHandler extends BaseThingHandler implements GroupStatusList
 
         logger.trace("New state for group {}", groupId);
 
+        initializeProperties(group);
+
         lastSentColorTemp = null;
         lastSentBrightness = null;
 
index 336791740865f659c8eeef057d3a7be43961df40..fcd6d37f43035249843deefd232ce32e3e91b8cb 100644 (file)
@@ -81,15 +81,10 @@ public class HueLightHandler extends BaseThingHandler implements LightStatusList
             THING_TYPE_COLOR_TEMPERATURE_LIGHT, THING_TYPE_DIMMABLE_LIGHT, THING_TYPE_EXTENDED_COLOR_LIGHT,
             THING_TYPE_ON_OFF_LIGHT, THING_TYPE_ON_OFF_PLUG, THING_TYPE_DIMMABLE_PLUG);
 
-    private static final Map<String, List<String>> VENDOR_MODEL_MAP = Map.of( //
-            "Philips", List.of("LCT001", "LCT002", "LCT003", "LCT007", "LLC001", "LLC006", "LLC007", "LLC010", //
-                    "LLC011", "LLC012", "LLC013", "LLC020", "LST001", "LST002", "LWB004", "LWB006", "LWB007", //
-                    "LWL001"),
-            "OSRAM", List.of("Classic_A60_RGBW", "PAR16_50_TW", "Surface_Light_TW", "Plug_01"));
-
-    private static final String OSRAM_PAR16_50_TW_MODEL_ID = "PAR16_50_TW";
+    public static final String OSRAM_PAR16_50_TW_MODEL_ID = "PAR16_50_TW";
 
     private final Logger logger = LoggerFactory.getLogger(HueLightHandler.class);
+
     private final HueStateDescriptionOptionProvider stateDescriptionOptionProvider;
 
     private @NonNullByDefault({}) String lightId;
@@ -170,13 +165,8 @@ public class HueLightHandler extends BaseThingHandler implements LightStatusList
             String modelId = fullLight.getNormalizedModelID();
             if (modelId != null) {
                 properties.put(PROPERTY_MODEL_ID, modelId);
-                String vendor = getVendor(modelId);
-                if (vendor != null) {
-                    properties.put(PROPERTY_VENDOR, vendor);
-                }
-            } else {
-                properties.put(PROPERTY_VENDOR, fullLight.getManufacturerName());
             }
+            properties.put(PROPERTY_VENDOR, fullLight.getManufacturerName());
             properties.put(PRODUCT_NAME, fullLight.getProductName());
             String uniqueID = fullLight.getUniqueID();
             if (uniqueID != null) {
@@ -215,15 +205,6 @@ public class HueLightHandler extends BaseThingHandler implements LightStatusList
         }
     }
 
-    private @Nullable String getVendor(String modelId) {
-        for (String vendor : VENDOR_MODEL_MAP.keySet()) {
-            if (VENDOR_MODEL_MAP.get(vendor).contains(modelId)) {
-                return vendor;
-            }
-        }
-        return null;
-    }
-
     @Override
     public void dispose() {
         logger.debug("Hue light handler disposes. Unregistering listener.");
index b40602f2879051b5ec2e571933c1e9efb26b2fbf..378433e0837dfaba4efe626ed6feba9d5fd00bd7 100644 (file)
@@ -103,6 +103,8 @@ channel-type.hue.alert.state.option.SELECT = Einmaliges Blinken
 channel-type.hue.alert.state.option.LSELECT = Mehrfaches Blinken
 channel-type.hue.effect.label = Farbeffekt
 channel-type.hue.effect.description = Ermöglicht einen automatischen Farbwechsels.
+channel-type.hue.scene.label = Szene
+channel-type.hue.scene.description = Ermöglicht das Anwenden einer Szene für alle Lichter, die zur Gruppe gehören.
 
 channel-type.hue.last_updated.label = Letzte Aktualisierung
 channel-type.hue.last_updated.description = Zeit, zu der sich dieser Wert geändert hat.
index 2d62bbe8a5506087637821468c11a2650434572b..ea16da229cff906d136c3f4cbd1a80fbdeb7f32e 100644 (file)
@@ -17,7 +17,7 @@ import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 import static org.openhab.binding.hue.internal.HueBindingConstants.*;
 
-import java.util.Collections;
+import java.util.Map;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -62,8 +62,9 @@ public class HueLightHandlerTest {
     private static final int MAX_COLOR_TEMPERATURE = 500;
     private static final int COLOR_TEMPERATURE_RANGE = MAX_COLOR_TEMPERATURE - MIN_COLOR_TEMPERATURE;
 
-    private static final String OSRAM_MODEL_TYPE = "PAR16 50 TW";
-    private static final String OSRAM_MODEL_TYPE_ID = "PAR16_50_TW";
+    private static final String OSRAM = "OSRAM";
+    private static final String OSRAM_MODEL_TYPE = HueLightHandler.OSRAM_PAR16_50_TW_MODEL_ID;
+    private static final String OSRAM_MODEL_TYPE_ID = HueLightHandler.OSRAM_PAR16_50_TW_MODEL_ID;
 
     private Gson gson;
 
@@ -75,25 +76,26 @@ public class HueLightHandlerTest {
     @Test
     public void assertCommandForOsramPar1650ForColorTemperatureChannelOn() {
         String expectedReply = "{\"on\" : true, \"bri\" : 254}";
-        assertSendCommandForColorTempForPar16(OnOffType.ON, new HueLightState(OSRAM_MODEL_TYPE), expectedReply);
+        assertSendCommandForColorTempForPar16(OnOffType.ON, new HueLightState(OSRAM_MODEL_TYPE, OSRAM), expectedReply);
     }
 
     @Test
     public void assertCommandForOsramPar1650ForColorTemperatureChannelOff() {
         String expectedReply = "{\"on\" : false, \"transitiontime\" : 0}";
-        assertSendCommandForColorTempForPar16(OnOffType.OFF, new HueLightState(OSRAM_MODEL_TYPE), expectedReply);
+        assertSendCommandForColorTempForPar16(OnOffType.OFF, new HueLightState(OSRAM_MODEL_TYPE, OSRAM), expectedReply);
     }
 
     @Test
     public void assertCommandForOsramPar1650ForBrightnessChannelOn() {
         String expectedReply = "{\"on\" : true, \"bri\" : 254}";
-        assertSendCommandForBrightnessForPar16(OnOffType.ON, new HueLightState(OSRAM_MODEL_TYPE), expectedReply);
+        assertSendCommandForBrightnessForPar16(OnOffType.ON, new HueLightState(OSRAM_MODEL_TYPE, OSRAM), expectedReply);
     }
 
     @Test
     public void assertCommandForOsramPar1650ForBrightnessChannelOff() {
         String expectedReply = "{\"on\" : false, \"transitiontime\" : 0}";
-        assertSendCommandForBrightnessForPar16(OnOffType.OFF, new HueLightState(OSRAM_MODEL_TYPE), expectedReply);
+        assertSendCommandForBrightnessForPar16(OnOffType.OFF, new HueLightState(OSRAM_MODEL_TYPE, OSRAM),
+                expectedReply);
     }
 
     @Test
@@ -341,12 +343,12 @@ public class HueLightHandlerTest {
 
     private void assertSendCommandForColorTempForPar16(Command command, HueLightState currentState,
             String expectedReply) {
-        assertSendCommand(CHANNEL_COLORTEMPERATURE, command, currentState, expectedReply, OSRAM_MODEL_TYPE_ID, "OSRAM");
+        assertSendCommand(CHANNEL_COLORTEMPERATURE, command, currentState, expectedReply, OSRAM_MODEL_TYPE_ID, OSRAM);
     }
 
     private void assertSendCommandForBrightnessForPar16(Command command, HueLightState currentState,
             String expectedReply) {
-        assertSendCommand(CHANNEL_BRIGHTNESS, command, currentState, expectedReply, OSRAM_MODEL_TYPE_ID, "OSRAM");
+        assertSendCommand(CHANNEL_BRIGHTNESS, command, currentState, expectedReply, OSRAM_MODEL_TYPE_ID, OSRAM);
     }
 
     private void assertSendCommandForColor(Command command, HueLightState currentState, String expectedReply) {
@@ -390,7 +392,7 @@ public class HueLightHandlerTest {
         when(mockBridge.getStatus()).thenReturn(ThingStatus.ONLINE);
 
         Thing mockThing = mock(Thing.class);
-        when(mockThing.getConfiguration()).thenReturn(new Configuration(Collections.singletonMap(LIGHT_ID, "1")));
+        when(mockThing.getConfiguration()).thenReturn(new Configuration(Map.of(LIGHT_ID, "1")));
 
         HueClient mockClient = mock(HueClient.class);
         when(mockClient.getLightById(any())).thenReturn(light);
index f7dc42f03e5ad9919b3dc0964ed9843c69ab7764..1d99ee7fd1ca58dfed5e7c22afacbbb0a30b796d 100644 (file)
@@ -33,12 +33,14 @@ public class HueLightState {
     String effect = "none";
     String colorMode = "hs";
     String model = "LCT001";
+    String vendor = "Philips";
 
     public HueLightState() {
     }
 
-    public HueLightState(String model) {
+    public HueLightState(String model, String vendor) {
         this.model = model;
+        this.vendor = vendor;
     }
 
     public HueLightState bri(int brightness) {
@@ -105,6 +107,7 @@ public class HueLightState {
                 "      \"type\": \"Extended color light\"," + //
                 "      \"name\": \"Hue Light 1\"," + //
                 "      \"modelid\": \"" + model + "\"," + //
+                "      \"manufacturername\": \"" + vendor + "\"," + //
                 "      \"swversion\": \"65003148\"," + //
                 "      \"uniqueid\": \"00:17:88:01:00:e1:88:29-0b\"," + //
                 "      \"pointsymbol\": {" + //