diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 9afc826e83c..90add8f012e 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -29,16 +29,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None): signal_repetitions = discovery_info.get(ATTR_DISCOVER_CONFIG, DEFAULT_SIGNAL_REPETITIONS) - add_devices(TellstickLight(tellcore_id, signal_repetitions) + add_devices(TellstickLight(tellcore_id, hass.data['tellcore_registry'], + signal_repetitions) for tellcore_id in discovery_info[ATTR_DISCOVER_DEVICES]) class TellstickLight(TellstickDevice, Light): """Representation of a Tellstick light.""" - def __init__(self, tellcore_id, signal_repetitions): + def __init__(self, tellcore_id, tellcore_registry, signal_repetitions): """Initialize the light.""" - super().__init__(tellcore_id, signal_repetitions) + super().__init__(tellcore_id, tellcore_registry, signal_repetitions) self._brightness = 255 diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index d3660ab36ca..46b1ad0aa49 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -26,7 +26,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): signal_repetitions = discovery_info.get(ATTR_DISCOVER_CONFIG, DEFAULT_SIGNAL_REPETITIONS) - add_devices(TellstickSwitch(tellcore_id, signal_repetitions) + add_devices(TellstickSwitch(tellcore_id, hass.data['tellcore_registry'], + signal_repetitions) for tellcore_id in discovery_info[ATTR_DISCOVER_DEVICES]) diff --git a/homeassistant/components/tellstick.py b/homeassistant/components/tellstick.py index cbd5ff20583..e957ef5e2a8 100644 --- a/homeassistant/components/tellstick.py +++ b/homeassistant/components/tellstick.py @@ -62,8 +62,6 @@ def setup(hass, config): from tellcore.library import DirectCallbackDispatcher from tellcore.telldus import TelldusCore - global TELLCORE_REGISTRY - try: tellcore_lib = TelldusCore( callback_dispatcher=DirectCallbackDispatcher()) @@ -75,8 +73,9 @@ def setup(hass, config): all_tellcore_devices = tellcore_lib.devices() # Register devices - TELLCORE_REGISTRY = TellstickRegistry(hass, tellcore_lib) - TELLCORE_REGISTRY.register_tellcore_devices(all_tellcore_devices) + tellcore_registry = TellstickRegistry(hass, tellcore_lib) + tellcore_registry.register_tellcore_devices(all_tellcore_devices) + hass.data['tellcore_registry'] = tellcore_registry # Discover the switches _discover(hass, config, 'switch', @@ -153,17 +152,17 @@ class TellstickDevice(Entity): Contains the common logic for all Tellstick devices. """ - def __init__(self, tellcore_id, signal_repetitions): + def __init__(self, tellcore_id, tellcore_registry, signal_repetitions): """Initalize the Tellstick device.""" self._signal_repetitions = signal_repetitions self._state = None # Look up our corresponding tellcore device - self._tellcore_device = TELLCORE_REGISTRY.get_tellcore_device( + self._tellcore_device = tellcore_registry.get_tellcore_device( tellcore_id) # Query tellcore for the current state self.update() # Add ourselves to the mapping - TELLCORE_REGISTRY.register_ha_device(tellcore_id, self) + tellcore_registry.register_ha_device(tellcore_id, self) @property def should_poll(self):