Search in sources :

Example 21 with StringType

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");
        }
    }
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 22 with StringType

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));
    });
}
Also used : EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) Configuration(org.eclipse.smarthome.config.core.Configuration) StringType(org.eclipse.smarthome.core.library.types.StringType) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ItemStateEvent(org.eclipse.smarthome.core.items.events.ItemStateEvent) Event(org.eclipse.smarthome.core.events.Event)

Example 23 with StringType

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.
    }
}
Also used : UnsupportedAudioFormatException(org.eclipse.smarthome.core.audio.UnsupportedAudioFormatException) FixedLengthAudioStream(org.eclipse.smarthome.core.audio.FixedLengthAudioStream) StringType(org.eclipse.smarthome.core.library.types.StringType) URLAudioStream(org.eclipse.smarthome.core.audio.URLAudioStream) IOException(java.io.IOException) AudioFormat(org.eclipse.smarthome.core.audio.AudioFormat) UnsupportedAudioStreamException(org.eclipse.smarthome.core.audio.UnsupportedAudioStreamException)

Example 24 with StringType

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;
        }
    };
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) Command(org.eclipse.smarthome.core.types.Command) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ResourceBundle(java.util.ResourceBundle)

Example 25 with StringType

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());
    }
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) ResumeAction(org.eclipse.smarthome.binding.dmx.internal.action.ResumeAction) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) Vector(java.util.Vector)

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