Search in sources :

Example 1 with DeviceBinarayInputEnum

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum in project smarthome by eclipse.

the class DeviceHandler method checkSensorChannel.

private void checkSensorChannel() {
    List<Channel> channelList = new LinkedList<Channel>(this.getThing().getChannels());
    boolean channelListChanged = false;
    // if sensor channels with priority never are loaded delete these channels
    if (!channelList.isEmpty()) {
        Iterator<Channel> channelInter = channelList.iterator();
        while (channelInter.hasNext()) {
            Channel channel = channelInter.next();
            String channelID = channel.getUID().getId();
            if (channelID.startsWith(DsChannelTypeProvider.BINARY_INPUT_PRE)) {
                DeviceBinarayInputEnum devBinInput = getBinaryInput(channelID);
                if (device.getBinaryInput(devBinInput) != null) {
                    addLoadedSensorChannel(channelID);
                } else {
                    logger.debug("remove {} binary input channel", channelID);
                    channelInter.remove();
                    channelListChanged = removeLoadedSensorChannel(channelID);
                }
            } else {
                SensorEnum sensorType = getSensorEnum(channelID);
                if (sensorType != null) {
                    if (SensorEnum.isPowerSensor(sensorType)) {
                        if (device.checkPowerSensorRefreshPriorityNever(sensorType)) {
                            logger.debug("remove {} sensor channel", channelID);
                            channelInter.remove();
                            channelListChanged = removeLoadedSensorChannel(channelID);
                        } else {
                            addLoadedSensorChannel(channelID);
                        }
                    } else {
                        if (device.supportsSensorType(sensorType)) {
                            addLoadedSensorChannel(channelID);
                        } else {
                            logger.debug("remove {} sensor channel", channelID);
                            channelInter.remove();
                            removeLoadedSensorChannel(channelID);
                            channelListChanged = true;
                        }
                    }
                }
            }
        }
    }
    for (SensorEnum sensorType : device.getPowerSensorTypes()) {
        if (!device.checkPowerSensorRefreshPriorityNever(sensorType) && !isSensorChannelLoaded(getSensorChannelID(sensorType))) {
            logger.debug("create {} sensor channel", sensorType.toString());
            channelList.add(getSensorChannel(sensorType));
            channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
        }
    }
    if (device.hasClimateSensors()) {
        for (SensorEnum sensorType : device.getClimateSensorTypes()) {
            if (!isSensorChannelLoaded(getSensorChannelID(sensorType))) {
                logger.debug("create {} sensor channel", sensorType.toString());
                channelList.add(getSensorChannel(sensorType));
                channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
            }
        }
    }
    if (device.isBinaryInputDevice()) {
        for (DeviceBinaryInput binInput : device.getBinaryInputs()) {
            DeviceBinarayInputEnum binInputType = DeviceBinarayInputEnum.getdeviceBinarayInput(binInput.getInputType());
            if (binInputType != null && !isSensorChannelLoaded(getBinaryInputChannelID(binInputType))) {
                logger.debug("create {} sensor channel", binInputType.toString());
                channelList.add(getBinaryChannel(binInputType));
                channelListChanged = addLoadedSensorChannel(getBinaryInputChannelID(binInputType));
            }
        }
    }
    if (channelListChanged) {
        logger.debug("load new channel list");
        ThingBuilder thingBuilder = editThing();
        thingBuilder.withChannels(channelList);
        updateThing(thingBuilder.build());
    }
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) DeviceBinaryInput(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceBinaryInput) SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) DeviceBinarayInputEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum) Channel(org.eclipse.smarthome.core.thing.Channel) LinkedList(java.util.LinkedList)

Example 2 with DeviceBinarayInputEnum

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum in project smarthome by eclipse.

the class DeviceStatusManagerImpl method handleEvent.

@Override
public void handleEvent(EventItem eventItem) {
    if (EventNames.DEVICE_SENSOR_VALUE.equals(eventItem.getName()) || EventNames.DEVICE_BINARY_INPUT_EVENT.equals(eventItem.getName())) {
        logger.debug("Detect {} eventItem = {}", eventItem.getName(), eventItem.toString());
        Device dev = getDeviceOfEvent(eventItem);
        if (dev != null) {
            if (EventNames.DEVICE_SENSOR_VALUE.equals(eventItem.getName())) {
                dev.setDeviceSensorByEvent(eventItem);
            } else {
                DeviceBinarayInputEnum binaryInputType = DeviceBinarayInputEnum.getdeviceBinarayInput(Short.parseShort(eventItem.getProperties().get(EventResponseEnum.INPUT_TYPE)));
                Short newState = Short.parseShort(eventItem.getProperties().get(EventResponseEnum.INPUT_STATE));
                if (binaryInputType != null) {
                    dev.setBinaryInputState(binaryInputType, newState);
                }
            }
        }
    }
}
Also used : Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) DeviceBinarayInputEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum)

Example 3 with DeviceBinarayInputEnum

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum in project smarthome by eclipse.

the class DsChannelTypeProvider method getChannelTypes.

@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
    List<ChannelType> channelTypeList = new LinkedList<ChannelType>();
    for (String channelTypeId : supportedOutputChannelTypes) {
        channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, channelTypeId), locale));
    }
    for (SensorEnum sensorType : SensorEnum.values()) {
        channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, buildIdentifier(sensorType)), locale));
    }
    for (MeteringTypeEnum meteringType : MeteringTypeEnum.values()) {
        channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, buildIdentifier(meteringType, MeteringUnitsEnum.WH)), locale));
        channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, buildIdentifier(TOTAL_PRE, meteringType, MeteringUnitsEnum.WH)), locale));
    }
    for (DeviceBinarayInputEnum binaryInput : DeviceBinarayInputEnum.values()) {
        channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, buildIdentifier(BINARY_INPUT_PRE, binaryInput)), locale));
    }
    return channelTypeList;
}
Also used : MeteringTypeEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) DeviceBinarayInputEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) LinkedList(java.util.LinkedList)

Aggregations

DeviceBinarayInputEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum)3 LinkedList (java.util.LinkedList)2 SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)2 Device (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device)1 MeteringTypeEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum)1 DeviceBinaryInput (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceBinaryInput)1 Channel (org.eclipse.smarthome.core.thing.Channel)1 ThingBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder)1 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1