use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ZonePlayerHandler method onValueReceived.
@Override
public void onValueReceived(String variable, String value, String service) {
if (getThing().getStatus() == ThingStatus.ONLINE) {
logger.trace("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() });
String oldValue = this.stateMap.get(variable);
if (shouldIgnoreVariableUpdate(variable, value, oldValue)) {
return;
}
this.stateMap.put(variable, value);
// pre-process some variables, eg XML processing
if (service.equals("AVTransport") && variable.equals("LastChange")) {
Map<String, String> parsedValues = SonosXMLParser.getAVTransportFromXML(value);
for (String parsedValue : parsedValues.keySet()) {
// to not break the notification mechanism
if (!parsedValue.equals("TransportState")) {
onValueReceived(parsedValue, parsedValues.get(parsedValue), "AVTransport");
}
// for a compatibility with the result of the action GetMediaInfo
if (parsedValue.equals("AVTransportURI")) {
onValueReceived("CurrentURI", parsedValues.get(parsedValue), service);
} else if (parsedValue.equals("AVTransportURIMetaData")) {
onValueReceived("CurrentURIMetaData", parsedValues.get(parsedValue), service);
}
}
updateMediaInformation();
if (parsedValues.get("TransportState") != null) {
onValueReceived("TransportState", parsedValues.get("TransportState"), "AVTransport");
}
}
if (service.equals("RenderingControl") && variable.equals("LastChange")) {
Map<String, String> parsedValues = SonosXMLParser.getRenderingControlFromXML(value);
for (String parsedValue : parsedValues.keySet()) {
onValueReceived(parsedValue, parsedValues.get(parsedValue), "RenderingControl");
}
}
// update the appropriate channel
switch(variable) {
case "TransportState":
updateChannel(STATE);
updateChannel(CONTROL);
updateChannel(STOP);
dispatchOnAllGroupMembers(variable, value, service);
break;
case "CurrentPlayMode":
updateChannel(SHUFFLE);
updateChannel(REPEAT);
dispatchOnAllGroupMembers(variable, value, service);
break;
case "CurrentLEDState":
updateChannel(LED);
break;
case "ZoneName":
updateState(ZONENAME, (stateMap.get("ZoneName") != null) ? new StringType(stateMap.get("ZoneName")) : UnDefType.UNDEF);
break;
case "CurrentZoneName":
updateChannel(ZONENAME);
break;
case "ZoneGroupState":
updateChannel(COORDINATOR);
// Update coordinator after a change is made to the grouping of Sonos players
updateGroupCoordinator();
updateMediaInformation();
// Update state and control channels for the group members with the coordinator values
if (stateMap.get("TransportState") != null) {
dispatchOnAllGroupMembers("TransportState", stateMap.get("TransportState"), "AVTransport");
}
// Update shuffle and repeat channels for the group members with the coordinator values
if (stateMap.get("CurrentPlayMode") != null) {
dispatchOnAllGroupMembers("CurrentPlayMode", stateMap.get("CurrentPlayMode"), "AVTransport");
}
break;
case "LocalGroupUUID":
updateChannel(ZONEGROUPID);
break;
case "GroupCoordinatorIsLocal":
updateChannel(LOCALCOORDINATOR);
break;
case "VolumeMaster":
updateChannel(VOLUME);
break;
case "MuteMaster":
updateChannel(MUTE);
break;
case "LineInConnected":
case "TOSLinkConnected":
if (SonosBindingConstants.WITH_LINEIN_THING_TYPES_UIDS.contains(getThing().getThingTypeUID())) {
updateChannel(LINEIN);
}
break;
case "AlarmRunning":
updateChannel(ALARMRUNNING);
break;
case "RunningAlarmProperties":
updateChannel(ALARMPROPERTIES);
break;
case "CurrentURIFormatted":
updateChannel(CURRENTTRACK);
break;
case "CurrentTitle":
updateChannel(CURRENTTITLE);
break;
case "CurrentArtist":
updateChannel(CURRENTARTIST);
break;
case "CurrentAlbum":
updateChannel(CURRENTALBUM);
break;
case "CurrentURI":
updateChannel(CURRENTTRANSPORTURI);
break;
case "CurrentTrackURI":
updateChannel(CURRENTTRACKURI);
break;
case "CurrentAlbumArtURI":
updateChannel(CURRENTALBUMARTURL);
break;
case "CurrentSleepTimerGeneration":
if (value.equals("0")) {
updateState(SLEEPTIMER, new DecimalType(0));
}
break;
case "SleepTimerGeneration":
if (value.equals("0")) {
updateState(SLEEPTIMER, new DecimalType(0));
} else {
updateSleepTimerDuration();
}
break;
case "RemainingSleepTimerDuration":
updateState(SLEEPTIMER, (stateMap.get("RemainingSleepTimerDuration") != null) ? new DecimalType(sleepStrTimeToSeconds(stateMap.get("RemainingSleepTimerDuration"))) : UnDefType.UNDEF);
break;
case "CurrentTuneInStationId":
updateChannel(TUNEINSTATIONID);
break;
default:
break;
}
}
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_groupLabelWithValue.
@Test
public void getLabel_groupLabelWithValue() throws ItemNotFoundException {
String testLabel = "Label [%d]";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getState()).thenReturn(OnOffType.ON);
when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(5));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [5]", label);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithIntegerValue.
@Test
public void getLabel_labelWithIntegerValue() throws ItemNotFoundException {
String testLabel = "Label [%d]";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getState()).thenReturn(new DecimalType(20));
when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [20]", label);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithDecimalValue.
@Test
public void getLabel_labelWithDecimalValue() throws ItemNotFoundException {
String testLabel = "Label [%.3f]";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getState()).thenReturn(new DecimalType(10f / 3f));
when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(10f / 3f));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [3" + sep + "333]", label);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class BeaconBluetoothHandler method updateRSSI.
/**
* Updates the RSSI channel and the Thing status according to the new received rssi value
*/
protected void updateRSSI() {
if (device != null) {
Integer rssi = device.getRssi();
if (rssi != null && rssi != 0) {
updateState(BluetoothBindingConstants.CHANNEL_TYPE_RSSI, new DecimalType(rssi));
updateStatusBasedOnRssi(true);
} else {
updateState(BluetoothBindingConstants.CHANNEL_TYPE_RSSI, UnDefType.NULL);
updateStatusBasedOnRssi(false);
}
}
}
Aggregations