mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Merge pull request #210 from balloob/tellstick-robustness
Added functionallity so that the tellstick switch can send its signals repeatedly
This commit is contained in:
commit
045e0c70cb
@ -3,6 +3,12 @@ homeassistant.components.switch.tellstick
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Support for Tellstick switches.
|
Support for Tellstick switches.
|
||||||
|
|
||||||
|
Because the tellstick sends its actions via radio and from most
|
||||||
|
receivers it's impossible to know if the signal was received or not.
|
||||||
|
Therefore you can configure the switch to try to send each signal repeatedly
|
||||||
|
with the config parameter signal_repetitions (default is 1).
|
||||||
|
signal_repetitions: 3
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -11,6 +17,8 @@ from homeassistant.const import ATTR_FRIENDLY_NAME
|
|||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
import tellcore.constants as tellcore_constants
|
import tellcore.constants as tellcore_constants
|
||||||
|
|
||||||
|
SINGAL_REPETITIONS = 1
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
@ -22,6 +30,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
"Failed to import tellcore")
|
"Failed to import tellcore")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
signal_repetitions = config.get('signal_repetitions', SINGAL_REPETITIONS)
|
||||||
|
|
||||||
core = telldus.TelldusCore()
|
core = telldus.TelldusCore()
|
||||||
switches_and_lights = core.devices()
|
switches_and_lights = core.devices()
|
||||||
|
|
||||||
@ -29,7 +39,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
|
|
||||||
for switch in switches_and_lights:
|
for switch in switches_and_lights:
|
||||||
if not switch.methods(tellcore_constants.TELLSTICK_DIM):
|
if not switch.methods(tellcore_constants.TELLSTICK_DIM):
|
||||||
switches.append(TellstickSwitchDevice(switch))
|
switches.append(TellstickSwitchDevice(switch, signal_repetitions))
|
||||||
|
|
||||||
add_devices_callback(switches)
|
add_devices_callback(switches)
|
||||||
|
|
||||||
@ -39,9 +49,10 @@ class TellstickSwitchDevice(ToggleEntity):
|
|||||||
last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
|
last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
|
||||||
tellcore_constants.TELLSTICK_TURNOFF)
|
tellcore_constants.TELLSTICK_TURNOFF)
|
||||||
|
|
||||||
def __init__(self, tellstick):
|
def __init__(self, tellstick, signal_repetitions):
|
||||||
self.tellstick = tellstick
|
self.tellstick = tellstick
|
||||||
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick.name}
|
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick.name}
|
||||||
|
self.signal_repetitions = signal_repetitions
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -63,8 +74,10 @@ class TellstickSwitchDevice(ToggleEntity):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turns the switch on. """
|
""" Turns the switch on. """
|
||||||
self.tellstick.turn_on()
|
for _ in range(self.signal_repetitions):
|
||||||
|
self.tellstick.turn_on()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turns the switch off. """
|
""" Turns the switch off. """
|
||||||
self.tellstick.turn_off()
|
for _ in range(self.signal_repetitions):
|
||||||
|
self.tellstick.turn_off()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user