Search in sources :

Example 1 with InvalidValueException

use of org.teleal.cling.model.types.InvalidValueException 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 2 with InvalidValueException

use of org.teleal.cling.model.types.InvalidValueException 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 3 with InvalidValueException

use of org.teleal.cling.model.types.InvalidValueException in project openhab1-addons by openhab.

the class SonosZonePlayer method removeAllTracksFromQueue.

/**
     * Clear all scheduled music from the current queue.
     * 
     * @return true if no error occurred.
     */
public boolean removeAllTracksFromQueue() {
    if (!isConfigured) {
        return false;
    }
    Service service = device.findService(new UDAServiceId("AVTransport"));
    Action action = service.getAction("RemoveAllTracksFromQueue");
    ActionInvocation invocation = new ActionInvocation(action);
    try {
        invocation.setInput("InstanceID", "0");
    } 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;
}
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 InvalidValueException

use of org.teleal.cling.model.types.InvalidValueException in project openhab1-addons by openhab.

the class SonosZonePlayer method setMute.

public boolean setMute(String string) {
    if (string != null && isConfigured()) {
        Service service = device.findService(new UDAServiceId("RenderingControl"));
        Action action = service.getAction("SetMute");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            invocation.setInput("Channel", "Master");
            if (string.equals("ON") || string.equals("OPEN") || string.equals("UP")) {
                invocation.setInput("DesiredMute", "True");
            } else if (string.equals("OFF") || string.equals("CLOSED") || string.equals("DOWN")) {
                invocation.setInput("DesiredMute", "False");
            } else {
                return false;
            }
        } 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 5 with InvalidValueException

use of org.teleal.cling.model.types.InvalidValueException in project openhab1-addons by openhab.

the class SonosZonePlayer method updateAlarm.

public boolean updateAlarm(SonosAlarm alarm) {
    if (alarm != null && isConfigured()) {
        Service service = device.findService(new UDAServiceId("AlarmClock"));
        Action action = service.getAction("ListAlarms");
        ActionInvocation invocation = new ActionInvocation(action);
        DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
        PeriodFormatter pFormatter = new PeriodFormatterBuilder().printZeroAlways().appendHours().appendSeparator(":").appendMinutes().appendSeparator(":").appendSeconds().toFormatter();
        try {
            invocation.setInput("ID", Integer.toString(alarm.getID()));
            invocation.setInput("StartLocalTime", formatter.print(alarm.getStartTime()));
            invocation.setInput("Duration", pFormatter.print(alarm.getDuration()));
            invocation.setInput("Recurrence", alarm.getRecurrence());
            invocation.setInput("RoomUUID", alarm.getRoomUUID());
            invocation.setInput("ProgramURI", alarm.getProgramURI());
            invocation.setInput("ProgramMetaData", alarm.getProgramMetaData());
            invocation.setInput("PlayMode", alarm.getPlayMode());
            invocation.setInput("Volume", Integer.toString(alarm.getVolume()));
            if (alarm.getIncludeLinkedZones()) {
                invocation.setInput("IncludeLinkedZones", "1");
            } else {
                invocation.setInput("IncludeLinkedZones", "0");
            }
            if (alarm.getEnabled()) {
                invocation.setInput("Enabled", "1");
            } else {
                invocation.setInput("Enabled", "0");
            }
        } 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) PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Aggregations

UpnpService (org.teleal.cling.UpnpService)12 ActionInvocation (org.teleal.cling.model.action.ActionInvocation)12 Action (org.teleal.cling.model.meta.Action)12 Service (org.teleal.cling.model.meta.Service)12 InvalidValueException (org.teleal.cling.model.types.InvalidValueException)12 UDAServiceId (org.teleal.cling.model.types.UDAServiceId)12 PeriodFormatter (org.joda.time.format.PeriodFormatter)2 PeriodFormatterBuilder (org.joda.time.format.PeriodFormatterBuilder)2 UnsignedIntegerFourBytes (org.teleal.cling.model.types.UnsignedIntegerFourBytes)2 Period (org.joda.time.Period)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 ActionCallback (org.teleal.cling.controlpoint.ActionCallback)1 SAXException (org.xml.sax.SAXException)1