Search in sources :

Example 41 with PercentType

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

the class ZonePlayerHandler method updateChannel.

protected void updateChannel(String channelId) {
    if (!isLinked(channelId)) {
        return;
    }
    String url;
    State newState = UnDefType.UNDEF;
    switch(channelId) {
        case STATE:
            if (stateMap.get("TransportState") != null) {
                newState = new StringType(stateMap.get("TransportState"));
            }
            break;
        case CONTROL:
            if (stateMap.get("TransportState") != null) {
                if (stateMap.get("TransportState").equals(STATE_PLAYING)) {
                    newState = PlayPauseType.PLAY;
                } else if (stateMap.get("TransportState").equals(STATE_STOPPED)) {
                    newState = PlayPauseType.PAUSE;
                } else if (stateMap.get("TransportState").equals(STATE_PAUSED_PLAYBACK)) {
                    newState = PlayPauseType.PAUSE;
                }
            }
            break;
        case STOP:
            if (stateMap.get("TransportState") != null) {
                if (stateMap.get("TransportState").equals(STATE_STOPPED)) {
                    newState = OnOffType.ON;
                } else {
                    newState = OnOffType.OFF;
                }
            }
            break;
        case SHUFFLE:
            if (stateMap.get("CurrentPlayMode") != null) {
                newState = isShuffleActive() ? OnOffType.ON : OnOffType.OFF;
            }
            break;
        case REPEAT:
            if (stateMap.get("CurrentPlayMode") != null) {
                newState = new StringType(getRepeatMode());
            }
            break;
        case LED:
            if (stateMap.get("CurrentLEDState") != null) {
                newState = stateMap.get("CurrentLEDState").equals("On") ? OnOffType.ON : OnOffType.OFF;
            }
            break;
        case ZONENAME:
            if (stateMap.get("CurrentZoneName") != null) {
                newState = new StringType(stateMap.get("CurrentZoneName"));
            }
            break;
        case ZONEGROUPID:
            if (stateMap.get("LocalGroupUUID") != null) {
                newState = new StringType(stateMap.get("LocalGroupUUID"));
            }
            break;
        case COORDINATOR:
            newState = new StringType(getCoordinator());
            break;
        case LOCALCOORDINATOR:
            if (stateMap.get("GroupCoordinatorIsLocal") != null) {
                newState = stateMap.get("GroupCoordinatorIsLocal").equals("true") ? OnOffType.ON : OnOffType.OFF;
            }
            break;
        case VOLUME:
            if (stateMap.get("VolumeMaster") != null) {
                newState = new PercentType(stateMap.get("VolumeMaster"));
            }
            break;
        case MUTE:
            if (stateMap.get("MuteMaster") != null) {
                newState = stateMap.get("MuteMaster").equals("1") ? OnOffType.ON : OnOffType.OFF;
            }
            break;
        case LINEIN:
            if (stateMap.get("LineInConnected") != null) {
                newState = stateMap.get("LineInConnected").equals("true") ? OnOffType.ON : OnOffType.OFF;
            } else if (stateMap.get("TOSLinkConnected") != null) {
                newState = stateMap.get("TOSLinkConnected").equals("true") ? OnOffType.ON : OnOffType.OFF;
            }
            break;
        case ALARMRUNNING:
            if (stateMap.get("AlarmRunning") != null) {
                newState = stateMap.get("AlarmRunning").equals("1") ? OnOffType.ON : OnOffType.OFF;
            }
            break;
        case ALARMPROPERTIES:
            if (stateMap.get("RunningAlarmProperties") != null) {
                newState = new StringType(stateMap.get("RunningAlarmProperties"));
            }
            break;
        case CURRENTTRACK:
            if (stateMap.get("CurrentURIFormatted") != null) {
                newState = new StringType(stateMap.get("CurrentURIFormatted"));
            }
            break;
        case CURRENTTITLE:
            if (stateMap.get("CurrentTitle") != null) {
                newState = new StringType(stateMap.get("CurrentTitle"));
            }
            break;
        case CURRENTARTIST:
            if (stateMap.get("CurrentArtist") != null) {
                newState = new StringType(stateMap.get("CurrentArtist"));
            }
            break;
        case CURRENTALBUM:
            if (stateMap.get("CurrentAlbum") != null) {
                newState = new StringType(stateMap.get("CurrentAlbum"));
            }
            break;
        case CURRENTALBUMART:
            newState = null;
            updateAlbumArtChannel(false);
            break;
        case CURRENTALBUMARTURL:
            url = getAlbumArtUrl();
            if (url != null) {
                newState = new StringType(url);
            }
            break;
        case CURRENTTRANSPORTURI:
            if (stateMap.get("CurrentURI") != null) {
                newState = new StringType(stateMap.get("CurrentURI"));
            }
            break;
        case CURRENTTRACKURI:
            if (stateMap.get("CurrentTrackURI") != null) {
                newState = new StringType(stateMap.get("CurrentTrackURI"));
            }
            break;
        case TUNEINSTATIONID:
            if (stateMap.get("CurrentTuneInStationId") != null) {
                newState = new StringType(stateMap.get("CurrentTuneInStationId"));
            }
            break;
        default:
            newState = null;
            break;
    }
    if (newState != null) {
        updateState(channelId, newState);
    }
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) SonosZonePlayerState(org.eclipse.smarthome.binding.sonos.internal.SonosZonePlayerState) State(org.eclipse.smarthome.core.types.State) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 42 with PercentType

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

the class TradfriColorTest method testCalculateColorTemperature.

@Test
public void testCalculateColorTemperature() {
    // preset 1 -> coldest -> 0 percent
    PercentType preset1 = new TradfriColor(24933, 24691, null).getColorTemperature();
    assertEquals(0, preset1.intValue());
    // preset 2 -> middle -> 50 percent
    PercentType preset2 = new TradfriColor(30138, 26909, null).getColorTemperature();
    assertEquals(50, preset2.intValue());
    // preset 3 -> warmest -> 100 percent
    PercentType preset3 = new TradfriColor(33137, 27211, null).getColorTemperature();
    assertEquals(100, preset3.intValue());
    // preset 3 -> warmest -> 100 percent
    PercentType colder = new TradfriColor(22222, 23333, null).getColorTemperature();
    assertEquals(0, colder.intValue());
    // preset 3 -> warmest -> 100 percent
    PercentType temp3 = new TradfriColor(34000, 34000, null).getColorTemperature();
    assertEquals(100, temp3.intValue());
    // mixed case 1
    PercentType mixed1 = new TradfriColor(0, 1000000, null).getColorTemperature();
    assertEquals(0, mixed1.intValue());
    // mixed case 1
    PercentType mixed2 = new TradfriColor(1000000, 0, null).getColorTemperature();
    assertEquals(100, mixed2.intValue());
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) Test(org.junit.Test)

Example 43 with PercentType

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

the class LifxMessageUtil method increaseDecreasePercentType.

public static PercentType increaseDecreasePercentType(IncreaseDecreaseType increaseDecreaseType, PercentType old) {
    BigDecimal delta = ZERO;
    if (increaseDecreaseType == IncreaseDecreaseType.INCREASE) {
        delta = INCREASE_DECREASE_STEP;
    } else if (increaseDecreaseType == IncreaseDecreaseType.DECREASE) {
        delta = INCREASE_DECREASE_STEP.negate();
    }
    if (!ZERO.equals(delta)) {
        BigDecimal newValue = old.toBigDecimal().add(delta);
        newValue = newValue.setScale(0, RoundingMode.HALF_UP);
        newValue = newValue.min(HUNDRED);
        newValue = newValue.max(ZERO);
        return new PercentType(newValue);
    } else {
        return old;
    }
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) BigDecimal(java.math.BigDecimal)

Example 44 with PercentType

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

the class TradfriLightData method getBrightness.

public PercentType getBrightness() {
    PercentType result = null;
    JsonElement dimmer = attributes.get(DIMMER);
    if (dimmer != null) {
        result = TradfriColor.xyBrightnessToPercentType(dimmer.getAsInt());
    }
    return result;
}
Also used : JsonElement(com.google.gson.JsonElement) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 45 with PercentType

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

the class VoiceManagerImpl method say.

@Override
public void say(String text, String voiceId, String sinkId, PercentType volume) {
    Objects.requireNonNull(text, "Text cannot be said as it is null.");
    try {
        TTSService tts = null;
        Voice voice = null;
        String selectedVoiceId = voiceId;
        if (selectedVoiceId == null) {
            // use the configured default, if set
            selectedVoiceId = defaultVoice;
        }
        if (selectedVoiceId == null) {
            tts = getTTS();
            if (tts != null) {
                voice = getPreferredVoice(tts.getAvailableVoices());
            }
        } else if (selectedVoiceId.contains(":")) {
            // it is a fully qualified unique id
            String[] segments = selectedVoiceId.split(":");
            tts = getTTS(segments[0]);
            if (tts != null) {
                voice = getVoice(tts.getAvailableVoices(), segments[1]);
            }
        } else {
            // voiceId is not fully qualified
            tts = getTTS();
            if (tts != null) {
                voice = getVoice(tts.getAvailableVoices(), selectedVoiceId);
            }
        }
        if (tts == null) {
            throw new TTSException("No TTS service can be found for voice " + selectedVoiceId);
        }
        if (voice == null) {
            throw new TTSException("Unable to find a voice for language " + localeProvider.getLocale().getLanguage());
        }
        Set<AudioFormat> audioFormats = tts.getSupportedFormats();
        AudioSink sink = audioManager.getSink(sinkId);
        if (sink != null) {
            AudioFormat audioFormat = getBestMatch(audioFormats, sink.getSupportedFormats());
            if (audioFormat != null) {
                AudioStream audioStream = tts.synthesize(text, voice, audioFormat);
                if (sink.getSupportedStreams().stream().anyMatch(clazz -> clazz.isInstance(audioStream))) {
                    // get current volume
                    PercentType oldVolume = audioManager.getVolume(sinkId);
                    // set notification sound volume
                    if (volume != null) {
                        audioManager.setVolume(volume, sinkId);
                    }
                    try {
                        sink.process(audioStream);
                    } catch (UnsupportedAudioFormatException | UnsupportedAudioStreamException e) {
                        logger.warn("Error saying '{}': {}", text, e.getMessage(), e);
                    } finally {
                        if (volume != null) {
                            // restore volume only if it was set before
                            audioManager.setVolume(oldVolume, sinkId);
                        }
                    }
                } else {
                    logger.warn("Failed playing audio stream '{}' as audio sink doesn't support it.", audioStream);
                }
            } else {
                logger.warn("No compatible audio format found for TTS '{}' and sink '{}'", tts.getId(), sink.getId());
            }
        }
    } catch (TTSException e) {
        logger.warn("Error saying '{}': {}", text, e.getMessage(), e);
    }
}
Also used : AudioSink(org.eclipse.smarthome.core.audio.AudioSink) AudioStream(org.eclipse.smarthome.core.audio.AudioStream) UnsupportedAudioFormatException(org.eclipse.smarthome.core.audio.UnsupportedAudioFormatException) TTSService(org.eclipse.smarthome.core.voice.TTSService) TTSException(org.eclipse.smarthome.core.voice.TTSException) PercentType(org.eclipse.smarthome.core.library.types.PercentType) AudioFormat(org.eclipse.smarthome.core.audio.AudioFormat) Voice(org.eclipse.smarthome.core.voice.Voice) UnsupportedAudioStreamException(org.eclipse.smarthome.core.audio.UnsupportedAudioStreamException)

Aggregations

PercentType (org.eclipse.smarthome.core.library.types.PercentType)63 Test (org.junit.Test)25 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)17 State (org.eclipse.smarthome.core.types.State)17 HSBType (org.eclipse.smarthome.core.library.types.HSBType)16 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)13 LifxMessageUtil.increaseDecreasePercentType (org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)9 StringType (org.eclipse.smarthome.core.library.types.StringType)9 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)7 RefreshType (org.eclipse.smarthome.core.types.RefreshType)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)4 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 BigDecimal (java.math.BigDecimal)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)3 LinkedList (java.util.LinkedList)2