use of org.teleal.cling.model.state.StateVariableValue in project openhab1-addons by openhab.
the class SonosBinding method processVariableMap.
@SuppressWarnings("rawtypes")
public void processVariableMap(RemoteDevice device, Map<String, StateVariableValue> values) {
if (device != null && values != null) {
SonosZonePlayer associatedPlayer = sonosZonePlayerCache.getByDevice(device);
if (associatedPlayer == null) {
logger.debug("There is no Sonos Player defined matching the device {}", device);
return;
}
for (String stateVariable : values.keySet()) {
// find all the CommandTypes that are defined for each
// StateVariable
List<SonosCommandType> supportedCommands = SonosCommandType.getCommandByVariable(stateVariable);
StateVariableValue status = values.get(stateVariable);
for (SonosCommandType sonosCommandType : supportedCommands) {
// create a new State based on the type of Sonos Command and
// the status value in the map
Type newState = null;
try {
newState = createStateForType((Class<? extends State>) sonosCommandType.getTypeClass(), status.getValue().toString());
} catch (BindingConfigParseException e) {
logger.error("Error parsing a value {} to a state variable of type {}", status.toString(), sonosCommandType.getTypeClass().toString());
}
for (SonosBindingProvider provider : providers) {
List<String> qualifiedItems = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getId(), sonosCommandType.getSonosCommand());
List<String> qualifiedItemsByUDN = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getUdn().getIdentifierString(), sonosCommandType.getSonosCommand());
for (String item : qualifiedItemsByUDN) {
if (!qualifiedItems.contains(item)) {
qualifiedItems.add(item);
}
}
for (String anItem : qualifiedItems) {
// get the openHAB commands attached to each Item at
// this given Provider
List<Command> commands = provider.getCommands(anItem, sonosCommandType.getSonosCommand());
if (provider.getAcceptedDataTypes(anItem).contains(sonosCommandType.getTypeClass())) {
if (newState != null) {
eventPublisher.postUpdate(anItem, (State) newState);
} else {
throw new IllegalClassException("Cannot process update for the command of type " + sonosCommandType.toString());
}
} else {
logger.warn("Cannot cast {} to an accepted state type for item {}", sonosCommandType.getTypeClass().toString(), anItem);
}
}
}
}
}
}
}
use of org.teleal.cling.model.state.StateVariableValue in project openhab1-addons by openhab.
the class SonosZonePlayer method getEnqueuedTransportURIMetaData.
public SonosMetaData getEnqueuedTransportURIMetaData() {
if (stateMap != null && isConfigured()) {
StateVariableValue value = stateMap.get("EnqueuedTransportURIMetaData");
SonosMetaData currentTrack = null;
if (value != null) {
try {
if (((String) value.getValue()).length() != 0) {
currentTrack = SonosXMLParser.getMetaDataFromXML((String) value.getValue());
}
} catch (SAXException e) {
logger.error("Could not parse MetaData from String {}", value.getValue().toString());
}
return currentTrack;
} else {
return null;
}
} else {
return null;
}
}
use of org.teleal.cling.model.state.StateVariableValue in project openhab1-addons by openhab.
the class SonosZonePlayer method playPlayList.
public boolean playPlayList(String playlist) {
if (isConfigured()) {
List<SonosEntry> playlists = getPlayLists();
SonosEntry theEntry = null;
// search for the appropriate play list based on its name (title)
for (SonosEntry somePlaylist : playlists) {
if (somePlaylist.getTitle().equals(playlist)) {
theEntry = somePlaylist;
break;
}
}
// set the URI of the group coordinator
if (theEntry != null) {
SonosZonePlayer coordinator = sonosBinding.getCoordinatorForZonePlayer(this);
// coordinator.setCurrentURI(theEntry);
coordinator.addURIToQueue(theEntry);
if (stateMap != null && isConfigured()) {
StateVariableValue firstTrackNumberEnqueued = stateMap.get("FirstTrackNumberEnqueued");
if (firstTrackNumberEnqueued != null) {
coordinator.seek("TRACK_NR", firstTrackNumberEnqueued.getValue().toString());
}
}
coordinator.play();
return true;
} else {
return false;
}
} else {
return false;
}
}
use of org.teleal.cling.model.state.StateVariableValue in project openhab1-addons by openhab.
the class SonosZonePlayer method getTrackMetadata.
public SonosMetaData getTrackMetadata() {
if (stateMap != null && isConfigured()) {
StateVariableValue value = stateMap.get("CurrentTrackMetaData");
SonosMetaData currentTrack = null;
if (value != null) {
try {
if (((String) value.getValue()).length() != 0) {
currentTrack = SonosXMLParser.getMetaDataFromXML((String) value.getValue());
}
} catch (SAXException e) {
logger.error("Could not parse MetaData from String {}", value.getValue().toString());
}
return currentTrack;
} else {
return null;
}
} else {
return null;
}
}
use of org.teleal.cling.model.state.StateVariableValue in project openhab1-addons by openhab.
the class SonosZonePlayer method updateRunningAlarmProperties.
public boolean updateRunningAlarmProperties() {
if (stateMap != null && isConfigured()) {
Service service = device.findService(new UDAServiceId("AVTransport"));
Action action = service.getAction("GetRunningAlarmProperties");
ActionInvocation invocation = new ActionInvocation(action);
executeActionInvocation(invocation);
// for this property we would like to "compile" a more friendly variable.
// this newly created "variable" is also store in the stateMap
StateVariableValue alarmID = stateMap.get("AlarmID");
StateVariableValue groupID = stateMap.get("GroupID");
StateVariableValue loggedStartTime = stateMap.get("LoggedStartTime");
String newStringValue = null;
if (alarmID != null && loggedStartTime != null) {
newStringValue = alarmID.getValue() + " - " + loggedStartTime.getValue();
} else {
newStringValue = "No running alarm";
}
StateVariable newVariable = new StateVariable("RunningAlarmProperties", new StateVariableTypeDetails(Datatype.Builtin.STRING.getDatatype()));
StateVariableValue newValue = new StateVariableValue(newVariable, newStringValue);
processStateVariableValue(newVariable.getName(), newValue);
return true;
} else {
return false;
}
}
Aggregations