2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Tellstick switches."""
|
2015-03-22 02:16:13 +00:00
|
|
|
from homeassistant.helpers.entity import ToggleEntity
|
2015-07-08 19:39:50 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_DISCOVER_CONFIG,
|
|
|
|
ATTR_DISCOVER_DEVICES,
|
|
|
|
DATA_TELLSTICK,
|
|
|
|
DEFAULT_SIGNAL_REPETITIONS,
|
|
|
|
TellstickDevice,
|
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2014-11-12 05:39:17 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up Tellstick switches."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if discovery_info is None or discovery_info[ATTR_DISCOVER_DEVICES] is None:
|
2016-03-11 20:54:43 +00:00
|
|
|
return
|
2015-09-20 12:11:42 +00:00
|
|
|
|
2016-03-11 20:54:43 +00:00
|
|
|
# Allow platform level override, fallback to module config
|
2019-07-31 19:25:30 +00:00
|
|
|
signal_repetitions = discovery_info.get(
|
|
|
|
ATTR_DISCOVER_CONFIG, DEFAULT_SIGNAL_REPETITIONS
|
|
|
|
)
|
|
|
|
|
|
|
|
add_entities(
|
|
|
|
[
|
|
|
|
TellstickSwitch(hass.data[DATA_TELLSTICK][tellcore_id], signal_repetitions)
|
|
|
|
for tellcore_id in discovery_info[ATTR_DISCOVER_DEVICES]
|
|
|
|
],
|
|
|
|
True,
|
|
|
|
)
|
2015-09-23 06:26:40 +00:00
|
|
|
|
2014-11-12 05:39:17 +00:00
|
|
|
|
2016-11-23 05:48:22 +00:00
|
|
|
class TellstickSwitch(TellstickDevice, ToggleEntity):
|
2016-03-08 12:35:39 +00:00
|
|
|
"""Representation of a Tellstick switch."""
|
2014-11-12 05:39:17 +00:00
|
|
|
|
2016-11-23 05:48:22 +00:00
|
|
|
def _parse_ha_data(self, kwargs):
|
|
|
|
"""Turn the value from HA into something useful."""
|
2015-01-11 17:20:41 +00:00
|
|
|
|
2016-11-23 05:48:22 +00:00
|
|
|
def _parse_tellcore_data(self, tellcore_data):
|
2017-09-23 15:15:46 +00:00
|
|
|
"""Turn the value received from tellcore into something useful."""
|
2015-01-11 17:20:41 +00:00
|
|
|
|
2016-11-23 05:48:22 +00:00
|
|
|
def _update_model(self, new_state, data):
|
|
|
|
"""Update the device entity state to match the arguments."""
|
|
|
|
self._state = new_state
|
2014-11-12 05:39:17 +00:00
|
|
|
|
2017-01-03 22:54:11 +00:00
|
|
|
def _send_device_command(self, requested_state, requested_data):
|
|
|
|
"""Let tellcore update the actual device to the requested state."""
|
|
|
|
if requested_state:
|
2016-11-23 05:48:22 +00:00
|
|
|
self._tellcore_device.turn_on()
|
|
|
|
else:
|
|
|
|
self._tellcore_device.turn_off()
|
2016-10-16 22:56:55 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def force_update(self) -> bool:
|
|
|
|
"""Will trigger anytime the state property is updated."""
|
|
|
|
return True
|