From 526abdd329fbe3945fd8e269f9102c3297e5d67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Fri, 5 May 2017 08:50:53 +0200 Subject: [PATCH] Add hass to rfxtrx object (#6844) --- homeassistant/components/cover/rfxtrx.py | 4 ++-- homeassistant/components/light/rfxtrx.py | 4 ++-- homeassistant/components/rfxtrx.py | 6 ++++-- homeassistant/components/switch/rfxtrx.py | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/cover/rfxtrx.py b/homeassistant/components/cover/rfxtrx.py index 0e28d3ef701..f599ea3ede1 100644 --- a/homeassistant/components/cover/rfxtrx.py +++ b/homeassistant/components/cover/rfxtrx.py @@ -16,7 +16,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Set up the RFXtrx cover.""" import RFXtrx as rfxtrxmod - covers = rfxtrx.get_devices_from_config(config, RfxtrxCover) + covers = rfxtrx.get_devices_from_config(config, RfxtrxCover, hass) add_devices_callback(covers) def cover_update(event): @@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): not event.device.known_to_be_rollershutter: return - new_device = rfxtrx.get_new_device(event, config, RfxtrxCover) + new_device = rfxtrx.get_new_device(event, config, RfxtrxCover, hass) if new_device: add_devices_callback([new_device]) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index 9248b0131f1..f831d6c04ce 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -23,7 +23,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the RFXtrx platform.""" import RFXtrx as rfxtrxmod - lights = rfxtrx.get_devices_from_config(config, RfxtrxLight) + lights = rfxtrx.get_devices_from_config(config, RfxtrxLight, hass) add_devices(lights) def light_update(event): @@ -32,7 +32,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): not event.device.known_to_be_dimmable: return - new_device = rfxtrx.get_new_device(event, config, RfxtrxLight) + new_device = rfxtrx.get_new_device(event, config, RfxtrxLight, hass) if new_device: add_devices([new_device]) diff --git a/homeassistant/components/rfxtrx.py b/homeassistant/components/rfxtrx.py index b7f016d1029..3c3f1e00f68 100644 --- a/homeassistant/components/rfxtrx.py +++ b/homeassistant/components/rfxtrx.py @@ -191,7 +191,7 @@ def get_rfx_object(packetid): return obj -def get_devices_from_config(config, device): +def get_devices_from_config(config, device, hass): """Read rfxtrx configuration.""" signal_repetitions = config[CONF_SIGNAL_REPETITIONS] @@ -209,12 +209,13 @@ def get_devices_from_config(config, device): new_device = device(entity_info[ATTR_NAME], event, datas, signal_repetitions) + new_device.hass = hass RFX_DEVICES[device_id] = new_device devices.append(new_device) return devices -def get_new_device(event, config, device): +def get_new_device(event, config, device, hass): """Add entity if not exist and the automatic_add is True.""" device_id = slugify(event.device.id_string.lower()) if device_id in RFX_DEVICES: @@ -235,6 +236,7 @@ def get_new_device(event, config, device): signal_repetitions = config[CONF_SIGNAL_REPETITIONS] new_device = device(pkt_id, event, datas, signal_repetitions) + new_device.hass = hass RFX_DEVICES[device_id] = new_device return new_device diff --git a/homeassistant/components/switch/rfxtrx.py b/homeassistant/components/switch/rfxtrx.py index 1361d22de18..36044f5f168 100644 --- a/homeassistant/components/switch/rfxtrx.py +++ b/homeassistant/components/switch/rfxtrx.py @@ -21,7 +21,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): import RFXtrx as rfxtrxmod # Add switch from config file - switches = rfxtrx.get_devices_from_config(config, RfxtrxSwitch) + switches = rfxtrx.get_devices_from_config(config, RfxtrxSwitch, hass) add_devices_callback(switches) def switch_update(event): @@ -31,7 +31,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): event.device.known_to_be_rollershutter: return - new_device = rfxtrx.get_new_device(event, config, RfxtrxSwitch) + new_device = rfxtrx.get_new_device(event, config, RfxtrxSwitch, hass) if new_device: add_devices_callback([new_device])