use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ThingResource method updateFirmware.
@PUT
@Path("/{thingUID}/firmware/{firmwareVersion}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update thing firmware.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Firmware update preconditions not satisfied."), @ApiResponse(code = 404, message = "Thing not found.") })
public Response updateFirmware(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID, @PathParam("firmwareVersion") @ApiParam(value = "version") String firmwareVersion) throws IOException {
Thing thing = thingRegistry.get(new ThingUID(thingUID));
if (thing == null) {
return getThingNotFoundResponse(thingUID);
}
FirmwareUID firmwareUID = new FirmwareUID(thing.getThingTypeUID(), firmwareVersion);
try {
firmwareUpdateService.updateFirmware(thing.getUID(), firmwareUID, LocaleUtil.getLocale(language));
} catch (IllegalArgumentException | NullPointerException | IllegalStateException ex) {
return JSONResponse.createResponse(Status.BAD_REQUEST, null, "Firmware update preconditions not satisfied.");
}
return Response.status(Status.OK).build();
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class EnrichedThingDTOMapperTest method setup.
@Before
public void setup() {
initMocks(this);
when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID(THING_TYPE_UID));
when(thing.getUID()).thenReturn(new ThingUID(UID));
when(thing.getLabel()).thenReturn(THING_LABEL);
when(thing.getChannels()).thenReturn(mockChannels());
when(thing.getConfiguration()).thenReturn(configuration);
when(thing.getProperties()).thenReturn(properties);
when(thing.getLocation()).thenReturn(LOCATION);
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ZonePlayerDiscoveryParticipant method getThingUID.
@Override
public ThingUID getThingUID(RemoteDevice device) {
if (device.getDetails().getManufacturerDetails().getManufacturer() != null) {
if (device.getDetails().getManufacturerDetails().getManufacturer().toUpperCase().contains("SONOS")) {
String modelName = getModelName(device);
if (modelName.equals("ZP80")) {
modelName = "CONNECT";
} else if (modelName.equals("ZP100")) {
modelName = "CONNECTAMP";
}
ThingTypeUID thingUID = new ThingTypeUID(SonosBindingConstants.BINDING_ID, modelName);
// In case a new "unknown" Sonos player is discovered a generic ThingTypeUID will be used
if (!SonosBindingConstants.SUPPORTED_KNOWN_THING_TYPES_UIDS.contains(thingUID)) {
thingUID = SonosBindingConstants.ZONEPLAYER_THING_TYPE_UID;
}
logger.debug("Discovered a Sonos '{}' thing with UDN '{}'", thingUID, device.getIdentity().getUdn().getIdentifierString());
return new ThingUID(thingUID, device.getIdentity().getUdn().getIdentifierString());
}
}
return null;
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ZonePlayerDiscoveryParticipant method createResult.
@Override
public DiscoveryResult createResult(RemoteDevice device) {
ThingUID uid = getThingUID(device);
if (uid != null) {
String roomName = getSonosRoomName(device);
if (roomName != null) {
Map<String, Object> properties = new HashMap<>(3);
String label = "Sonos device";
try {
label = device.getDetails().getModelDetails().getModelName();
} catch (Exception e) {
// ignore and use default label
}
label += " (" + roomName + ")";
properties.put(ZonePlayerConfiguration.UDN, device.getIdentity().getUdn().getIdentifierString());
properties.put(SonosBindingConstants.IDENTIFICATION, roomName);
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label).withRepresentationProperty(ZonePlayerConfiguration.UDN).build();
logger.debug("Created a DiscoveryResult for device '{}' with UDN '{}'", device.getDetails().getFriendlyName(), device.getIdentity().getUdn().getIdentifierString());
return result;
}
}
return null;
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class TradfriDiscoveryServiceTest method validDiscoveryResultMotionSensor.
@Test
public void validDiscoveryResultMotionSensor() {
String json = "{\"9001\":\"TRADFRI motion sensor\",\"9002\":1492955083,\"9020\":1507120083,\"9003\":65538,\"9054\":0,\"5750\":4,\"9019\":1,\"3\":{\"0\":\"IKEA of Sweden\",\"1\":\"TRADFRI motion sensor\",\"2\":\"\",\"3\":\"1.2.214\",\"6\":3,\"9\":60},\"3300\":[{\"9003\":0}]}";
JsonObject data = new JsonParser().parse(json).getAsJsonObject();
discovery.onUpdate("65538", data);
assertNotNull(discoveryResult);
assertThat(discoveryResult.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(discoveryResult.getThingUID(), is(new ThingUID("tradfri:0107:1:65538")));
assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_MOTION_SENSOR));
assertThat(discoveryResult.getBridgeUID(), is(GATEWAY_THING_UID));
assertThat(discoveryResult.getProperties().get(CONFIG_ID), is(65538));
assertThat(discoveryResult.getRepresentationProperty(), is(CONFIG_ID));
}
Aggregations