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);
}
}
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());
}
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;
}
}
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;
}
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);
}
}
Aggregations