1 """Support for w800rf32 binary sensors."""
3 from __future__
import annotations
7 import voluptuous
as vol
8 import W800rf32
as w800
11 DEVICE_CLASSES_SCHEMA,
12 PLATFORM_SCHEMA
as BINARY_SENSOR_PLATFORM_SCHEMA,
22 from .
import W800RF32_DEVICE
24 _LOGGER = logging.getLogger(__name__)
26 CONF_OFF_DELAY =
"off_delay"
28 PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
30 vol.Required(CONF_DEVICES): {
31 cv.string: vol.Schema(
33 vol.Optional(CONF_NAME): cv.string,
34 vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
35 vol.Optional(CONF_OFF_DELAY): vol.All(
36 cv.time_period, cv.positive_timedelta
42 extra=vol.ALLOW_EXTRA,
49 add_entities: AddEntitiesCallback,
50 discovery_info: DiscoveryInfoType |
None =
None,
52 """Set up the Binary Sensor platform to w800rf32."""
56 for device_id, entity
in config[CONF_DEVICES].items():
58 "Add %s w800rf32.binary_sensor (class %s)",
60 entity.get(CONF_DEVICE_CLASS),
65 entity.get(CONF_NAME),
66 entity.get(CONF_DEVICE_CLASS),
67 entity.get(CONF_OFF_DELAY),
70 binary_sensors.append(device)
76 """A representation of a w800rf32 binary sensor."""
78 _attr_should_poll =
False
80 def __init__(self, device_id, name, device_class=None, off_delay=None):
81 """Initialize the w800rf32 sensor."""
82 self.
_signal_signal = W800RF32_DEVICE.format(device_id)
91 """Switch device off after a delay."""
97 """Return the device name."""
98 return self.
_name_name
102 """Return the sensor class."""
107 """Return true if the sensor state is True."""
112 """Call for control updates from the w800rf32 gateway."""
114 if not isinstance(event, w800.W800rf32Event):
117 dev_id = event.device
118 command = event.command
121 "BinarySensor update (Device ID: %s Command %s ...)", dev_id, command
125 if command
in (
"On",
"Off"):
126 is_on = command ==
"On"
135 """Update the state of the device."""
140 """Register update callback."""
None async_added_to_hass(self)
def __init__(self, device_id, name, device_class=None, off_delay=None)
def binary_sensor_update(self, event)
def _off_delay_listener(self, now)
def update_state(self, state)
None async_write_ha_state(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)