Search in sources :

Example 1 with Service

use of org.teleal.cling.model.meta.Service in project openhab1-addons by openhab.

the class SonosZonePlayer method getCurrentAlarmList.

public List<SonosAlarm> getCurrentAlarmList() {
    List<SonosAlarm> sonosAlarms = null;
    if (isConfigured()) {
        Service service = device.findService(new UDAServiceId("AlarmClock"));
        Action action = service.getAction("ListAlarms");
        ActionInvocation invocation = new ActionInvocation(action);
        executeActionInvocation(invocation);
        try {
            sonosAlarms = SonosXMLParser.getAlarmsFromStringResult(invocation.getOutput("CurrentAlarmList").toString());
        } catch (SAXException e) {
            logger.error("Could not parse Alarms from String {}", invocation.getOutput("CurrentAlarmList").toString());
        }
    }
    return sonosAlarms;
}
Also used : Action(org.teleal.cling.model.meta.Action) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) UDAServiceId(org.teleal.cling.model.types.UDAServiceId) SAXException(org.xml.sax.SAXException)

Example 2 with Service

use of org.teleal.cling.model.meta.Service in project openhab1-addons by openhab.

the class SonosZonePlayer method seek.

protected boolean seek(String unit, String target) {
    if (isConfigured() && unit != null && target != null) {
        Service service = device.findService(new UDAServiceId("AVTransport"));
        Action action = service.getAction("Seek");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            invocation.setInput("InstanceID", "0");
            invocation.setInput("Unit", unit);
            invocation.setInput("Target", target);
        } catch (InvalidValueException ex) {
            logger.error("Action Invalid Value Exception {}", ex.getMessage());
        } catch (NumberFormatException ex) {
            logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
        }
        executeActionInvocation(invocation);
        return true;
    }
    return false;
}
Also used : InvalidValueException(org.teleal.cling.model.types.InvalidValueException) Action(org.teleal.cling.model.meta.Action) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Example 3 with Service

use of org.teleal.cling.model.meta.Service in project openhab1-addons by openhab.

the class SonosZonePlayer method setVolume.

public boolean setVolume(String value) {
    if (value != null && isConfigured()) {
        Service service = device.findService(new UDAServiceId("RenderingControl"));
        Action action = service.getAction("SetVolume");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            String newValue = value;
            if (value.equals("INCREASE")) {
                int i = Integer.valueOf(this.getVolume());
                newValue = String.valueOf(Math.min(100, i + 1));
            } else if (value.equals("DECREASE")) {
                int i = Integer.valueOf(this.getVolume());
                newValue = String.valueOf(Math.max(0, i - 1));
            } else if (value.equals("ON")) {
                newValue = "100";
            } else if (value.equals("OFF")) {
                newValue = "0";
            } else {
                newValue = value;
            }
            invocation.setInput("Channel", "Master");
            invocation.setInput("DesiredVolume", newValue);
        } catch (InvalidValueException ex) {
            logger.error("Action Invalid Value Exception {}", ex.getMessage());
        } catch (NumberFormatException ex) {
            logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
        }
        executeActionInvocation(invocation);
        return true;
    } else {
        return false;
    }
}
Also used : InvalidValueException(org.teleal.cling.model.types.InvalidValueException) Action(org.teleal.cling.model.meta.Action) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Example 4 with Service

use of org.teleal.cling.model.meta.Service 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)

Example 5 with Service

use of org.teleal.cling.model.meta.Service in project openhab1-addons by openhab.

the class SonosZonePlayer method updateTime.

public boolean updateTime() {
    if (isConfigured()) {
        Service service = device.findService(new UDAServiceId("AlarmClock"));
        Action action = service.getAction("GetTimeNow");
        ActionInvocation invocation = new ActionInvocation(action);
        executeActionInvocation(invocation);
        return true;
    } else {
        return false;
    }
}
Also used : Action(org.teleal.cling.model.meta.Action) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Aggregations

UpnpService (org.teleal.cling.UpnpService)26 Service (org.teleal.cling.model.meta.Service)26 UDAServiceId (org.teleal.cling.model.types.UDAServiceId)26 ActionInvocation (org.teleal.cling.model.action.ActionInvocation)25 Action (org.teleal.cling.model.meta.Action)25 InvalidValueException (org.teleal.cling.model.types.InvalidValueException)12 PeriodFormatter (org.joda.time.format.PeriodFormatter)2 PeriodFormatterBuilder (org.joda.time.format.PeriodFormatterBuilder)2 UnsignedIntegerFourBytes (org.teleal.cling.model.types.UnsignedIntegerFourBytes)2 SAXException (org.xml.sax.SAXException)2 ArrayList (java.util.ArrayList)1 Period (org.joda.time.Period)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 SonosCommandType (org.openhab.binding.sonos.SonosCommandType)1 ActionCallback (org.teleal.cling.controlpoint.ActionCallback)1 StateVariable (org.teleal.cling.model.meta.StateVariable)1 StateVariableTypeDetails (org.teleal.cling.model.meta.StateVariableTypeDetails)1 StateVariableValue (org.teleal.cling.model.state.StateVariableValue)1