Search in sources :

Example 11 with ThingUID

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();
}
Also used : FirmwareUID(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Thing(org.eclipse.smarthome.core.thing.Thing) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with ThingUID

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);
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Before(org.junit.Before)

Example 13 with ThingUID

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;
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 14 with ThingUID

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;
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 15 with ThingUID

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));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Aggregations

ThingUID (org.eclipse.smarthome.core.thing.ThingUID)99 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)29 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)27 Thing (org.eclipse.smarthome.core.thing.Thing)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)21 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)14 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)9 JsonObject (com.google.gson.JsonObject)8 JsonParser (com.google.gson.JsonParser)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Locale (java.util.Locale)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 Consumes (javax.ws.rs.Consumes)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Collection (java.util.Collection)4 GET (javax.ws.rs.GET)4 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)4