use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class DeviceHandler method onDeviceStateChanged.
@Override
public synchronized void onDeviceStateChanged(DeviceStateUpdate deviceStateUpdate) {
if (device != null) {
if (deviceStateUpdate != null) {
if (sensorChannelsLoaded()) {
if (deviceStateUpdate.isSensorUpdateType()) {
updateState(getSensorChannelID(deviceStateUpdate.getTypeAsSensorEnum()), new DecimalType(deviceStateUpdate.getValueAsFloat()));
logger.debug("Update ESH-State");
return;
}
if (deviceStateUpdate.isBinarayInputType()) {
if (deviceStateUpdate.getValueAsShort() == 1) {
updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.ON);
} else {
updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.OFF);
}
}
}
if (!device.isShade()) {
if (currentChannel != null) {
switch(deviceStateUpdate.getType()) {
case DeviceStateUpdate.OUTPUT_DECREASE:
case DeviceStateUpdate.OUTPUT_INCREASE:
case DeviceStateUpdate.OUTPUT:
if (currentChannel.contains(DsChannelTypeProvider.DIMMER)) {
if (deviceStateUpdate.getValueAsInteger() > 0) {
updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxOutputValue())));
} else {
updateState(currentChannel, OnOffType.OFF);
}
} else if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
if (currentChannel.contains(TWO_STAGE_SWITCH_IDENTICATOR)) {
updateState(currentChannel, new StringType(convertStageValue((short) 2, device.getOutputValue())));
} else {
updateState(currentChannel, new StringType(convertStageValue((short) 3, device.getOutputValue())));
}
}
break;
case DeviceStateUpdate.ON_OFF:
if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
onDeviceStateChanged(new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT, device.getOutputValue()));
}
if (deviceStateUpdate.getValueAsInteger() > 0) {
updateState(currentChannel, OnOffType.ON);
} else {
updateState(currentChannel, OnOffType.OFF);
}
break;
default:
return;
}
}
} else {
int percent = 0;
switch(deviceStateUpdate.getType()) {
case DeviceStateUpdate.SLAT_DECREASE:
case DeviceStateUpdate.SLAT_INCREASE:
case DeviceStateUpdate.SLATPOSITION:
percent = fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatPosition());
break;
case DeviceStateUpdate.OPEN_CLOSE:
if (deviceStateUpdate.getValueAsInteger() > 0) {
percent = 100;
}
break;
case DeviceStateUpdate.OPEN_CLOSE_ANGLE:
if (device.isBlind() && currentChannel != null) {
if (deviceStateUpdate.getValueAsInteger() > 0) {
updateState(currentChannel, PercentType.HUNDRED);
} else {
updateState(currentChannel, PercentType.ZERO);
}
}
return;
case DeviceStateUpdate.SLAT_ANGLE_DECREASE:
case DeviceStateUpdate.SLAT_ANGLE_INCREASE:
case DeviceStateUpdate.SLAT_ANGLE:
if (device.isBlind() && currentChannel != null) {
updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatAngle())));
}
return;
default:
return;
}
if (!device.getHWinfo().equals("GR-KL210")) {
percent = 100 - percent;
}
updateState(DsChannelTypeProvider.SHADE, new PercentType(percent));
}
logger.debug("Update ESH-State");
}
}
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class NtpOSGiTest method assertEventIsReceived.
private void assertEventIsReceived(UpdateEventType updateEventType, String channelID, String acceptedItemType) {
Configuration configuration = new Configuration();
initialize(configuration, channelID, acceptedItemType, null, null);
EventSubscriber eventSubscriberMock = mock(EventSubscriber.class);
when(eventSubscriberMock.getSubscribedEventTypes()).thenReturn(Collections.singleton(ItemStateEvent.TYPE));
registerService(eventSubscriberMock);
if (updateEventType.equals(UpdateEventType.HANDLE_COMMAND)) {
ntpHandler.handleCommand(new ChannelUID("ntp:test:chan:1"), new StringType("test"));
} else if (updateEventType.equals(UpdateEventType.CHANNEL_LINKED)) {
ntpHandler.channelLinked(new ChannelUID("ntp:test:chan:1"));
}
waitForAssert(() -> {
verify(eventSubscriberMock, atLeastOnce()).receive(ArgumentMatchers.any(Event.class));
});
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class SonosAudioSink method process.
@Override
public void process(AudioStream audioStream) throws UnsupportedAudioFormatException, UnsupportedAudioStreamException {
if (audioStream == null) {
// in case the audioStream is null, this should be interpreted as a request to end any currently playing
// stream.
logger.trace("Stop currently playing stream.");
handler.stopPlaying(OnOffType.ON);
} else if (audioStream instanceof URLAudioStream) {
// it is an external URL, the speaker can access it itself and play it.
URLAudioStream urlAudioStream = (URLAudioStream) audioStream;
handler.playURI(new StringType(urlAudioStream.getURL()));
try {
audioStream.close();
} catch (IOException e) {
}
} else if (audioStream instanceof FixedLengthAudioStream) {
// the AudioServlet, so a one time serving won't work.
if (callbackUrl != null) {
String relativeUrl = audioHTTPServer.serve((FixedLengthAudioStream) audioStream, 10).toString();
String url = callbackUrl + relativeUrl;
AudioFormat format = audioStream.getFormat();
if (!ThingHandlerHelper.isHandlerInitialized(handler)) {
logger.warn("Sonos speaker '{}' is not initialized - status is {}", handler.getThing().getUID(), handler.getThing().getStatus());
} else if (AudioFormat.WAV.isCompatible(format)) {
handler.playNotificationSoundURI(new StringType(url + AudioStreamUtils.EXTENSION_SEPARATOR + FileAudioStream.WAV_EXTENSION));
} else if (AudioFormat.MP3.isCompatible(format)) {
handler.playNotificationSoundURI(new StringType(url + AudioStreamUtils.EXTENSION_SEPARATOR + FileAudioStream.MP3_EXTENSION));
} else {
throw new UnsupportedAudioFormatException("Sonos only supports MP3 or WAV.", format);
}
} else {
logger.warn("We do not have any callback url, so Sonos cannot play the audio stream!");
}
} else {
IOUtils.closeQuietly(audioStream);
throw new UnsupportedAudioStreamException("Sonos can only handle FixedLengthAudioStreams and URLAudioStreams.", audioStream.getClass());
// Instead of throwing an exception, we could ourselves try to wrap it into a
// FixedLengthAudioStream, but this might be dangerous as we have no clue, how much data to expect from
// the stream.
}
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class AbstractRuleBasedInterpreter method itemRule.
/**
* Creates an item rule on base of a head and a tail expression, where the middle part of the new rule's expression
* will consist of an item
* name expression. Either the head expression or the tail expression should contain at least one {@link cmd}
* generated expression.
*
* @param headExpression The head expression.
* @param tailExpression The tail expression.
* @return The created rule.
*/
protected Rule itemRule(Object headExpression, Object tailExpression) {
Expression tail = exp(tailExpression);
Expression expression = tail == null ? seq(headExpression, name()) : seq(headExpression, name(tail), tail);
return new Rule(expression) {
@Override
public InterpretationResult interpretAST(ResourceBundle language, ASTNode node) {
String[] name = node.findValueAsStringArray(NAME);
ASTNode cmdNode = node.findNode(CMD);
Object tag = cmdNode.getTag();
Object value = cmdNode.getValue();
Command command;
if (tag instanceof Command) {
command = (Command) tag;
} else if (value instanceof Number) {
command = new DecimalType(((Number) value).longValue());
} else {
command = new StringType(cmdNode.getValueAsString());
}
if (name != null && command != null) {
try {
return new InterpretationResult(true, executeSingle(language, name, command));
} catch (InterpretationException ex) {
return new InterpretationResult(ex);
}
}
return InterpretationResult.SEMANTIC_ERROR;
}
};
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class ChaserThingHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
switch(channelUID.getId()) {
case CHANNEL_SWITCH:
if (command instanceof OnOffType) {
if (((OnOffType) command).equals(OnOffType.ON)) {
Integer channelCounter = 0;
for (DmxChannel channel : channels) {
if (resumeAfter) {
channel.suspendAction();
} else {
channel.clearAction();
}
for (ValueSet value : values) {
channel.addChannelAction(new FadeAction(value.getFadeTime(), value.getValue(channelCounter), value.getHoldTime()));
}
if (resumeAfter) {
channel.addChannelAction(new ResumeAction());
}
channel.addListener(channelUID, this, ListenerType.ACTION);
channelCounter++;
}
} else {
for (DmxChannel channel : channels) {
if (resumeAfter && channel.isSuspended()) {
channel.setChannelAction(new ResumeAction());
} else {
channel.clearAction();
}
}
}
} else if (command instanceof RefreshType) {
updateState(channelUID, isRunning);
} else {
logger.debug("command {} not supported in channel {}:switch", command.getClass(), this.thing.getUID());
}
break;
case CHANNEL_CONTROL:
if (command instanceof StringType) {
Vector<ValueSet> oldValues = new Vector<ValueSet>(values);
if (parseChaserConfig(((StringType) command).toString())) {
logger.debug("updated chase config in {}", this.thing.getUID());
} else {
// restore old chase config
values = oldValues;
logger.debug("could not update chase config in {}, malformed", this.thing.getUID());
}
} else {
logger.debug("command {} not supported in channel {}:control", command.getClass(), this.thing.getUID());
}
break;
default:
logger.debug("Channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
}
}
Aggregations