use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class VideoRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Video videoWidget = (Video) w;
String snippet = null;
String widgetId = itemUIRegistry.getWidgetId(w);
String sitemap = w.eResource().getURI().path();
if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("mjpeg")) {
// we handle mjpeg streams as an html image as browser can usually handle this
snippet = getSnippet("image");
snippet = StringUtils.replace(snippet, "%setrefresh%", "");
snippet = StringUtils.replace(snippet, "%refresh%", "");
} else {
snippet = getSnippet("video");
}
String url = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
String mediaType = "";
if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("hls")) {
// For HTTP Live Stream we don't proxy the URL and we set the appropriate media type
State state = itemUIRegistry.getState(w);
url = (state instanceof StringType) ? state.toString() : videoWidget.getUrl();
mediaType = "type=\"application/vnd.apple.mpegurl\"";
}
snippet = StringUtils.replace(snippet, "%url%", url);
snippet = StringUtils.replace(snippet, "%media_type%", mediaType);
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class ImageRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Image image = (Image) w;
String snippet = (image.getChildren().size() > 0) ? getSnippet("image_link") : getSnippet("image");
if (image.getRefresh() > 0) {
snippet = StringUtils.replace(snippet, "%refresh%", "id=\"%id%\" data-timeout=\"" + image.getRefresh() + "\" onload=\"startReloadImage('%url%', '%id%')\"");
} else {
snippet = StringUtils.replace(snippet, "%refresh%", "");
}
String widgetId = itemUIRegistry.getWidgetId(w);
snippet = StringUtils.replace(snippet, "%id%", widgetId);
String sitemap = null;
if (w.eResource() != null) {
sitemap = w.eResource().getURI().path();
}
boolean validUrl = false;
if (image.getUrl() != null && !image.getUrl().isEmpty()) {
try {
URI.create(image.getUrl());
validUrl = true;
} catch (IllegalArgumentException ex) {
}
}
String proxiedUrl = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
State state = itemUIRegistry.getState(w);
String url;
if (state instanceof RawType) {
url = state.toFullString();
} else if ((sitemap != null) && ((state instanceof StringType) || validUrl)) {
url = proxiedUrl + "&t=" + (new Date()).getTime();
} else {
url = "images/none.png";
}
snippet = StringUtils.replace(snippet, "%url%", url);
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class HueLightHandler method onLightStateChanged.
@Override
public void onLightStateChanged(@Nullable HueBridge bridge, FullLight fullLight) {
logger.trace("onLightStateChanged() was called");
if (!fullLight.getId().equals(lightId)) {
logger.trace("Received state change for another handler's light ({}). Will be ignored.", fullLight.getId());
return;
}
initializeProperties();
lastSentColorTemp = null;
lastSentBrightness = null;
// update status (ONLINE, OFFLINE)
if (fullLight.getState().isReachable()) {
updateStatus(ThingStatus.ONLINE);
} else {
// we assume OFFLINE without any error (NONE), as this is an
// expected state (when bulb powered off)
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/offline.light-not-reachable");
}
HSBType hsbType = LightStateConverter.toHSBType(fullLight.getState());
if (!fullLight.getState().isOn()) {
hsbType = new HSBType(hsbType.getHue(), hsbType.getSaturation(), new PercentType(0));
}
updateState(CHANNEL_COLOR, hsbType);
PercentType percentType = LightStateConverter.toColorTemperaturePercentType(fullLight.getState());
updateState(CHANNEL_COLORTEMPERATURE, percentType);
percentType = LightStateConverter.toBrightnessPercentType(fullLight.getState());
if (!fullLight.getState().isOn()) {
percentType = new PercentType(0);
}
updateState(CHANNEL_BRIGHTNESS, percentType);
if (fullLight.getState().isOn()) {
updateState(CHANNEL_SWITCH, OnOffType.ON);
} else {
updateState(CHANNEL_SWITCH, OnOffType.OFF);
}
StringType stringType = LightStateConverter.toAlertStringType(fullLight.getState());
if (!stringType.toString().equals("NULL")) {
updateState(CHANNEL_ALERT, stringType);
scheduleAlertStateRestore(stringType);
}
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class HueLightHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
HueBridgeHandler hueBridge = getHueBridgeHandler();
if (hueBridge == null) {
logger.warn("hue bridge handler not found. Cannot handle command without bridge.");
return;
}
FullLight light = getLight();
if (light == null) {
logger.debug("hue light not known on bridge. Cannot handle command.");
return;
}
StateUpdate lightState = null;
switch(channelUID.getId()) {
case CHANNEL_COLORTEMPERATURE:
if (command instanceof PercentType) {
lightState = LightStateConverter.toColorTemperatureLightState((PercentType) command);
} else if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
}
} else if (command instanceof IncreaseDecreaseType) {
lightState = convertColorTempChangeToStateUpdate((IncreaseDecreaseType) command, light);
}
break;
case CHANNEL_BRIGHTNESS:
if (command instanceof PercentType) {
lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
} else if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
}
} else if (command instanceof IncreaseDecreaseType) {
lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
}
break;
case CHANNEL_SWITCH:
logger.trace("CHANNEL_SWITCH handling command {}", command);
if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
}
}
break;
case CHANNEL_COLOR:
if (command instanceof HSBType) {
HSBType hsbCommand = (HSBType) command;
if (hsbCommand.getBrightness().intValue() == 0) {
lightState = LightStateConverter.toOnOffLightState(OnOffType.OFF);
} else {
lightState = LightStateConverter.toColorLightState(hsbCommand);
}
} else if (command instanceof PercentType) {
lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
} else if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
} else if (command instanceof IncreaseDecreaseType) {
lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
}
break;
case CHANNEL_ALERT:
if (command instanceof StringType) {
lightState = LightStateConverter.toAlertState((StringType) command);
if (lightState == null) {
// Unsupported StringType is passed. Log a warning
// message and return.
logger.warn("Unsupported String command: {}. Supported commands are: {}, {}, {} ", command, LightStateConverter.ALERT_MODE_NONE, LightStateConverter.ALERT_MODE_SELECT, LightStateConverter.ALERT_MODE_LONG_SELECT);
return;
} else {
scheduleAlertStateRestore(command);
}
}
break;
case CHANNEL_EFFECT:
if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffEffectState((OnOffType) command);
}
break;
}
if (lightState != null) {
hueBridge.updateLightState(light, lightState);
} else {
logger.warn("Command sent to an unknown channel id: {}", channelUID);
}
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class WemoCoffeeHandler method updateWemoState.
/**
* The {@link updateWemoState} polls the actual state of a WeMo CoffeeMaker.
*/
protected void updateWemoState() {
String action = "GetAttributes";
String actionService = "deviceevent";
String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\"";
String content = "<?xml version=\"1.0\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + "<u:" + action + " xmlns:u=\"urn:Belkin:service:" + actionService + ":1\">" + "</u:" + action + ">" + "</s:Body>" + "</s:Envelope>";
try {
String wemoURL = getWemoURL(actionService);
if (wemoURL != null) {
String wemoCallResponse = WemoHttpCall.executeCall(wemoURL, soapHeader, content);
if (wemoCallResponse != null) {
try {
String stringParser = StringUtils.substringBetween(wemoCallResponse, "<attributeList>", "</attributeList>");
// Due to Belkins bad response formatting, we need to run this twice.
stringParser = StringEscapeUtils.unescapeXml(stringParser);
stringParser = StringEscapeUtils.unescapeXml(stringParser);
logger.trace("CoffeeMaker response '{}' for device '{}' received", stringParser, getThing().getUID());
stringParser = "<data>" + stringParser + "</data>";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(stringParser));
Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName("attribute");
// iterate the attributes
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList deviceIndex = element.getElementsByTagName("name");
Element line = (Element) deviceIndex.item(0);
String attributeName = getCharacterDataFromElement(line);
logger.trace("attributeName: {}", attributeName);
NodeList deviceID = element.getElementsByTagName("value");
line = (Element) deviceID.item(0);
String attributeValue = getCharacterDataFromElement(line);
logger.trace("attributeValue: {}", attributeValue);
switch(attributeName) {
case "Mode":
State newMode = new StringType("Brewing");
switch(attributeValue) {
case "0":
updateState(CHANNEL_STATE, OnOffType.ON);
newMode = new StringType("Refill");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "1":
updateState(CHANNEL_STATE, OnOffType.OFF);
newMode = new StringType("PlaceCarafe");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "2":
updateState(CHANNEL_STATE, OnOffType.OFF);
newMode = new StringType("RefillWater");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "3":
updateState(CHANNEL_STATE, OnOffType.OFF);
newMode = new StringType("Ready");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "4":
updateState(CHANNEL_STATE, OnOffType.ON);
newMode = new StringType("Brewing");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "5":
updateState(CHANNEL_STATE, OnOffType.OFF);
newMode = new StringType("Brewed");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "6":
updateState(CHANNEL_STATE, OnOffType.OFF);
newMode = new StringType("CleaningBrewing");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "7":
updateState(CHANNEL_STATE, OnOffType.OFF);
newMode = new StringType("CleaningSoaking");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
case "8":
updateState(CHANNEL_STATE, OnOffType.OFF);
newMode = new StringType("BrewFailCarafeRemoved");
updateState(CHANNEL_COFFEEMODE, newMode);
break;
}
break;
case "ModeTime":
if (attributeValue != null) {
State newAttributeValue = new DecimalType(attributeValue);
updateState(CHANNEL_MODETIME, newAttributeValue);
}
break;
case "TimeRemaining":
if (attributeValue != null) {
State newAttributeValue = new DecimalType(attributeValue);
updateState(CHANNEL_TIMEREMAINING, newAttributeValue);
}
break;
case "WaterLevelReached":
if (attributeValue != null) {
State newAttributeValue = new DecimalType(attributeValue);
updateState(CHANNEL_WATERLEVELREACHED, newAttributeValue);
}
break;
case "CleanAdvise":
if (attributeValue != null) {
State newAttributeValue = attributeValue.equals("0") ? OnOffType.OFF : OnOffType.ON;
updateState(CHANNEL_CLEANADVISE, newAttributeValue);
}
break;
case "FilterAdvise":
if (attributeValue != null) {
State newAttributeValue = attributeValue.equals("0") ? OnOffType.OFF : OnOffType.ON;
updateState(CHANNEL_FILTERADVISE, newAttributeValue);
}
break;
case "Brewed":
if (attributeValue != null) {
State newAttributeValue = getDateTimeState(attributeValue);
if (newAttributeValue != null) {
updateState(CHANNEL_BREWED, newAttributeValue);
}
}
break;
case "LastCleaned":
if (attributeValue != null) {
State newAttributeValue = getDateTimeState(attributeValue);
if (newAttributeValue != null) {
updateState(CHANNEL_LASTCLEANED, newAttributeValue);
}
}
break;
}
}
} catch (Exception e) {
logger.error("Failed to parse attributeList for WeMo CoffeMaker '{}'", this.getThing().getUID(), e);
}
}
}
} catch (Exception e) {
logger.error("Failed to get attributes for device '{}'", getThing().getUID(), e);
}
}
Aggregations