Search in sources :

Example 1 with StateVariableValue

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : StateVariableValue(org.teleal.cling.model.state.StateVariableValue) SonosCommandType(org.openhab.binding.sonos.SonosCommandType) IllegalClassException(org.apache.commons.lang.IllegalClassException) StringType(org.openhab.core.library.types.StringType) SonosCommandType(org.openhab.binding.sonos.SonosCommandType) OnOffType(org.openhab.core.library.types.OnOffType) UDAServiceType(org.teleal.cling.model.types.UDAServiceType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) SonosBindingProvider(org.openhab.binding.sonos.SonosBindingProvider) Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 2 with StateVariableValue

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;
    }
}
Also used : StateVariableValue(org.teleal.cling.model.state.StateVariableValue) SAXException(org.xml.sax.SAXException)

Example 3 with StateVariableValue

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;
    }
}
Also used : StateVariableValue(org.teleal.cling.model.state.StateVariableValue)

Example 4 with StateVariableValue

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;
    }
}
Also used : StateVariableValue(org.teleal.cling.model.state.StateVariableValue) SAXException(org.xml.sax.SAXException)

Example 5 with StateVariableValue

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;
    }
}
Also used : Action(org.teleal.cling.model.meta.Action) StateVariableValue(org.teleal.cling.model.state.StateVariableValue) StateVariable(org.teleal.cling.model.meta.StateVariable) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) StateVariableTypeDetails(org.teleal.cling.model.meta.StateVariableTypeDetails) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Aggregations

StateVariableValue (org.teleal.cling.model.state.StateVariableValue)9 SAXException (org.xml.sax.SAXException)4 StateVariable (org.teleal.cling.model.meta.StateVariable)3 StateVariableTypeDetails (org.teleal.cling.model.meta.StateVariableTypeDetails)3 HashMap (java.util.HashMap)1 IllegalClassException (org.apache.commons.lang.IllegalClassException)1 SonosBindingProvider (org.openhab.binding.sonos.SonosBindingProvider)1 SonosCommandType (org.openhab.binding.sonos.SonosCommandType)1 DecimalType (org.openhab.core.library.types.DecimalType)1 OnOffType (org.openhab.core.library.types.OnOffType)1 StringType (org.openhab.core.library.types.StringType)1 Command (org.openhab.core.types.Command)1 State (org.openhab.core.types.State)1 Type (org.openhab.core.types.Type)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1 UpnpService (org.teleal.cling.UpnpService)1 ActionCallback (org.teleal.cling.controlpoint.ActionCallback)1 ActionArgumentValue (org.teleal.cling.model.action.ActionArgumentValue)1 ActionException (org.teleal.cling.model.action.ActionException)1 ActionInvocation (org.teleal.cling.model.action.ActionInvocation)1