Search in sources :

Example 1 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class ZonePlayerHandler method playFavorite.

/**
 * This will attempt to match the station string with a entry in the
 * favorites list, this supports both single entries and playlists
 *
 * @param favorite to match
 * @return true if a match was found and played.
 */
public void playFavorite(Command command) {
    if (command instanceof StringType) {
        String favorite = command.toString();
        List<SonosEntry> favorites = getFavorites();
        SonosEntry theEntry = null;
        // search for the appropriate favorite based on its name (title)
        for (SonosEntry entry : favorites) {
            if (entry.getTitle().equals(favorite)) {
                theEntry = entry;
                break;
            }
        }
        // set the URI of the group coordinator
        if (theEntry != null) {
            try {
                ZonePlayerHandler coordinator = getCoordinatorHandler();
                /**
                 * If this is a playlist we need to treat it as such
                 */
                if (theEntry.getResourceMetaData() != null && theEntry.getResourceMetaData().getUpnpClass().startsWith("object.container")) {
                    coordinator.removeAllTracksFromQueue();
                    coordinator.addURIToQueue(theEntry);
                    coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", "");
                    String firstTrackNumberEnqueued = stateMap.get("FirstTrackNumberEnqueued");
                    if (firstTrackNumberEnqueued != null) {
                        coordinator.seek("TRACK_NR", firstTrackNumberEnqueued);
                    }
                } else {
                    coordinator.setCurrentURI(theEntry);
                }
                coordinator.play();
            } catch (IllegalStateException e) {
                logger.debug("Cannot paly favorite ({})", e.getMessage());
            }
        } else {
            logger.debug("Favorite '{}' not found", favorite);
        }
    }
}
Also used : SonosEntry(org.eclipse.smarthome.binding.sonos.internal.SonosEntry) StringType(org.eclipse.smarthome.core.library.types.StringType)

Example 2 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class ZonePlayerHandler method handleNotificationSound.

/**
 * Handle the execution of the notification sound by sequentially executing the required steps.
 *
 * @param notificationURL - the notification url in the format of //host/folder/filename.mp3
 * @param coordinator - {@link ZonePlayerHandler} coordinator for the SONOS device(s)
 */
private void handleNotificationSound(Command notificationURL, ZonePlayerHandler coordinator) {
    String originalVolume = (isAdHocGroup() || isStandalonePlayer()) ? getVolume() : coordinator.getVolume();
    coordinator.stop();
    coordinator.waitForNotTransportState(STATE_PLAYING);
    applyNotificationSoundVolume();
    long notificationPosition = coordinator.getQueueSize() + 1;
    coordinator.addURIToQueue(notificationURL.toString(), "", notificationPosition, false);
    coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", "");
    coordinator.setPositionTrack(notificationPosition);
    coordinator.play();
    coordinator.waitForFinishedNotification();
    if (originalVolume != null) {
        setVolumeForGroup(DecimalType.valueOf(originalVolume));
    }
    coordinator.removeRangeOfTracksFromQueue(new StringType(Long.toString(notificationPosition) + ",1"));
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType)

Example 3 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class ZonePlayerHandler method playRadio.

public void playRadio(Command command) {
    if (command instanceof StringType) {
        String station = command.toString();
        List<SonosEntry> stations = getFavoriteRadios();
        SonosEntry theEntry = null;
        // search for the appropriate radio based on its name (title)
        for (SonosEntry someStation : stations) {
            if (someStation.getTitle().equals(station)) {
                theEntry = someStation;
                break;
            }
        }
        // set the URI of the group coordinator
        if (theEntry != null) {
            try {
                ZonePlayerHandler coordinator = getCoordinatorHandler();
                coordinator.setCurrentURI(theEntry);
                coordinator.play();
            } catch (IllegalStateException e) {
                logger.debug("Cannot play radio ({})", e.getMessage());
            }
        } else {
            logger.debug("Radio station '{}' not found", station);
        }
    }
}
Also used : SonosEntry(org.eclipse.smarthome.binding.sonos.internal.SonosEntry) StringType(org.eclipse.smarthome.core.library.types.StringType)

Example 4 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class ZonePlayerHandler method onValueReceived.

@Override
public void onValueReceived(String variable, String value, String service) {
    if (getThing().getStatus() == ThingStatus.ONLINE) {
        logger.trace("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() });
        String oldValue = this.stateMap.get(variable);
        if (shouldIgnoreVariableUpdate(variable, value, oldValue)) {
            return;
        }
        this.stateMap.put(variable, value);
        // pre-process some variables, eg XML processing
        if (service.equals("AVTransport") && variable.equals("LastChange")) {
            Map<String, String> parsedValues = SonosXMLParser.getAVTransportFromXML(value);
            for (String parsedValue : parsedValues.keySet()) {
                // to not break the notification mechanism
                if (!parsedValue.equals("TransportState")) {
                    onValueReceived(parsedValue, parsedValues.get(parsedValue), "AVTransport");
                }
                // for a compatibility with the result of the action GetMediaInfo
                if (parsedValue.equals("AVTransportURI")) {
                    onValueReceived("CurrentURI", parsedValues.get(parsedValue), service);
                } else if (parsedValue.equals("AVTransportURIMetaData")) {
                    onValueReceived("CurrentURIMetaData", parsedValues.get(parsedValue), service);
                }
            }
            updateMediaInformation();
            if (parsedValues.get("TransportState") != null) {
                onValueReceived("TransportState", parsedValues.get("TransportState"), "AVTransport");
            }
        }
        if (service.equals("RenderingControl") && variable.equals("LastChange")) {
            Map<String, String> parsedValues = SonosXMLParser.getRenderingControlFromXML(value);
            for (String parsedValue : parsedValues.keySet()) {
                onValueReceived(parsedValue, parsedValues.get(parsedValue), "RenderingControl");
            }
        }
        // update the appropriate channel
        switch(variable) {
            case "TransportState":
                updateChannel(STATE);
                updateChannel(CONTROL);
                updateChannel(STOP);
                dispatchOnAllGroupMembers(variable, value, service);
                break;
            case "CurrentPlayMode":
                updateChannel(SHUFFLE);
                updateChannel(REPEAT);
                dispatchOnAllGroupMembers(variable, value, service);
                break;
            case "CurrentLEDState":
                updateChannel(LED);
                break;
            case "ZoneName":
                updateState(ZONENAME, (stateMap.get("ZoneName") != null) ? new StringType(stateMap.get("ZoneName")) : UnDefType.UNDEF);
                break;
            case "CurrentZoneName":
                updateChannel(ZONENAME);
                break;
            case "ZoneGroupState":
                updateChannel(COORDINATOR);
                // Update coordinator after a change is made to the grouping of Sonos players
                updateGroupCoordinator();
                updateMediaInformation();
                // Update state and control channels for the group members with the coordinator values
                if (stateMap.get("TransportState") != null) {
                    dispatchOnAllGroupMembers("TransportState", stateMap.get("TransportState"), "AVTransport");
                }
                // Update shuffle and repeat channels for the group members with the coordinator values
                if (stateMap.get("CurrentPlayMode") != null) {
                    dispatchOnAllGroupMembers("CurrentPlayMode", stateMap.get("CurrentPlayMode"), "AVTransport");
                }
                break;
            case "LocalGroupUUID":
                updateChannel(ZONEGROUPID);
                break;
            case "GroupCoordinatorIsLocal":
                updateChannel(LOCALCOORDINATOR);
                break;
            case "VolumeMaster":
                updateChannel(VOLUME);
                break;
            case "MuteMaster":
                updateChannel(MUTE);
                break;
            case "LineInConnected":
            case "TOSLinkConnected":
                if (SonosBindingConstants.WITH_LINEIN_THING_TYPES_UIDS.contains(getThing().getThingTypeUID())) {
                    updateChannel(LINEIN);
                }
                break;
            case "AlarmRunning":
                updateChannel(ALARMRUNNING);
                break;
            case "RunningAlarmProperties":
                updateChannel(ALARMPROPERTIES);
                break;
            case "CurrentURIFormatted":
                updateChannel(CURRENTTRACK);
                break;
            case "CurrentTitle":
                updateChannel(CURRENTTITLE);
                break;
            case "CurrentArtist":
                updateChannel(CURRENTARTIST);
                break;
            case "CurrentAlbum":
                updateChannel(CURRENTALBUM);
                break;
            case "CurrentURI":
                updateChannel(CURRENTTRANSPORTURI);
                break;
            case "CurrentTrackURI":
                updateChannel(CURRENTTRACKURI);
                break;
            case "CurrentAlbumArtURI":
                updateChannel(CURRENTALBUMARTURL);
                break;
            case "CurrentSleepTimerGeneration":
                if (value.equals("0")) {
                    updateState(SLEEPTIMER, new DecimalType(0));
                }
                break;
            case "SleepTimerGeneration":
                if (value.equals("0")) {
                    updateState(SLEEPTIMER, new DecimalType(0));
                } else {
                    updateSleepTimerDuration();
                }
                break;
            case "RemainingSleepTimerDuration":
                updateState(SLEEPTIMER, (stateMap.get("RemainingSleepTimerDuration") != null) ? new DecimalType(sleepStrTimeToSeconds(stateMap.get("RemainingSleepTimerDuration"))) : UnDefType.UNDEF);
                break;
            case "CurrentTuneInStationId":
                updateChannel(TUNEINSTATIONID);
                break;
            default:
                break;
        }
    }
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType)

Example 5 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class ZonePlayerHandler method removeMember.

public void removeMember(Command command) {
    if (command != null && command instanceof StringType) {
        try {
            ZonePlayerHandler oldmemberHandler = getHandlerByName(command.toString());
            oldmemberHandler.becomeStandAlonePlayer();
            SonosEntry entry = new SonosEntry("", "", "", "", "", "", "", QUEUE_URI + oldmemberHandler.getUDN() + "#0");
            oldmemberHandler.setCurrentURI(entry);
        } catch (IllegalStateException e) {
            logger.debug("Cannot remove group member ({})", e.getMessage());
        }
    }
}
Also used : SonosEntry(org.eclipse.smarthome.binding.sonos.internal.SonosEntry) StringType(org.eclipse.smarthome.core.library.types.StringType)

Aggregations

StringType (org.eclipse.smarthome.core.library.types.StringType)43 State (org.eclipse.smarthome.core.types.State)13 Test (org.junit.Test)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)9 PercentType (org.eclipse.smarthome.core.library.types.PercentType)8 StateDescription (org.eclipse.smarthome.core.types.StateDescription)6 SonosEntry (org.eclipse.smarthome.binding.sonos.internal.SonosEntry)5 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)5 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)5 Date (java.util.Date)3 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)3 RefreshType (org.eclipse.smarthome.core.types.RefreshType)3 ArrayList (java.util.ArrayList)2 SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)2 DeviceStateUpdateImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)2 Event (org.eclipse.smarthome.core.events.Event)2 Item (org.eclipse.smarthome.core.items.Item)2 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)2 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)2