Search in sources :

Example 6 with InvalidValueException

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

the class SonosZonePlayer method setCurrentURI.

public boolean setCurrentURI(String URI, String URIMetaData) {
    if (URI != null && URIMetaData != null && isConfigured()) {
        Service service = device.findService(new UDAServiceId("AVTransport"));
        Action action = service.getAction("SetAVTransportURI");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            invocation.setInput("InstanceID", "0");
            invocation.setInput("CurrentURI", URI);
            invocation.setInput("CurrentURIMetaData", URIMetaData);
        } 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 7 with InvalidValueException

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

the class SonosZonePlayer method snoozeAlarm.

public boolean snoozeAlarm(int minutes) {
    if (isAlarmRunning() && isConfigured()) {
        Service service = device.findService(new UDAServiceId("AVTransport"));
        Action action = service.getAction("SnoozeAlarm");
        ActionInvocation invocation = new ActionInvocation(action);
        Period snoozePeriod = Period.minutes(minutes);
        PeriodFormatter pFormatter = new PeriodFormatterBuilder().printZeroAlways().appendHours().appendSeparator(":").appendMinutes().appendSeparator(":").appendSeconds().toFormatter();
        try {
            invocation.setInput("Duration", pFormatter.print(snoozePeriod));
        } 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 {
        logger.warn("There is no alarm running on {} ", this);
        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) Period(org.joda.time.Period) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Example 8 with InvalidValueException

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

the class SonosZonePlayer method setLed.

public boolean setLed(String string) {
    if (string != null && isConfigured()) {
        Service service = device.findService(new UDAServiceId("DeviceProperties"));
        Action action = service.getAction("SetLEDState");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            if (string.equals("ON") || string.equals("OPEN") || string.equals("UP")) {
                invocation.setInput("DesiredLEDState", "On");
            } else if (string.equals("OFF") || string.equals("CLOSED") || string.equals("DOWN")) {
                invocation.setInput("DesiredLEDState", "Off");
            } 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 9 with InvalidValueException

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

the class SonosZonePlayer method getEntries.

protected List<SonosEntry> getEntries(String type, String filter) {
    List<SonosEntry> resultList = null;
    if (isConfigured()) {
        long startAt = 0;
        Service service = device.findService(new UDAServiceId("ContentDirectory"));
        Action action = service.getAction("Browse");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            invocation.setInput("ObjectID", type);
            invocation.setInput("BrowseFlag", "BrowseDirectChildren");
            invocation.setInput("Filter", filter);
            invocation.setInput("StartingIndex", new UnsignedIntegerFourBytes(startAt));
            invocation.setInput("RequestedCount", new UnsignedIntegerFourBytes(200));
            invocation.setInput("SortCriteria", "");
        } catch (InvalidValueException ex) {
            logger.error("Action Invalid Value Exception {}", ex.getMessage());
        } catch (NumberFormatException ex) {
            logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
        }
        // Execute this action synchronously
        new ActionCallback.Default(invocation, upnpService.getControlPoint()).run();
        Long totalMatches = ((UnsignedIntegerFourBytes) invocation.getOutput("TotalMatches").getValue()).getValue();
        Long initialNumberReturned = ((UnsignedIntegerFourBytes) invocation.getOutput("NumberReturned").getValue()).getValue();
        String initialResult = (String) invocation.getOutput("Result").getValue();
        try {
            resultList = SonosXMLParser.getEntriesFromString(initialResult);
        } catch (SAXException e) {
            logger.error("Could not parse Entries from String {}", initialResult);
        }
        startAt = startAt + initialNumberReturned;
        while (startAt < totalMatches) {
            invocation = new ActionInvocation(action);
            try {
                invocation.setInput("ObjectID", type);
                invocation.setInput("BrowseFlag", "BrowseDirectChildren");
                invocation.setInput("Filter", filter);
                invocation.setInput("StartingIndex", new UnsignedIntegerFourBytes(startAt));
                invocation.setInput("RequestedCount", new UnsignedIntegerFourBytes(200));
                invocation.setInput("SortCriteria", "");
            } catch (InvalidValueException ex) {
                logger.error("Action Invalid Value Exception {}", ex.getMessage());
            } catch (NumberFormatException ex) {
                logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
            }
            // Execute this action synchronously
            new ActionCallback.Default(invocation, upnpService.getControlPoint()).run();
            String result = (String) invocation.getOutput("Result").getValue();
            int numberReturned = (Integer) invocation.getOutput("NumberReturned").getValue();
            try {
                resultList.addAll(SonosXMLParser.getEntriesFromString(result));
            } catch (SAXException e) {
                logger.error("Could not parse Entries from String {}", result);
            }
            startAt = startAt + numberReturned;
        }
    }
    return resultList;
}
Also used : Action(org.teleal.cling.model.meta.Action) ActionCallback(org.teleal.cling.controlpoint.ActionCallback) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) SAXException(org.xml.sax.SAXException) InvalidValueException(org.teleal.cling.model.types.InvalidValueException) UnsignedIntegerFourBytes(org.teleal.cling.model.types.UnsignedIntegerFourBytes) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Example 10 with InvalidValueException

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

the class SonosZonePlayer method updateMediaInfo.

public boolean updateMediaInfo() {
    if (isConfigured()) {
        Service service = device.findService(new UDAServiceId("AVTransport"));
        Action action = service.getAction("GetMediaInfo");
        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;
    }
    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)

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