Search in sources :

Example 1 with HmDevice

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.

the class HomegearLoadDeviceNamesParser method parse.

@Override
@SuppressWarnings("unchecked")
public Void parse(Object[] message) throws IOException {
    Map<String, HmDevice> devicesById = new HashMap<String, HmDevice>();
    for (HmDevice device : devices) {
        devicesById.put(device.getHomegearId(), device);
    }
    message = (Object[]) message[0];
    for (int i = 0; i < message.length; i++) {
        Map<String, ?> data = (Map<String, ?>) message[i];
        String id = toString(data.get("ID"));
        String name = toString(data.get("NAME"));
        HmDevice device = devicesById.get(getSanitizedAddress(id));
        if (device != null) {
            device.setName(name);
        }
    }
    return null;
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with HmDevice

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.

the class HomematicThingHandler method doInitializeInBackground.

private void doInitializeInBackground() throws GatewayNotAvailableException, HomematicClientException, IOException {
    HomematicGateway gateway = getHomematicGateway();
    HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
    HmChannel channelZero = device.getChannel(0);
    loadHomematicChannelValues(channelZero);
    updateStatus(device);
    logger.debug("Initializing thing '{}' from gateway '{}'", getThing().getUID(), gateway.getId());
    // update properties
    Map<String, String> properties = editProperties();
    setProperty(properties, channelZero, PROPERTY_BATTERY_TYPE, VIRTUAL_DATAPOINT_NAME_BATTERY_TYPE);
    setProperty(properties, channelZero, Thing.PROPERTY_FIRMWARE_VERSION, VIRTUAL_DATAPOINT_NAME_FIRMWARE);
    setProperty(properties, channelZero, Thing.PROPERTY_SERIAL_NUMBER, device.getAddress());
    setProperty(properties, channelZero, PROPERTY_AES_KEY, DATAPOINT_NAME_AES_KEY);
    updateProperties(properties);
    // update data point list for reconfigurable channels
    for (HmChannel channel : device.getChannels()) {
        if (channel.isReconfigurable()) {
            loadHomematicChannelValues(channel);
            if (channel.checkForChannelFunctionChange()) {
                gateway.updateChannelValueDatapoints(channel);
            }
        }
    }
    // update configurations
    Configuration config = editConfiguration();
    for (HmChannel channel : device.getChannels()) {
        loadHomematicChannelValues(channel);
        for (HmDatapoint dp : channel.getDatapoints()) {
            if (dp.getParamsetType() == HmParamsetType.MASTER) {
                config.put(MetadataUtils.getParameterName(dp), dp.isEnumType() ? dp.getOptionValue() : dp.getValue());
            }
        }
    }
    updateConfiguration(config);
    // update thing channel list for reconfigurable channels (relies on the new value of the
    // CHANNEL_FUNCTION datapoint fetched during configuration update)
    List<Channel> thingChannels = new ArrayList<>(getThing().getChannels());
    if (updateDynamicChannelList(device, thingChannels)) {
        updateThing(editThing().withChannels(thingChannels).build());
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) Configuration(org.eclipse.smarthome.config.core.Configuration) Channel(org.eclipse.smarthome.core.thing.Channel) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) ArrayList(java.util.ArrayList) HomematicGateway(org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 3 with HmDevice

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.

the class HomematicThingHandler method handleConfigurationUpdate.

@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) throws ConfigValidationException {
    super.handleConfigurationUpdate(configurationParameters);
    try {
        HomematicGateway gateway = getHomematicGateway();
        HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
        for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
            String key = configurationParameter.getKey();
            Object newValue = configurationParameter.getValue();
            if (key.startsWith("HMP_")) {
                key = StringUtils.removeStart(key, "HMP_");
                Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
                String dpName = StringUtils.substringAfter(key, "_");
                HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER, channelNumber, dpName);
                HmDatapoint dp = device.getChannel(channelNumber).getDatapoint(dpInfo);
                if (dp != null) {
                    try {
                        if (newValue != null) {
                            if (newValue instanceof BigDecimal) {
                                final BigDecimal decimal = (BigDecimal) newValue;
                                if (dp.isIntegerType()) {
                                    newValue = decimal.intValue();
                                } else if (dp.isFloatType()) {
                                    newValue = decimal.doubleValue();
                                }
                            }
                            if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) {
                                sendDatapoint(dp, new HmDatapointConfig(), newValue);
                            }
                        }
                    } catch (IOException ex) {
                        logger.error("Error setting thing property {}: {}", dpInfo, ex.getMessage());
                    }
                } else {
                    logger.error("Can't find datapoint for thing property {}", dpInfo);
                }
            }
        }
        gateway.triggerDeviceValuesReload(device);
    } catch (HomematicClientException | GatewayNotAvailableException ex) {
        logger.error("Error setting thing properties: {}", ex.getMessage(), ex);
    }
}
Also used : HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) HomematicGateway(org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)

Example 4 with HmDevice

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.

the class AbstractHomematicGateway method getDatapoint.

@Override
public HmDatapoint getDatapoint(HmDatapointInfo dpInfo) throws HomematicClientException {
    HmDevice device = getDevice(dpInfo.getAddress());
    HmChannel channel = device.getChannel(dpInfo.getChannel());
    if (channel == null) {
        throw new HomematicClientException(String.format("Channel %s in device '%s' not found on gateway '%s'", dpInfo.getChannel(), dpInfo.getAddress(), id));
    }
    HmDatapoint dp = channel.getDatapoint(dpInfo);
    if (dp == null) {
        throw new HomematicClientException(String.format("Datapoint '%s' not found on gateway '%s'", dpInfo, id));
    }
    return dp;
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 5 with HmDevice

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.

the class AbstractHomematicGateway method newDevices.

@Override
public void newDevices(List<String> adresses) {
    if (initialized && newDeviceEventsEnabled) {
        for (String address : adresses) {
            try {
                logger.debug("New device '{}' detected on gateway with id '{}'", address, id);
                List<HmDevice> deviceDescriptions = getDeviceDescriptions();
                for (HmDevice device : deviceDescriptions) {
                    if (device.getAddress().equals(address)) {
                        for (HmChannel channel : device.getChannels()) {
                            addChannelDatapoints(channel, HmParamsetType.MASTER);
                            addChannelDatapoints(channel, HmParamsetType.VALUES);
                        }
                        prepareDevice(device);
                        gatewayAdapter.onNewDevice(device);
                    }
                }
            } catch (Exception ex) {
                logger.error("{}", ex.getMessage(), ex);
            }
        }
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) IOException(java.io.IOException) UnknownParameterSetException(org.eclipse.smarthome.binding.homematic.internal.communicator.client.UnknownParameterSetException)

Aggregations

HmDevice (org.eclipse.smarthome.binding.homematic.internal.model.HmDevice)20 HmChannel (org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)9 HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)7 HomematicClientException (org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException)5 DimmerHelper.createDimmerHmDevice (org.eclipse.smarthome.binding.homematic.test.util.DimmerHelper.createDimmerHmDevice)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 HomematicGateway (org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway)2 HmDatapointConfig (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig)2 HmDatapointInfo (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)2 HmInterface (org.eclipse.smarthome.binding.homematic.internal.model.HmInterface)2 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)2 BigDecimal (java.math.BigDecimal)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 UnknownParameterSetException (org.eclipse.smarthome.binding.homematic.internal.communicator.client.UnknownParameterSetException)1 BatteryTypeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler)1