[hue] Removed internal vendor Map and minor additional improvements (#10137)

* Removed internal vendor Map and minor additional improvements
* Incorporated comments from review

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2021-02-13 22:48:40 +01:00 committed by GitHub
parent 5b20a7df1c
commit b4ca793963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 36 deletions

View File

@ -75,10 +75,10 @@ public class HueCommandExtension extends AbstractConsoleCommandExtension {
console.println("Bad thing id '" + args[0] + "'"); console.println("Bad thing id '" + args[0] + "'");
printUsage(console); printUsage(console);
} else if (thingHandler == null) { } 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); printUsage(console);
} else if (bridgeHandler == null && groupHandler == null) { } 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); printUsage(console);
} else { } else {
switch (args[1]) { switch (args[1]) {
@ -87,7 +87,7 @@ public class HueCommandExtension extends AbstractConsoleCommandExtension {
String userName = bridgeHandler.getUserName(); String userName = bridgeHandler.getUserName();
console.println("Your user name is " + (userName != null ? userName : "undefined")); console.println("Your user name is " + (userName != null ? userName : "undefined"));
} else { } else {
console.println("'" + args[0] + "' is not a hue bridge id"); console.println("'" + args[0] + "' is not a Hue bridgeUID");
printUsage(console); printUsage(console);
} }
break; break;

View File

@ -16,6 +16,7 @@ import static org.openhab.binding.hue.internal.HueBindingConstants.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
@ -60,6 +61,7 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault @NonNullByDefault
public class HueGroupHandler extends BaseThingHandler implements GroupStatusListener { public class HueGroupHandler extends BaseThingHandler implements GroupStatusListener {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_GROUP); 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 Logger logger = LoggerFactory.getLogger(HueGroupHandler.class);
private final HueStateDescriptionOptionProvider stateDescriptionOptionProvider; 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 @Override
public void dispose() { public void dispose() {
logger.debug("Hue group handler disposes. Unregistering listener."); 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); logger.trace("New state for group {}", groupId);
initializeProperties(group);
lastSentColorTemp = null; lastSentColorTemp = null;
lastSentBrightness = null; lastSentBrightness = null;

View 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_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); 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( // public static final String OSRAM_PAR16_50_TW_MODEL_ID = "PAR16_50_TW";
"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";
private final Logger logger = LoggerFactory.getLogger(HueLightHandler.class); private final Logger logger = LoggerFactory.getLogger(HueLightHandler.class);
private final HueStateDescriptionOptionProvider stateDescriptionOptionProvider; private final HueStateDescriptionOptionProvider stateDescriptionOptionProvider;
private @NonNullByDefault({}) String lightId; private @NonNullByDefault({}) String lightId;
@ -170,13 +165,8 @@ public class HueLightHandler extends BaseThingHandler implements LightStatusList
String modelId = fullLight.getNormalizedModelID(); String modelId = fullLight.getNormalizedModelID();
if (modelId != null) { if (modelId != null) {
properties.put(PROPERTY_MODEL_ID, modelId); 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()); properties.put(PRODUCT_NAME, fullLight.getProductName());
String uniqueID = fullLight.getUniqueID(); String uniqueID = fullLight.getUniqueID();
if (uniqueID != null) { 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 @Override
public void dispose() { public void dispose() {
logger.debug("Hue light handler disposes. Unregistering listener."); logger.debug("Hue light handler disposes. Unregistering listener.");

View 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.alert.state.option.LSELECT = Mehrfaches Blinken
channel-type.hue.effect.label = Farbeffekt channel-type.hue.effect.label = Farbeffekt
channel-type.hue.effect.description = Ermöglicht einen automatischen Farbwechsels. 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.label = Letzte Aktualisierung
channel-type.hue.last_updated.description = Zeit, zu der sich dieser Wert geändert hat. channel-type.hue.last_updated.description = Zeit, zu der sich dieser Wert geändert hat.

View File

@ -17,7 +17,7 @@ import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.openhab.binding.hue.internal.HueBindingConstants.*; 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.BeforeEach;
import org.junit.jupiter.api.Test; 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 MAX_COLOR_TEMPERATURE = 500;
private static final int COLOR_TEMPERATURE_RANGE = MAX_COLOR_TEMPERATURE - MIN_COLOR_TEMPERATURE; 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 = "OSRAM";
private static final String OSRAM_MODEL_TYPE_ID = "PAR16_50_TW"; 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; private Gson gson;
@ -75,25 +76,26 @@ public class HueLightHandlerTest {
@Test @Test
public void assertCommandForOsramPar1650ForColorTemperatureChannelOn() { public void assertCommandForOsramPar1650ForColorTemperatureChannelOn() {
String expectedReply = "{\"on\" : true, \"bri\" : 254}"; 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 @Test
public void assertCommandForOsramPar1650ForColorTemperatureChannelOff() { public void assertCommandForOsramPar1650ForColorTemperatureChannelOff() {
String expectedReply = "{\"on\" : false, \"transitiontime\" : 0}"; 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 @Test
public void assertCommandForOsramPar1650ForBrightnessChannelOn() { public void assertCommandForOsramPar1650ForBrightnessChannelOn() {
String expectedReply = "{\"on\" : true, \"bri\" : 254}"; 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 @Test
public void assertCommandForOsramPar1650ForBrightnessChannelOff() { public void assertCommandForOsramPar1650ForBrightnessChannelOff() {
String expectedReply = "{\"on\" : false, \"transitiontime\" : 0}"; 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 @Test
@ -341,12 +343,12 @@ public class HueLightHandlerTest {
private void assertSendCommandForColorTempForPar16(Command command, HueLightState currentState, private void assertSendCommandForColorTempForPar16(Command command, HueLightState currentState,
String expectedReply) { 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, private void assertSendCommandForBrightnessForPar16(Command command, HueLightState currentState,
String expectedReply) { 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) { private void assertSendCommandForColor(Command command, HueLightState currentState, String expectedReply) {
@ -390,7 +392,7 @@ public class HueLightHandlerTest {
when(mockBridge.getStatus()).thenReturn(ThingStatus.ONLINE); when(mockBridge.getStatus()).thenReturn(ThingStatus.ONLINE);
Thing mockThing = mock(Thing.class); 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); HueClient mockClient = mock(HueClient.class);
when(mockClient.getLightById(any())).thenReturn(light); when(mockClient.getLightById(any())).thenReturn(light);

View File

@ -33,12 +33,14 @@ public class HueLightState {
String effect = "none"; String effect = "none";
String colorMode = "hs"; String colorMode = "hs";
String model = "LCT001"; String model = "LCT001";
String vendor = "Philips";
public HueLightState() { public HueLightState() {
} }
public HueLightState(String model) { public HueLightState(String model, String vendor) {
this.model = model; this.model = model;
this.vendor = vendor;
} }
public HueLightState bri(int brightness) { public HueLightState bri(int brightness) {
@ -105,6 +107,7 @@ public class HueLightState {
" \"type\": \"Extended color light\"," + // " \"type\": \"Extended color light\"," + //
" \"name\": \"Hue Light 1\"," + // " \"name\": \"Hue Light 1\"," + //
" \"modelid\": \"" + model + "\"," + // " \"modelid\": \"" + model + "\"," + //
" \"manufacturername\": \"" + vendor + "\"," + //
" \"swversion\": \"65003148\"," + // " \"swversion\": \"65003148\"," + //
" \"uniqueid\": \"00:17:88:01:00:e1:88:29-0b\"," + // " \"uniqueid\": \"00:17:88:01:00:e1:88:29-0b\"," + //
" \"pointsymbol\": {" + // " \"pointsymbol\": {" + //