Search in sources :

Example 6 with HmDevice

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

the class AbstractHomematicGateway method setInstallMode.

@Override
public void setInstallMode(boolean enable, int seconds) throws IOException {
    HmDevice gwExtrasHm = devices.get(HmDevice.ADDRESS_GATEWAY_EXTRAS);
    if (gwExtrasHm != null) {
        // since the homematic virtual device exist: try setting install mode via its dataPoints
        HmDatapoint installModeDataPoint = null;
        HmDatapoint installModeDurationDataPoint = null;
        // collect virtual datapoints to be accessed
        HmChannel hmChannel = gwExtrasHm.getChannel(HmChannel.CHANNEL_NUMBER_EXTRAS);
        HmDatapointInfo installModeDurationDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE_DURATION);
        if (enable) {
            installModeDurationDataPoint = hmChannel.getDatapoint(installModeDurationDataPointInfo);
        }
        HmDatapointInfo installModeDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE);
        installModeDataPoint = hmChannel.getDatapoint(installModeDataPointInfo);
        // first set duration on the datapoint
        if (installModeDurationDataPoint != null) {
            try {
                VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDurationDataPoint, null);
                handler.handleCommand(this, installModeDurationDataPoint, new HmDatapointConfig(), seconds);
                // notify thing if exists
                gatewayAdapter.onStateUpdated(installModeDurationDataPoint);
            } catch (HomematicClientException ex) {
                logger.warn("Failed to send datapoint {}", installModeDurationDataPoint, ex);
            }
        }
        // now that the duration is set, we can enable / disable
        if (installModeDataPoint != null) {
            try {
                VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDataPoint, null);
                handler.handleCommand(this, installModeDataPoint, new HmDatapointConfig(), enable);
                // notify thing if exists
                gatewayAdapter.onStateUpdated(installModeDataPoint);
                return;
            } catch (HomematicClientException ex) {
                logger.warn("Failed to send datapoint {}", installModeDataPoint, ex);
            }
        }
    }
    // no gwExtrasHm available (or previous approach failed), therefore use rpc client directly
    for (HmInterface hmInterface : availableInterfaces.keySet()) {
        if (hmInterface == HmInterface.RF || hmInterface == HmInterface.CUXD) {
            getRpcClient(hmInterface).setInstallMode(hmInterface, enable, seconds);
        }
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) HmInterface(org.eclipse.smarthome.binding.homematic.internal.model.HmInterface) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) ReloadFromGatewayVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadFromGatewayVirtualDatapointHandler) RssiVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.RssiVirtualDatapointHandler) ReloadAllFromGatewayVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadAllFromGatewayVirtualDatapointHandler) StateContactVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.StateContactVirtualDatapointHandler) SignalStrengthVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.SignalStrengthVirtualDatapointHandler) ButtonVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ButtonVirtualDatapointHandler) FirmwareVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.FirmwareVirtualDatapointHandler) ReloadRssiVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadRssiVirtualDatapointHandler) DeleteDeviceModeVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler) VirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualDatapointHandler) DeleteDeviceVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceVirtualDatapointHandler) HmwIoModuleVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.HmwIoModuleVirtualDatapointHandler) OnTimeAutomaticVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.OnTimeAutomaticVirtualDatapointHandler) BatteryTypeVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler) DisplayOptionsVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DisplayOptionsVirtualDatapointHandler)

Example 7 with HmDevice

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

the class AbstractHomematicGateway method loadAllDeviceMetadata.

@Override
public void loadAllDeviceMetadata() throws IOException {
    cancelLoadAllMetadata = false;
    // load all device descriptions
    List<HmDevice> deviceDescriptions = getDeviceDescriptions();
    // loading datapoints for all channels
    Set<String> loadedDevices = new HashSet<String>();
    Map<String, Collection<HmDatapoint>> datapointsByChannelIdCache = new HashMap<String, Collection<HmDatapoint>>();
    for (HmDevice device : deviceDescriptions) {
        if (!cancelLoadAllMetadata) {
            try {
                logger.trace("Loading metadata for device '{}' of type '{}'", device.getAddress(), device.getType());
                if (device.isGatewayExtras()) {
                    loadChannelValues(device.getChannel(HmChannel.CHANNEL_NUMBER_VARIABLE));
                    loadChannelValues(device.getChannel(HmChannel.CHANNEL_NUMBER_SCRIPT));
                } else {
                    for (HmChannel channel : device.getChannels()) {
                        logger.trace("  Loading channel {}", channel);
                        // speed up metadata generation a little bit for equal channels in the gateway devices
                        if ((DEVICE_TYPE_VIRTUAL.equals(device.getType()) || DEVICE_TYPE_VIRTUAL_WIRED.equals(device.getType())) && channel.getNumber() > 1) {
                            HmChannel previousChannel = device.getChannel(channel.getNumber() - 1);
                            cloneAllDatapointsIntoChannel(channel, previousChannel.getDatapoints());
                        } else {
                            String channelId = String.format("%s:%s:%s", channel.getDevice().getType(), channel.getDevice().getFirmware(), channel.getNumber());
                            Collection<HmDatapoint> cachedDatapoints = datapointsByChannelIdCache.get(channelId);
                            if (cachedDatapoints != null) {
                                // clone all datapoints
                                cloneAllDatapointsIntoChannel(channel, cachedDatapoints);
                            } else {
                                logger.trace("    Loading datapoints into channel {}", channel);
                                addChannelDatapoints(channel, HmParamsetType.MASTER);
                                addChannelDatapoints(channel, HmParamsetType.VALUES);
                                // the data point set might change depending on the selected mode.
                                if (!channel.isReconfigurable()) {
                                    datapointsByChannelIdCache.put(channelId, channel.getDatapoints());
                                }
                            }
                        }
                    }
                }
                prepareDevice(device);
                loadedDevices.add(device.getAddress());
                gatewayAdapter.onDeviceLoaded(device);
            } catch (IOException ex) {
                logger.warn("Can't load device with address '{}' from gateway '{}': {}", device.getAddress(), id, ex.getMessage());
            }
        }
    }
    if (!cancelLoadAllMetadata) {
        devices.keySet().retainAll(loadedDevices);
    }
    initialized = true;
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HashMap(java.util.HashMap) Collection(java.util.Collection) IOException(java.io.IOException) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HashSet(java.util.HashSet) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 8 with HmDevice

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

the class AbstractHomematicGateway method getDeviceDescriptions.

/**
 * Loads all device descriptions from the gateway.
 */
private List<HmDevice> getDeviceDescriptions() throws IOException {
    List<HmDevice> deviceDescriptions = new ArrayList<HmDevice>();
    for (HmInterface hmInterface : availableInterfaces.keySet()) {
        deviceDescriptions.addAll(getRpcClient(hmInterface).listDevices(hmInterface));
    }
    if (!cancelLoadAllMetadata) {
        deviceDescriptions.add(createGatewayDevice());
        loadDeviceNames(deviceDescriptions);
    }
    return deviceDescriptions;
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) ArrayList(java.util.ArrayList) HmInterface(org.eclipse.smarthome.binding.homematic.internal.model.HmInterface)

Example 9 with HmDevice

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

the class AbstractHomematicGateway method deleteDevices.

@Override
public void deleteDevices(List<String> addresses) {
    if (initialized) {
        for (String address : addresses) {
            logger.debug("Device '{}' removed from gateway with id '{}'", address, id);
            HmDevice device = devices.remove(address);
            if (device != null) {
                gatewayAdapter.onDeviceDeleted(device);
            }
        }
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice)

Example 10 with HmDevice

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

the class BaseConverterTest method setup.

@Before
public void setup() {
    HmChannel stubChannel = new HmChannel("stubChannel", 0);
    stubChannel.setDevice(new HmDevice("LEQ123456", HmInterface.RF, "HM-STUB-DEVICE", "", "", ""));
    floatDp.setChannel(stubChannel);
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) Before(org.junit.Before)

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