1 """Support for Rflink binary sensors."""
3 from __future__
import annotations
7 import voluptuous
as vol
10 DEVICE_CLASSES_SCHEMA,
11 PLATFORM_SCHEMA
as BINARY_SENSOR_PLATFORM_SCHEMA,
12 BinarySensorDeviceClass,
29 from .const
import CONF_ALIASES
30 from .entity
import RflinkDevice
32 CONF_OFF_DELAY =
"off_delay"
33 DEFAULT_FORCE_UPDATE =
False
35 PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
37 vol.Optional(CONF_DEVICES, default={}): {
38 cv.string: vol.Schema(
40 vol.Optional(CONF_NAME): cv.string,
41 vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
43 CONF_FORCE_UPDATE, default=DEFAULT_FORCE_UPDATE
45 vol.Optional(CONF_OFF_DELAY): cv.positive_int,
46 vol.Optional(CONF_ALIASES, default=[]): vol.All(
47 cv.ensure_list, [cv.string]
53 extra=vol.ALLOW_EXTRA,
58 """Parse configuration and add Rflink sensor devices."""
60 for device_id, config
in domain_config[CONF_DEVICES].items():
62 devices.append(device)
70 async_add_entities: AddEntitiesCallback,
71 discovery_info: DiscoveryInfoType |
None =
None,
73 """Set up the Rflink platform."""
78 """Representation of an Rflink binary sensor."""
83 device_class: BinarySensorDeviceClass |
None =
None,
84 force_update: bool =
False,
85 off_delay: int |
None =
None,
88 """Handle sensor specific args and super init."""
94 super().
__init__(device_id, **kwargs)
97 """Restore RFLink BinarySensor state."""
101 self.
_state_state = old_state.state == STATE_ON
106 """Domain specific event handler."""
107 command = event[
"command"]
108 if command
in [
"on",
"allon"]:
110 elif command
in [
"off",
"alloff"]:
116 def off_delay_listener(now):
117 """Switch device off after a delay."""
130 """Return true if the binary sensor is on."""
None __init__(self, str device_id, BinarySensorDeviceClass|None device_class=None, bool force_update=False, int|None off_delay=None, **Any kwargs)
def _handle_event(self, event)
None async_added_to_hass(self)
None async_write_ha_state(self)
State|None async_get_last_state(self)
def devices_from_config(domain_config)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)