change homematic to autodetect only

This commit is contained in:
Pascal Vizeli 2016-06-28 22:53:53 +02:00
parent 00179763ef
commit baa9bdf6fc
7 changed files with 49 additions and 182 deletions

View File

@ -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: "<Homematic address for device>" # e.g. "JEQ0XXXXXXX"
name: "<User defined name>" (optional)
Configuration (multiple channels, like motion detector with buttons):
binary_sensor:
- platform: homematic
address: "<Homematic address for device>" # e.g. "JEQ0XXXXXXX"
param: <MOTION|PRESS_SHORT...> (device-dependent) (optional)
button: n (integer of channel to map, device-dependent) (optional)
name: "<User defined 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,

View File

@ -11,7 +11,6 @@ homematic:
local_port: <Port for connection with Home Assistant>
remote_ip: "<IP of Homegear / CCU>"
remote_port: <Port of Homegear / CCU XML-RPC Server>
autodetect: "<True/False>" (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."""

View File

@ -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: <Homematic addresss for device> # e.g. "JEQ0XXXXXXX"
name: <User defined 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):

View File

@ -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: "<Homematic address for device>" # e.g. "JEQ0XXXXXXX"
name: "<User defined 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):

View File

@ -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: <Homematic address for device> # e.g. "JEQ0XXXXXXX"
name: <User defined name> (optional)
param: <Name of datapoint to us as sensor> (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):

View File

@ -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: <Homematic address for device> # e.g. "JEQ0XXXXXXX"
name: <User defined 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):

View File

@ -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: "<Homematic address for device>" # e.g. "JEQ0XXXXXXX"
name: "<User defined 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