Bugfix RFLINK remove group (#6580)
* Bugfix RFLINK remove group * Remove group hack from lutron too * fix tests * fix lint * fix lint
This commit is contained in:
parent
e265401cd0
commit
774fd19638
7 changed files with 13 additions and 138 deletions
|
@ -2,9 +2,9 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, DOMAIN, SUPPORT_BRIGHTNESS, Light)
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||||
from homeassistant.components.lutron import (
|
from homeassistant.components.lutron import (
|
||||||
LutronDevice, LUTRON_DEVICES, LUTRON_GROUPS, LUTRON_CONTROLLER)
|
LutronDevice, LUTRON_DEVICES, LUTRON_CONTROLLER)
|
||||||
|
|
||||||
DEPENDENCIES = ['lutron']
|
DEPENDENCIES = ['lutron']
|
||||||
|
|
||||||
|
@ -21,15 +21,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
hass.data[LUTRON_CONTROLLER])
|
hass.data[LUTRON_CONTROLLER])
|
||||||
area_devs.setdefault(area_name, []).append(dev)
|
area_devs.setdefault(area_name, []).append(dev)
|
||||||
devs.append(dev)
|
devs.append(dev)
|
||||||
|
|
||||||
add_devices(devs, True)
|
add_devices(devs, True)
|
||||||
|
|
||||||
for area in area_devs:
|
|
||||||
if area not in hass.data[LUTRON_GROUPS]:
|
|
||||||
continue
|
|
||||||
grp = hass.data[LUTRON_GROUPS][area]
|
|
||||||
ids = list(grp.tracking) + [dev.entity_id for dev in area_devs[area]]
|
|
||||||
grp.update_tracked_entity_ids(ids)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,8 +42,7 @@ class LutronLight(LutronDevice, Light):
|
||||||
def __init__(self, hass, area_name, lutron_device, controller):
|
def __init__(self, hass, area_name, lutron_device, controller):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self._prev_brightness = None
|
self._prev_brightness = None
|
||||||
LutronDevice.__init__(self, hass, DOMAIN, area_name, lutron_device,
|
LutronDevice.__init__(self, hass, area_name, lutron_device, controller)
|
||||||
controller)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
|
|
|
@ -7,13 +7,12 @@ https://home-assistant.io/components/light.rflink/
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components import group
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||||
from homeassistant.components.rflink import (
|
from homeassistant.components.rflink import (
|
||||||
CONF_ALIASSES, CONF_DEVICE_DEFAULTS, CONF_DEVICES, CONF_FIRE_EVENT,
|
CONF_ALIASSES, CONF_DEVICE_DEFAULTS, CONF_DEVICES, CONF_FIRE_EVENT,
|
||||||
CONF_IGNORE_DEVICES, CONF_NEW_DEVICES_GROUP, CONF_SIGNAL_REPETITIONS,
|
CONF_IGNORE_DEVICES, CONF_SIGNAL_REPETITIONS, DATA_DEVICE_REGISTER,
|
||||||
DATA_DEVICE_REGISTER, DATA_ENTITY_LOOKUP, DEVICE_DEFAULTS_SCHEMA, DOMAIN,
|
DATA_ENTITY_LOOKUP, DEVICE_DEFAULTS_SCHEMA, DOMAIN,
|
||||||
EVENT_KEY_COMMAND, EVENT_KEY_ID, SwitchableRflinkDevice, cv, vol)
|
EVENT_KEY_COMMAND, EVENT_KEY_ID, SwitchableRflinkDevice, cv, vol)
|
||||||
from homeassistant.const import CONF_NAME, CONF_PLATFORM, CONF_TYPE
|
from homeassistant.const import CONF_NAME, CONF_PLATFORM, CONF_TYPE
|
||||||
|
|
||||||
|
@ -27,7 +26,6 @@ TYPE_HYBRID = 'hybrid'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = vol.Schema({
|
PLATFORM_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_PLATFORM): DOMAIN,
|
vol.Required(CONF_PLATFORM): DOMAIN,
|
||||||
vol.Optional(CONF_NEW_DEVICES_GROUP, default=None): cv.string,
|
|
||||||
vol.Optional(CONF_IGNORE_DEVICES): vol.All(cv.ensure_list, [cv.string]),
|
vol.Optional(CONF_IGNORE_DEVICES): vol.All(cv.ensure_list, [cv.string]),
|
||||||
vol.Optional(CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({})):
|
vol.Optional(CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({})):
|
||||||
DEVICE_DEFAULTS_SCHEMA,
|
DEVICE_DEFAULTS_SCHEMA,
|
||||||
|
@ -119,13 +117,6 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
"""Set up the Rflink light platform."""
|
"""Set up the Rflink light platform."""
|
||||||
async_add_devices(devices_from_config(config, hass))
|
async_add_devices(devices_from_config(config, hass))
|
||||||
|
|
||||||
# Add new (unconfigured) devices to user desired group
|
|
||||||
if config[CONF_NEW_DEVICES_GROUP]:
|
|
||||||
new_devices_group = yield from group.Group.async_create_group(
|
|
||||||
hass, config[CONF_NEW_DEVICES_GROUP], [], True)
|
|
||||||
else:
|
|
||||||
new_devices_group = None
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def add_new_device(event):
|
def add_new_device(event):
|
||||||
"""Check if device is known, otherwise add to list of known devices."""
|
"""Check if device is known, otherwise add to list of known devices."""
|
||||||
|
@ -145,21 +136,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
# Make sure the event is processed by the new entity
|
# Make sure the event is processed by the new entity
|
||||||
device.handle_event(event)
|
device.handle_event(event)
|
||||||
|
|
||||||
# Maybe add to new devices group
|
|
||||||
if new_devices_group:
|
|
||||||
yield from new_devices_group.async_update_tracked_entity_ids(
|
|
||||||
list(new_devices_group.tracking) + [device.entity_id])
|
|
||||||
|
|
||||||
hass.data[DATA_DEVICE_REGISTER][EVENT_KEY_COMMAND] = add_new_device
|
hass.data[DATA_DEVICE_REGISTER][EVENT_KEY_COMMAND] = add_new_device
|
||||||
|
|
||||||
|
|
||||||
class RflinkLight(SwitchableRflinkDevice, Light):
|
class RflinkLight(SwitchableRflinkDevice, Light):
|
||||||
"""Representation of a Rflink light."""
|
"""Representation of a Rflink light."""
|
||||||
|
|
||||||
@property
|
pass
|
||||||
def entity_id(self):
|
|
||||||
"""Return entity id."""
|
|
||||||
return "light.{}".format(self.name)
|
|
||||||
|
|
||||||
|
|
||||||
class DimmableRflinkLight(SwitchableRflinkDevice, Light):
|
class DimmableRflinkLight(SwitchableRflinkDevice, Light):
|
||||||
|
@ -167,11 +150,6 @@ class DimmableRflinkLight(SwitchableRflinkDevice, Light):
|
||||||
|
|
||||||
_brightness = 255
|
_brightness = 255
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_id(self):
|
|
||||||
"""Return entity id."""
|
|
||||||
return "light.{}".format(self.name)
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_turn_on(self, **kwargs):
|
def async_turn_on(self, **kwargs):
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
|
@ -210,11 +188,6 @@ class HybridRflinkLight(SwitchableRflinkDevice, Light):
|
||||||
|
|
||||||
_brightness = 255
|
_brightness = 255
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_id(self):
|
|
||||||
"""Return entity id."""
|
|
||||||
return "light.{}".format(self.name)
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_turn_on(self, **kwargs):
|
def async_turn_on(self, **kwargs):
|
||||||
"""Turn the device on and set dim level."""
|
"""Turn the device on and set dim level."""
|
||||||
|
|
|
@ -7,8 +7,7 @@ https://home-assistant.io/components/lutron/
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.helpers.entity import (Entity, generate_entity_id)
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.loader import get_component
|
|
||||||
|
|
||||||
REQUIREMENTS = ['https://github.com/thecynic/pylutron/archive/v0.1.0.zip#'
|
REQUIREMENTS = ['https://github.com/thecynic/pylutron/archive/v0.1.0.zip#'
|
||||||
'pylutron==0.1.0']
|
'pylutron==0.1.0']
|
||||||
|
@ -19,7 +18,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
LUTRON_CONTROLLER = 'lutron_controller'
|
LUTRON_CONTROLLER = 'lutron_controller'
|
||||||
LUTRON_DEVICES = 'lutron_devices'
|
LUTRON_DEVICES = 'lutron_devices'
|
||||||
LUTRON_GROUPS = 'lutron_groups'
|
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, base_config):
|
def setup(hass, base_config):
|
||||||
|
@ -28,7 +26,6 @@ def setup(hass, base_config):
|
||||||
|
|
||||||
hass.data[LUTRON_CONTROLLER] = None
|
hass.data[LUTRON_CONTROLLER] = None
|
||||||
hass.data[LUTRON_DEVICES] = {'light': []}
|
hass.data[LUTRON_DEVICES] = {'light': []}
|
||||||
hass.data[LUTRON_GROUPS] = {}
|
|
||||||
|
|
||||||
config = base_config.get(DOMAIN)
|
config = base_config.get(DOMAIN)
|
||||||
hass.data[LUTRON_CONTROLLER] = Lutron(
|
hass.data[LUTRON_CONTROLLER] = Lutron(
|
||||||
|
@ -40,13 +37,8 @@ def setup(hass, base_config):
|
||||||
hass.data[LUTRON_CONTROLLER].connect()
|
hass.data[LUTRON_CONTROLLER].connect()
|
||||||
_LOGGER.info("Connected to Main Repeater at %s", config['lutron_host'])
|
_LOGGER.info("Connected to Main Repeater at %s", config['lutron_host'])
|
||||||
|
|
||||||
group = get_component('group')
|
|
||||||
|
|
||||||
# Sort our devices into types
|
# Sort our devices into types
|
||||||
for area in hass.data[LUTRON_CONTROLLER].areas:
|
for area in hass.data[LUTRON_CONTROLLER].areas:
|
||||||
if area.name not in hass.data[LUTRON_GROUPS]:
|
|
||||||
grp = group.Group.create_group(hass, area.name, [])
|
|
||||||
hass.data[LUTRON_GROUPS][area.name] = grp
|
|
||||||
for output in area.outputs:
|
for output in area.outputs:
|
||||||
hass.data[LUTRON_DEVICES]['light'].append((area.name, output))
|
hass.data[LUTRON_DEVICES]['light'].append((area.name, output))
|
||||||
|
|
||||||
|
@ -58,16 +50,14 @@ def setup(hass, base_config):
|
||||||
class LutronDevice(Entity):
|
class LutronDevice(Entity):
|
||||||
"""Representation of a Lutron device entity."""
|
"""Representation of a Lutron device entity."""
|
||||||
|
|
||||||
def __init__(self, hass, domain, area_name, lutron_device, controller):
|
def __init__(self, hass, area_name, lutron_device, controller):
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
self._lutron_device = lutron_device
|
self._lutron_device = lutron_device
|
||||||
self._controller = controller
|
self._controller = controller
|
||||||
self._area_name = area_name
|
self._area_name = area_name
|
||||||
|
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
object_id = '{} {}'.format(area_name, lutron_device.name)
|
self.object_id = '{} {}'.format(area_name, lutron_device.name)
|
||||||
self.entity_id = generate_entity_id(domain + '.{}', object_id,
|
|
||||||
hass=hass)
|
|
||||||
|
|
||||||
self._controller.subscribe(self._lutron_device, self._update_callback)
|
self._controller.subscribe(self._lutron_device, self._update_callback)
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ CONF_DEVICE_DEFAULTS = 'device_defaults'
|
||||||
CONF_DEVICES = 'devices'
|
CONF_DEVICES = 'devices'
|
||||||
CONF_FIRE_EVENT = 'fire_event'
|
CONF_FIRE_EVENT = 'fire_event'
|
||||||
CONF_IGNORE_DEVICES = 'ignore_devices'
|
CONF_IGNORE_DEVICES = 'ignore_devices'
|
||||||
CONF_NEW_DEVICES_GROUP = 'new_devices_group'
|
|
||||||
CONF_RECONNECT_INTERVAL = 'reconnect_interval'
|
CONF_RECONNECT_INTERVAL = 'reconnect_interval'
|
||||||
CONF_SIGNAL_REPETITIONS = 'signal_repetitions'
|
CONF_SIGNAL_REPETITIONS = 'signal_repetitions'
|
||||||
CONF_WAIT_FOR_ACK = 'wait_for_ack'
|
CONF_WAIT_FOR_ACK = 'wait_for_ack'
|
||||||
|
|
|
@ -8,11 +8,10 @@ import asyncio
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components import group
|
|
||||||
from homeassistant.components.rflink import (
|
from homeassistant.components.rflink import (
|
||||||
CONF_ALIASSES, CONF_DEVICES, CONF_NEW_DEVICES_GROUP, DATA_DEVICE_REGISTER,
|
CONF_ALIASSES, CONF_DEVICES, DATA_DEVICE_REGISTER, DATA_ENTITY_LOOKUP,
|
||||||
DATA_ENTITY_LOOKUP, DOMAIN, EVENT_KEY_ID, EVENT_KEY_SENSOR, EVENT_KEY_UNIT,
|
DOMAIN, EVENT_KEY_ID, EVENT_KEY_SENSOR, EVENT_KEY_UNIT, RflinkDevice,
|
||||||
RflinkDevice, cv, vol)
|
cv, vol)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT, CONF_NAME, CONF_PLATFORM,
|
ATTR_UNIT_OF_MEASUREMENT, CONF_NAME, CONF_PLATFORM,
|
||||||
CONF_UNIT_OF_MEASUREMENT)
|
CONF_UNIT_OF_MEASUREMENT)
|
||||||
|
@ -31,7 +30,6 @@ CONF_SENSOR_TYPE = 'sensor_type'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = vol.Schema({
|
PLATFORM_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_PLATFORM): DOMAIN,
|
vol.Required(CONF_PLATFORM): DOMAIN,
|
||||||
vol.Optional(CONF_NEW_DEVICES_GROUP, default=None): cv.string,
|
|
||||||
vol.Optional(CONF_DEVICES, default={}): vol.Schema({
|
vol.Optional(CONF_DEVICES, default={}): vol.Schema({
|
||||||
cv.string: {
|
cv.string: {
|
||||||
vol.Optional(CONF_NAME): cv.string,
|
vol.Optional(CONF_NAME): cv.string,
|
||||||
|
@ -76,13 +74,6 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
"""Set up the Rflink platform."""
|
"""Set up the Rflink platform."""
|
||||||
async_add_devices(devices_from_config(config, hass))
|
async_add_devices(devices_from_config(config, hass))
|
||||||
|
|
||||||
# Add new (unconfigured) devices to user desired group
|
|
||||||
if config[CONF_NEW_DEVICES_GROUP]:
|
|
||||||
new_devices_group = yield from group.Group.async_create_group(
|
|
||||||
hass, config[CONF_NEW_DEVICES_GROUP], [], True)
|
|
||||||
else:
|
|
||||||
new_devices_group = None
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def add_new_device(event):
|
def add_new_device(event):
|
||||||
"""Check if device is known, otherwise create device entity."""
|
"""Check if device is known, otherwise create device entity."""
|
||||||
|
@ -100,11 +91,6 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
# Make sure the event is processed by the new entity
|
# Make sure the event is processed by the new entity
|
||||||
device.handle_event(event)
|
device.handle_event(event)
|
||||||
|
|
||||||
# Maybe add to new devices group
|
|
||||||
if new_devices_group:
|
|
||||||
yield from new_devices_group.async_update_tracked_entity_ids(
|
|
||||||
list(new_devices_group.tracking) + [device.entity_id])
|
|
||||||
|
|
||||||
hass.data[DATA_DEVICE_REGISTER][EVENT_KEY_SENSOR] = add_new_device
|
hass.data[DATA_DEVICE_REGISTER][EVENT_KEY_SENSOR] = add_new_device
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,11 +108,6 @@ class RflinkSensor(RflinkDevice):
|
||||||
"""Domain specific event handler."""
|
"""Domain specific event handler."""
|
||||||
self._state = event['value']
|
self._state = event['value']
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_id(self):
|
|
||||||
"""Return entity id."""
|
|
||||||
return "sensor.{}".format(self.name)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return measurement unit."""
|
"""Return measurement unit."""
|
||||||
|
|
|
@ -154,35 +154,6 @@ def test_default_setup(hass, monkeypatch):
|
||||||
assert protocol.send_command_ack.call_args_list[5][0][1] == '7'
|
assert protocol.send_command_ack.call_args_list[5][0][1] == '7'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_new_light_group(hass, monkeypatch):
|
|
||||||
"""New devices should be added to configured group."""
|
|
||||||
config = {
|
|
||||||
'rflink': {
|
|
||||||
'port': '/dev/ttyABC0',
|
|
||||||
},
|
|
||||||
DOMAIN: {
|
|
||||||
'platform': 'rflink',
|
|
||||||
'new_devices_group': 'new_rflink_lights',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
# setup mocking rflink module
|
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
|
||||||
hass, config, DOMAIN, monkeypatch)
|
|
||||||
|
|
||||||
# test event for new unconfigured sensor
|
|
||||||
event_callback({
|
|
||||||
'id': 'protocol_0_0',
|
|
||||||
'command': 'off',
|
|
||||||
})
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
# make sure new device is added to correct group
|
|
||||||
group = hass.states.get('group.new_rflink_lights')
|
|
||||||
assert group.attributes.get('entity_id') == ('light.protocol_0_0',)
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_firing_bus_event(hass, monkeypatch):
|
def test_firing_bus_event(hass, monkeypatch):
|
||||||
"""Incoming Rflink command events should be put on the HA event bus."""
|
"""Incoming Rflink command events should be put on the HA event bus."""
|
||||||
|
|
|
@ -70,34 +70,3 @@ def test_default_setup(hass, monkeypatch):
|
||||||
assert new_sensor.state == '0'
|
assert new_sensor.state == '0'
|
||||||
assert new_sensor.attributes['unit_of_measurement'] == '°C'
|
assert new_sensor.attributes['unit_of_measurement'] == '°C'
|
||||||
assert new_sensor.attributes['icon'] == 'mdi:thermometer'
|
assert new_sensor.attributes['icon'] == 'mdi:thermometer'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_new_sensors_group(hass, monkeypatch):
|
|
||||||
"""New devices should be added to configured group."""
|
|
||||||
config = {
|
|
||||||
'rflink': {
|
|
||||||
'port': '/dev/ttyABC0',
|
|
||||||
},
|
|
||||||
DOMAIN: {
|
|
||||||
'platform': 'rflink',
|
|
||||||
'new_devices_group': 'new_rflink_sensors',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
# setup mocking rflink module
|
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
|
||||||
hass, config, DOMAIN, monkeypatch)
|
|
||||||
|
|
||||||
# test event for new unconfigured sensor
|
|
||||||
event_callback({
|
|
||||||
'id': 'test',
|
|
||||||
'sensor': 'temperature',
|
|
||||||
'value': 0,
|
|
||||||
'unit': '°C',
|
|
||||||
})
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
# make sure new device is added to correct group
|
|
||||||
group = hass.states.get('group.new_rflink_sensors')
|
|
||||||
assert group.attributes.get('entity_id') == ('sensor.test',)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue