From b6d7cacc61f11aa431b59f82548d5dbda303c7e2 Mon Sep 17 00:00:00 2001 From: Daniel Hoyer Iversen Date: Sat, 28 Nov 2015 20:39:48 +0100 Subject: [PATCH] Added signal repetitions to tellstick light --- homeassistant/components/light/tellstick.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index 24d86c47c51..7b274eeac26 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -10,6 +10,7 @@ from homeassistant.components.light import Light, ATTR_BRIGHTNESS from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, ATTR_FRIENDLY_NAME) REQUIREMENTS = ['tellcore-py==1.1.2'] +SIGNAL_REPETITIONS = 1 # pylint: disable=unused-argument @@ -21,13 +22,14 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): import tellcore.constants as tellcore_constants core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher()) + signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS) switches_and_lights = core.devices() lights = [] for switch in switches_and_lights: if switch.methods(tellcore_constants.TELLSTICK_DIM): - lights.append(TellstickLight(switch)) + lights.append(TellstickLight(switch, signal_repetitions)) def _device_event_callback(id_, method, data, cid): """ Called from the TelldusCore library to update one device """ @@ -52,11 +54,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): class TellstickLight(Light): """ Represents a Tellstick light. """ - def __init__(self, tellstick_device): + def __init__(self, tellstick_device, signal_repetitions): import tellcore.constants as tellcore_constants self.tellstick_device = tellstick_device self.state_attr = {ATTR_FRIENDLY_NAME: tellstick_device.name} + self.signal_repetitions = signal_repetitions self._brightness = 0 self.last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON | @@ -82,7 +85,8 @@ class TellstickLight(Light): def turn_off(self, **kwargs): """ Turns the switch off. """ - self.tellstick_device.turn_off() + for _ in range(self.signal_repetitions): + self.tellstick_device.turn_off() self._brightness = 0 self.update_ha_state() @@ -95,7 +99,8 @@ class TellstickLight(Light): else: self._brightness = brightness - self.tellstick_device.dim(self._brightness) + for _ in range(self.signal_repetitions): + self.tellstick_device.dim(self._brightness) self.update_ha_state() def update(self):