From baa9bdf6fc75769aa45ce46ae175b989264a020f Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 28 Jun 2016 22:53:53 +0200 Subject: [PATCH] change homematic to autodetect only --- .../components/binary_sensor/homematic.py | 58 +++-------------- homeassistant/components/homematic.py | 65 +++---------------- homeassistant/components/light/homematic.py | 22 ++----- .../components/rollershutter/homematic.py | 21 ++---- homeassistant/components/sensor/homematic.py | 22 ++----- homeassistant/components/switch/homematic.py | 22 ++----- .../components/thermostat/homematic.py | 21 ++---- 7 files changed, 49 insertions(+), 182 deletions(-) diff --git a/homeassistant/components/binary_sensor/homematic.py b/homeassistant/components/binary_sensor/homematic.py index 08ea2099445..5452229ee54 100644 --- a/homeassistant/components/binary_sensor/homematic.py +++ b/homeassistant/components/binary_sensor/homematic.py @@ -6,26 +6,6 @@ https://home-assistant.io/components/binary_sensor.homematic/ Important: For this platform to work the homematic component has to be properly configured. - -Configuration (single channel, simple device): - -binary_sensor: - - platform: homematic - address: "" # e.g. "JEQ0XXXXXXX" - name: "" (optional) - - -Configuration (multiple channels, like motion detector with buttons): - -binary_sensor: - - platform: homematic - address: "" # e.g. "JEQ0XXXXXXX" - param: (device-dependent) (optional) - button: n (integer of channel to map, device-dependent) (optional) - name: "" (optional) -binary_sensor: - - platform: homematic - ... """ import logging @@ -55,14 +35,12 @@ SUPPORT_HM_EVENT_AS_BINMOD = [ def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" - if discovery_info: - return homematic.setup_hmdevice_discovery_helper(HMBinarySensor, - discovery_info, - add_callback_devices) - # Manual - return homematic.setup_hmdevice_entity_helper(HMBinarySensor, - config, - add_callback_devices) + if discovery_info is None: + return + + return homematic.setup_hmdevice_discovery_helper(HMBinarySensor, + discovery_info, + add_callback_devices) class HMBinarySensor(homematic.HMDevice, BinarySensorDevice): @@ -73,18 +51,6 @@ class HMBinarySensor(homematic.HMDevice, BinarySensorDevice): """Return True if switch is on.""" if not self.available: return False - # no binary is defined, check all! - if self._state is None: - available_bin = self._create_binary_list_from_hm() - for binary in available_bin: - try: - if binary in self._data and self._data[binary] == 1: - return True - except (ValueError, TypeError): - _LOGGER.warning("%s datatype error!", self._name) - return False - - # single binary return bool(self._hm_get_state()) @property @@ -123,9 +89,10 @@ class HMBinarySensor(homematic.HMDevice, BinarySensorDevice): # only check and give a warining to User if self._state is None and len(available_bin) > 1: - _LOGGER.warning("%s have multible binary params. It use all " + - "binary nodes as one. Possible param values: %s", - self._name, str(available_bin)) + _LOGGER.critical("%s have multible binary params. It use all " + + "binary nodes as one. Possible param values: %s", + self._name, str(available_bin)) + return False return True @@ -141,11 +108,6 @@ class HMBinarySensor(homematic.HMDevice, BinarySensorDevice): for value in available_bin: self._state = value - # no binary is definit, use all binary for state - if self._state is None and len(available_bin) > 1: - for node in available_bin: - self._data.update({node: STATE_UNKNOWN}) - # add state to data struct if self._state: _LOGGER.debug("%s init datastruct with main node '%s'", self._name, diff --git a/homeassistant/components/homematic.py b/homeassistant/components/homematic.py index 7b3e265a9dd..a0a31566661 100644 --- a/homeassistant/components/homematic.py +++ b/homeassistant/components/homematic.py @@ -11,7 +11,6 @@ homematic: local_port: remote_ip: "" remote_port: - autodetect: "" (optional, experimental, detect all devices) """ import time import logging @@ -119,22 +118,9 @@ def system_callback_handler(hass, config, src, *args): for dev in dev_descriptions: key_dict[dev['ADDRESS'].split(':')[0]] = True - # Connect devices already created in HA to pyhomematic and - # add remaining devices to list - devices_not_created = [] - for dev in key_dict: - if dev in HOMEMATIC_DEVICES: - for hm_element in HOMEMATIC_DEVICES[dev]: - hm_element.link_homematic() - else: - devices_not_created.append(dev) - # If configuration allows autodetection of devices, # all devices not configured are added. - autodetect = config[DOMAIN].get("autodetect", False) - _LOGGER.debug("Autodetect is %s / unknown device: %s", str(autodetect), - str(devices_not_created)) - if autodetect and devices_not_created: + if key_dict: for component_name, discovery_type in ( ('switch', DISCOVER_SWITCHES), ('light', DISCOVER_LIGHTS), @@ -143,8 +129,7 @@ def system_callback_handler(hass, config, src, *args): ('sensor', DISCOVER_SENSORS), ('thermostat', DISCOVER_THERMOSTATS)): # Get all devices of a specific type - found_devices = _get_devices(discovery_type, - devices_not_created) + found_devices = _get_devices(discovery_type, key_dict) # When devices of this type are found # they are setup in HA and an event is fired @@ -162,8 +147,6 @@ def _get_devices(device_type, keys): # run device_arr = [] - if not keys: - keys = HOMEMATIC.devices for key in keys: device = HOMEMATIC.devices[key] if device.__class__.__name__ not in HM_DEVICE_TYPES[device_type]: @@ -265,40 +248,16 @@ def setup_hmdevice_discovery_helper(hmdevicetype, discovery_info, add_callback_devices): """Helper to setup Homematic devices with discovery info.""" for config in discovery_info["devices"]: - ret = setup_hmdevice_entity_helper(hmdevicetype, config, - add_callback_devices) - if not ret: - _LOGGER.error("Setup discovery error with config %s", str(config)) + _LOGGER.debug("Add device %s from config: %s", + str(hmdevicetype), str(config)) - return True + # create object and add to HA + new_device = hmdevicetype(config) + add_callback_devices([new_device]) + # link to HM + new_device.link_homematic() -def setup_hmdevice_entity_helper(hmdevicetype, config, add_callback_devices): - """Helper to setup Homematic devices.""" - if HOMEMATIC is None: - _LOGGER.error('Error setting up HMDevice: Server not configured.') - return False - - address = config.get('address', None) - if address is None: - _LOGGER.error("Error setting up device '%s': " + - "'address' missing in configuration.", address) - return False - - _LOGGER.debug("Add device %s from config: %s", - str(hmdevicetype), str(config)) - # Create a new HA homematic object - new_device = hmdevicetype(config) - if address not in HOMEMATIC_DEVICES: - HOMEMATIC_DEVICES[address] = [] - HOMEMATIC_DEVICES[address].append(new_device) - - # Add to HA - add_callback_devices([new_device]) - - # HM is connected - if address in HOMEMATIC.devices: - return new_device.link_homematic() return True @@ -312,7 +271,6 @@ class HMDevice(Entity): self._address = config.get("address", None) self._channel = config.get("button", 1) self._state = config.get("param", None) - self._hidden = config.get("hidden", False) self._data = {} self._hmdevice = None self._connected = False @@ -348,11 +306,6 @@ class HMDevice(Entity): """Return True if device is available.""" return self._available - @property - def hidden(self): - """Return True if the entity should be hidden from UIs.""" - return self._hidden - @property def device_state_attributes(self): """Return device specific state attributes.""" diff --git a/homeassistant/components/light/homematic.py b/homeassistant/components/light/homematic.py index 159f3e4dbdc..b1f08db0783 100644 --- a/homeassistant/components/light/homematic.py +++ b/homeassistant/components/light/homematic.py @@ -6,14 +6,6 @@ https://home-assistant.io/components/light.homematic/ Important: For this platform to work the homematic component has to be properly configured. - -Configuration: - -light: - - platform: homematic - addresss: # e.g. "JEQ0XXXXXXX" - name: (optional) - button: n (integer of channel to map, device-dependent) """ import logging @@ -29,14 +21,12 @@ DEPENDENCIES = ['homematic'] def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" - if discovery_info: - return homematic.setup_hmdevice_discovery_helper(HMLight, - discovery_info, - add_callback_devices) - # Manual - return homematic.setup_hmdevice_entity_helper(HMLight, - config, - add_callback_devices) + if discovery_info is None: + return + + return homematic.setup_hmdevice_discovery_helper(HMLight, + discovery_info, + add_callback_devices) class HMLight(homematic.HMDevice, Light): diff --git a/homeassistant/components/rollershutter/homematic.py b/homeassistant/components/rollershutter/homematic.py index 737a7eb017d..9bdad7ee68c 100644 --- a/homeassistant/components/rollershutter/homematic.py +++ b/homeassistant/components/rollershutter/homematic.py @@ -6,13 +6,6 @@ https://home-assistant.io/components/rollershutter.homematic/ Important: For this platform to work the homematic component has to be properly configured. - -Configuration: - -rollershutter: - - platform: homematic - address: "" # e.g. "JEQ0XXXXXXX" - name: "" (optional) """ import logging @@ -29,14 +22,12 @@ DEPENDENCIES = ['homematic'] def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" - if discovery_info: - return homematic.setup_hmdevice_discovery_helper(HMRollershutter, - discovery_info, - add_callback_devices) - # Manual - return homematic.setup_hmdevice_entity_helper(HMRollershutter, - config, - add_callback_devices) + if discovery_info is None: + return + + return homematic.setup_hmdevice_discovery_helper(HMRollershutter, + discovery_info, + add_callback_devices) class HMRollershutter(homematic.HMDevice, RollershutterDevice): diff --git a/homeassistant/components/sensor/homematic.py b/homeassistant/components/sensor/homematic.py index f6f3825199b..2efa4fdef38 100644 --- a/homeassistant/components/sensor/homematic.py +++ b/homeassistant/components/sensor/homematic.py @@ -6,14 +6,6 @@ https://home-assistant.io/components/sensor.homematic/ Important: For this platform to work the homematic component has to be properly configured. - -Configuration: - -sensor: - - platform: homematic - address: # e.g. "JEQ0XXXXXXX" - name: (optional) - param: (optional) """ import logging @@ -41,14 +33,12 @@ HM_UNIT_HA_CAST = { def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" - if discovery_info: - return homematic.setup_hmdevice_discovery_helper(HMSensor, - discovery_info, - add_callback_devices) - # Manual - return homematic.setup_hmdevice_entity_helper(HMSensor, - config, - add_callback_devices) + if discovery_info is None: + return + + return homematic.setup_hmdevice_discovery_helper(HMSensor, + discovery_info, + add_callback_devices) class HMSensor(homematic.HMDevice): diff --git a/homeassistant/components/switch/homematic.py b/homeassistant/components/switch/homematic.py index 16cc63a6708..3e6a83afcc4 100644 --- a/homeassistant/components/switch/homematic.py +++ b/homeassistant/components/switch/homematic.py @@ -6,14 +6,6 @@ https://home-assistant.io/components/switch.homematic/ Important: For this platform to work the homematic component has to be properly configured. - -Configuration: - -switch: - - platform: homematic - address: # e.g. "JEQ0XXXXXXX" - name: (optional) - button: n (integer of channel to map, device-dependent) (optional) """ import logging @@ -28,14 +20,12 @@ DEPENDENCIES = ['homematic'] def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" - if discovery_info: - return homematic.setup_hmdevice_discovery_helper(HMSwitch, - discovery_info, - add_callback_devices) - # Manual - return homematic.setup_hmdevice_entity_helper(HMSwitch, - config, - add_callback_devices) + if discovery_info is None: + return + + return homematic.setup_hmdevice_discovery_helper(HMSwitch, + discovery_info, + add_callback_devices) class HMSwitch(homematic.HMDevice, SwitchDevice): diff --git a/homeassistant/components/thermostat/homematic.py b/homeassistant/components/thermostat/homematic.py index d7675a5cd47..3a537792522 100644 --- a/homeassistant/components/thermostat/homematic.py +++ b/homeassistant/components/thermostat/homematic.py @@ -6,13 +6,6 @@ https://home-assistant.io/components/thermostat.homematic/ Important: For this platform to work the homematic component has to be properly configured. - -Configuration: - -thermostat: - - platform: homematic - address: "" # e.g. "JEQ0XXXXXXX" - name: "" (optional) """ import logging @@ -28,14 +21,12 @@ _LOGGER = logging.getLogger(__name__) def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" - if discovery_info: - return homematic.setup_hmdevice_discovery_helper(HMThermostat, - discovery_info, - add_callback_devices) - # Manual - return homematic.setup_hmdevice_entity_helper(HMThermostat, - config, - add_callback_devices) + if discovery_info is None: + return + + return homematic.setup_hmdevice_discovery_helper(HMThermostat, + discovery_info, + add_callback_devices) # pylint: disable=abstract-method