Migrate to generic discovery method (#2271)
* Migrate to generic discovery method * Add tests for discovery
This commit is contained in:
1 parent
c9756c40e2
commit
30f74bb3ca
32 files changed
+322
-540
No files matched your search
@@ -5,16 +5,13 @@ For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/vera/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
from homeassistant import bootstrap
|
||||
from homeassistant.const import (
|
||||
ATTR_SERVICE, ATTR_DISCOVERED,
|
||||
EVENT_HOMEASSISTANT_STOP, EVENT_PLATFORM_DISCOVERED)
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.loader import get_component
|
||||
|
||||
REQUIREMENTS = ['pyvera==0.2.10']
|
||||
|
||||
@@ -27,28 +24,18 @@ VERA_CONTROLLER = None
|
||||
CONF_EXCLUDE = 'exclude'
|
||||
CONF_LIGHTS = 'lights'
|
||||
|
||||
BINARY_SENSOR = 'binary_sensor'
|
||||
SENSOR = 'sensor'
|
||||
LIGHT = 'light'
|
||||
SWITCH = 'switch'
|
||||
|
||||
DEVICE_CATEGORIES = {
|
||||
'Sensor': BINARY_SENSOR,
|
||||
'Temperature Sensor': SENSOR,
|
||||
'Light Sensor': SENSOR,
|
||||
'Humidity Sensor': SENSOR,
|
||||
'Dimmable Switch': LIGHT,
|
||||
'Switch': SWITCH,
|
||||
'Armable Sensor': SWITCH,
|
||||
'On/Off Switch': SWITCH,
|
||||
'Sensor': 'binary_sensor',
|
||||
'Temperature Sensor': 'sensor',
|
||||
'Light Sensor': 'sensor',
|
||||
'Humidity Sensor': 'sensor',
|
||||
'Dimmable Switch': 'light',
|
||||
'Switch': 'switch',
|
||||
'Armable Sensor': 'switch',
|
||||
'On/Off Switch': 'switch',
|
||||
# 'Window Covering': NOT SUPPORTED YET
|
||||
}
|
||||
|
||||
DISCOVER_BINARY_SENSORS = 'vera.binary_sensors'
|
||||
DISCOVER_SENSORS = 'vera.sensors'
|
||||
DISCOVER_LIGHTS = 'vera.lights'
|
||||
DISCOVER_SWITCHES = 'vera.switchs'
|
||||
|
||||
VERA_DEVICES = defaultdict(list)
|
||||
|
||||
|
||||
@@ -100,19 +87,13 @@ def setup(hass, base_config):
|
||||
dev_type = DEVICE_CATEGORIES.get(device.category)
|
||||
if dev_type is None:
|
||||
continue
|
||||
if dev_type == SWITCH and device.device_id in lights_ids:
|
||||
dev_type = LIGHT
|
||||
if dev_type == 'switch' and device.device_id in lights_ids:
|
||||
dev_type = 'light'
|
||||
VERA_DEVICES[dev_type].append(device)
|
||||
|
||||
for comp_name, discovery in (((BINARY_SENSOR, DISCOVER_BINARY_SENSORS),
|
||||
(SENSOR, DISCOVER_SENSORS),
|
||||
(LIGHT, DISCOVER_LIGHTS),
|
||||
(SWITCH, DISCOVER_SWITCHES))):
|
||||
component = get_component(comp_name)
|
||||
bootstrap.setup_component(hass, component.DOMAIN, base_config)
|
||||
hass.bus.fire(EVENT_PLATFORM_DISCOVERED,
|
||||
{ATTR_SERVICE: discovery,
|
||||
ATTR_DISCOVERED: {}})
|
||||
for component in 'binary_sensor', 'sensor', 'light', 'switch':
|
||||
discovery.load_platform(hass, component, DOMAIN, None, base_config)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user