use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class TradfriDiscoveryServiceTest method validDiscoveryResultColorLightCWS.
@Test
public void validDiscoveryResultColorLightCWS() {
String json = "{\"9001\":\"TRADFRI bulb E27 CWS opal 600lm\",\"9002\":1505151864,\"9020\":1505433527,\"9003\":65550,\"9019\":1,\"9054\":0,\"5750\":2,\"3\":{\"0\":\"IKEA of Sweden\",\"1\":\"TRADFRI bulb E27 CWS opal 600lm\",\"2\":\"\",\"3\":\"1.3.002\",\"6\":1},\"3311\":[{\"5850\":1,\"5708\":0,\"5851\":254,\"5707\":0,\"5709\":33137,\"5710\":27211,\"5711\":0,\"5706\":\"efd275\",\"9003\":0}]}";
JsonObject data = new JsonParser().parse(json).getAsJsonObject();
discovery.onUpdate("65550", data);
assertNotNull(discoveryResult);
assertThat(discoveryResult.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(discoveryResult.getThingUID(), is(new ThingUID("tradfri:0210:1:65550")));
assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_COLOR_LIGHT));
assertThat(discoveryResult.getBridgeUID(), is(GATEWAY_THING_UID));
assertThat(discoveryResult.getProperties().get(CONFIG_ID), is(65550));
assertThat(discoveryResult.getRepresentationProperty(), is(CONFIG_ID));
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class TradfriDiscoveryServiceTest method validDiscoveryResultWhiteLightWS.
@Test
public void validDiscoveryResultWhiteLightWS() {
String json = "{\"9001\":\"TRADFRI bulb E27 WS opal 980lm\",\"9002\":1492955148,\"9020\":1507200447,\"9003\":65537,\"3311\":[{\"5710\":26909,\"5850\":1,\"5851\":203,\"5707\":0,\"5708\":0,\"5709\":30140,\"5711\":370,\"5706\":\"f1e0b5\",\"9003\":0}],\"9054\":0,\"5750\":2,\"9019\":1,\"3\":{\"0\":\"IKEA of Sweden\",\"1\":\"TRADFRI bulb E27 WS opal 980lm\",\"2\":\"\",\"3\":\"1.2.217\",\"6\":1}}";
JsonObject data = new JsonParser().parse(json).getAsJsonObject();
discovery.onUpdate("65537", data);
assertNotNull(discoveryResult);
assertThat(discoveryResult.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(discoveryResult.getThingUID(), is(new ThingUID("tradfri:0220:1:65537")));
assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_COLOR_TEMP_LIGHT));
assertThat(discoveryResult.getBridgeUID(), is(GATEWAY_THING_UID));
assertThat(discoveryResult.getProperties().get(CONFIG_ID), is(65537));
assertThat(discoveryResult.getRepresentationProperty(), is(CONFIG_ID));
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class TradfriDiscoveryParticipant method createResult.
@Override
public DiscoveryResult createResult(ServiceInfo service) {
ThingUID thingUID = getThingUID(service);
if (thingUID != null) {
if (service.getHostAddresses() != null && service.getHostAddresses().length > 0 && !service.getHostAddresses()[0].isEmpty()) {
logger.debug("Discovered Tradfri gateway: {}", service);
Map<String, Object> properties = new HashMap<>(4);
properties.put(PROPERTY_VENDOR, "IKEA of Sweden");
properties.put(GATEWAY_CONFIG_HOST, service.getHostAddresses()[0]);
properties.put(GATEWAY_CONFIG_PORT, service.getPort());
properties.put(PROPERTY_SERIAL_NUMBER, service.getName());
String fwVersion = service.getPropertyString("version");
if (fwVersion != null) {
properties.put(PROPERTY_FIRMWARE_VERSION, fwVersion);
}
return DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel("TRÅDFRI Gateway").withRepresentationProperty(GATEWAY_CONFIG_HOST).build();
} else {
logger.warn("Discovered Tradfri gateway doesn't have an IP address: {}", service);
}
}
return null;
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class TradfriDiscoveryService method onUpdate.
@Override
public void onUpdate(String instanceId, JsonObject data) {
ThingUID bridge = handler.getThing().getUID();
try {
if (data.has(INSTANCE_ID)) {
int id = data.get(INSTANCE_ID).getAsInt();
String type = data.get(TYPE).getAsString();
JsonObject deviceInfo = data.get(DEVICE).getAsJsonObject();
String model = deviceInfo.get(DEVICE_MODEL).getAsString();
ThingUID thingId = null;
if (TYPE_LIGHT.equals(type) && data.has(LIGHT)) {
JsonObject state = data.get(LIGHT).getAsJsonArray().get(0).getAsJsonObject();
// Color temperature light:
// We do not always receive a COLOR attribute, even the light supports it - but the gateway does not
// seem to have this information, if the bulb is unreachable. We therefore also check against
// concrete model names.
// Color light:
// As the protocol does not distinguishes between color and full-color lights,
// we check if the "CWS" identifier is given in the model name
ThingTypeUID thingType = null;
if (model != null && model.contains(COLOR_MODELS_IDENTIFIER)) {
thingType = THING_TYPE_COLOR_LIGHT;
}
if (//
thingType == null && (state.has(COLOR) || (model != null && Arrays.asList(COLOR_TEMP_MODELS).contains(model)))) {
thingType = THING_TYPE_COLOR_TEMP_LIGHT;
}
if (thingType == null) {
thingType = THING_TYPE_DIMMABLE_LIGHT;
}
thingId = new ThingUID(thingType, bridge, Integer.toString(id));
} else if (TYPE_SWITCH.equals(type) && data.has(SWITCH)) {
// Remote control and wireless dimmer
// As protocol does not distinguishes between remote control and wireless dimmer,
// we check for the whole model name
ThingTypeUID thingType = (model != null && REMOTE_CONTROLLER_MODEL.equals(model)) ? THING_TYPE_REMOTE_CONTROL : THING_TYPE_DIMMER;
thingId = new ThingUID(thingType, bridge, Integer.toString(id));
} else if (TYPE_SENSOR.equals(type) && data.has(SENSOR)) {
// Motion sensor
thingId = new ThingUID(THING_TYPE_MOTION_SENSOR, bridge, Integer.toString(id));
}
if (thingId == null) {
// we didn't identify any device, so let's quit
return;
}
String label = data.get(NAME).getAsString();
Map<String, Object> properties = new HashMap<>(1);
properties.put("id", id);
properties.put(PROPERTY_MODEL_ID, model);
if (deviceInfo.get(DEVICE_VENDOR) != null) {
properties.put(PROPERTY_VENDOR, deviceInfo.get(DEVICE_VENDOR).getAsString());
}
if (deviceInfo.get(DEVICE_FIRMWARE) != null) {
properties.put(PROPERTY_FIRMWARE_VERSION, deviceInfo.get(DEVICE_FIRMWARE).getAsString());
}
logger.debug("Adding device {} to inbox", thingId);
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingId).withBridge(bridge).withLabel(label).withProperties(properties).withRepresentationProperty("id").build();
thingDiscovered(discoveryResult);
}
} catch (JsonSyntaxException e) {
logger.debug("JSON error during discovery: {}", e.getMessage());
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class WeatherUndergroundDiscoveryService method createResults.
public void createResults(PointType location) {
ThingUID localWeatherThing = new ThingUID(THING_TYPE_WEATHER, LOCAL);
Map<String, Object> properties = new HashMap<>(3);
properties.put(LOCATION, String.format("%s,%s", location.getLatitude(), location.getLongitude()));
thingDiscovered(DiscoveryResultBuilder.create(localWeatherThing).withLabel("Local Weather").withProperties(properties).build());
}
Aggregations