use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ThingResource method updateConfiguration.
/**
* Updates Thing configuration.
*
* @param thingUID
* @param configurationParameters
* @return Response with the updated Thing or error information
* @throws IOException
*/
@PUT
@RolesAllowed({ Role.ADMIN })
@Path("/{thingUID}/config")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Updates thing's configuration.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = Thing.class), @ApiResponse(code = 400, message = "Configuration of the thing is not valid."), @ApiResponse(code = 404, message = "Thing not found"), @ApiResponse(code = 409, message = "Thing could not be updated as it is not editable.") })
public Response updateConfiguration(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID, @ApiParam(value = "configuration parameters") Map<String, Object> configurationParameters) throws IOException {
final Locale locale = LocaleUtil.getLocale(language);
ThingUID thingUIDObject = new ThingUID(thingUID);
// ask whether the Thing exists at all, 404 otherwise
Thing thing = thingRegistry.get(thingUIDObject);
if (null == thing) {
logger.info("Received HTTP PUT request for update configuration at '{}' for the unknown thing '{}'.", uriInfo.getPath(), thingUID);
return getThingNotFoundResponse(thingUID);
}
// ask whether the Thing exists as a managed thing, so it can get
// updated, 409 otherwise
Thing managed = managedThingProvider.get(thingUIDObject);
if (null == managed) {
logger.info("Received HTTP PUT request for update configuration at '{}' for an unmanaged thing '{}'.", uriInfo.getPath(), thingUID);
return getThingResponse(Status.CONFLICT, thing, locale, "Cannot update Thing " + thingUID + " as it is not editable.");
}
// only move on if Thing is known to be managed, so it can get updated
try {
// note that we create a Configuration instance here in order to
// have normalized types
thingRegistry.updateConfiguration(thingUIDObject, new Configuration(normalizeConfiguration(configurationParameters, thing.getThingTypeUID(), thing.getUID())).getProperties());
} catch (ConfigValidationException ex) {
logger.debug("Config description validation exception occurred for thingUID {} - Messages: {}", thingUID, ex.getValidationMessages());
return Response.status(Status.BAD_REQUEST).entity(ex.getValidationMessages(locale)).build();
} catch (Exception ex) {
logger.error("Exception during HTTP PUT request for update config at '{}'", uriInfo.getPath(), ex);
return JSONResponse.createResponse(Status.INTERNAL_SERVER_ERROR, null, ex.getMessage());
}
return getThingResponse(Status.OK, thing, locale, null);
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ThingResource method getStatus.
@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Path("/{thingUID}/status")
@ApiOperation(value = "Gets thing's status.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class), @ApiResponse(code = 404, message = "Thing not found.") })
public Response getStatus(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID) throws IOException {
ThingUID thingUIDObject = new ThingUID(thingUID);
// Check if the Thing exists, 404 if not
Thing thing = thingRegistry.get(thingUIDObject);
if (null == thing) {
logger.info("Received HTTP GET request for thing config status at '{}' for the unknown thing '{}'.", uriInfo.getPath(), thingUID);
return getThingNotFoundResponse(thingUID);
}
ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, LocaleUtil.getLocale(language));
return Response.ok(null, MediaType.TEXT_PLAIN).entity(thingStatusInfo).build();
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method offlineIfZeroPort.
/**
* Verify OFFLINE Thing status when the PORT is zero.
*/
@Test
public void offlineIfZeroPort() {
Configuration config = createConfiguration(DEFAULT_CONFIG_PROPERTY_IP, DEFAULT_CONFIG_PROPERTY_PIN, "0", DEFAULT_CONFIG_PROPERTY_REFRESH);
Thing radioThingWithZeroPort = initializeRadioThing(config);
testRadioThingConsideringConfiguration(radioThingWithZeroPort);
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method powerChannelUpdated.
/**
* Verify the power channel is updated.
*/
@Test
public void powerChannelUpdated() {
Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
testRadioThingConsideringConfiguration(radioThing);
ChannelUID powerChannelUID = powerChannel.getUID();
initializeItem(powerChannelUID, DEFAULT_TEST_ITEM_NAME, acceptedItemTypes.get(FSInternetRadioBindingConstants.CHANNEL_POWER));
radioHandler.handleCommand(powerChannelUID, OnOffType.ON);
waitForAssert(() -> {
assertTrue("We should be able to turn on the radio", radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER));
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(powerChannelUID, OnOffType.OFF);
waitForAssert(() -> {
assertTrue("We should be able to turn off the radio", radioServiceDummy.containsRequestParameter(0, CHANNEL_POWER));
radioServiceDummy.clearRequestParameters();
});
/*
* Setting the needed boolean variable to true, so we can be sure
* that an invalid value will be returned in the XML response
*/
radioHandler.handleCommand(powerChannelUID, OnOffType.ON);
waitForAssert(() -> {
assertTrue("We should be able to turn on the radio", radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER));
radioServiceDummy.clearRequestParameters();
});
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method playInfoTextChannelUpdated.
/**
* Verify the playInfoText channel is updated.
*/
@Test
public void playInfoTextChannelUpdated() {
String playInfoTextChannelID = FSInternetRadioBindingConstants.CHANNEL_PLAY_INFO_TEXT;
String acceptedItemType = acceptedItemTypes.get(playInfoTextChannelID);
createChannel(DEFAULT_THING_UID, playInfoTextChannelID, acceptedItemType);
Thing radioThing = initializeRadioThingWithMockedHandler(DEFAULT_COMPLETE_CONFIGURATION);
testRadioThingConsideringConfiguration(radioThing);
turnTheRadioOn(radioThing);
ChannelUID playInfoTextChannelUID = getChannelUID(radioThing, FSInternetRadioBindingConstants.CHANNEL_PLAY_INFO_TEXT);
initializeItem(playInfoTextChannelUID, DEFAULT_TEST_ITEM_NAME, acceptedItemType);
waitForAssert(() -> {
verifyOnlineStatusIsSet();
});
}
Aggregations