1 """Support for Pilight binary sensors."""
3 from __future__
import annotations
7 import voluptuous
as vol
10 PLATFORM_SCHEMA
as BINARY_SENSOR_PLATFORM_SCHEMA,
14 CONF_DISARM_AFTER_TRIGGER,
29 CONF_VARIABLE =
"variable"
30 CONF_RESET_DELAY_SEC =
"reset_delay_sec"
32 DEFAULT_NAME =
"Pilight Binary Sensor"
33 PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
35 vol.Required(CONF_VARIABLE): cv.string,
36 vol.Required(CONF_PAYLOAD): vol.Schema(dict),
37 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
38 vol.Optional(CONF_PAYLOAD_ON, default=
"on"): vol.Any(
39 cv.positive_int, cv.small_float, cv.string
41 vol.Optional(CONF_PAYLOAD_OFF, default=
"off"): vol.Any(
42 cv.positive_int, cv.small_float, cv.string
44 vol.Optional(CONF_DISARM_AFTER_TRIGGER, default=
False): cv.boolean,
45 vol.Optional(CONF_RESET_DELAY_SEC, default=30): cv.positive_int,
53 add_entities: AddEntitiesCallback,
54 discovery_info: DiscoveryInfoType |
None =
None,
56 """Set up Pilight Binary Sensor."""
57 if config.get(CONF_DISARM_AFTER_TRIGGER):
62 name=config.get(CONF_NAME),
63 variable=config.get(CONF_VARIABLE),
64 payload=config.get(CONF_PAYLOAD),
65 on_value=config.get(CONF_PAYLOAD_ON),
66 off_value=config.get(CONF_PAYLOAD_OFF),
67 rst_dly_sec=config.get(CONF_RESET_DELAY_SEC),
76 name=config.get(CONF_NAME),
77 variable=config.get(CONF_VARIABLE),
78 payload=config.get(CONF_PAYLOAD),
79 on_value=config.get(CONF_PAYLOAD_ON),
80 off_value=config.get(CONF_PAYLOAD_OFF),
87 """Representation of a binary sensor that can be updated using Pilight."""
89 def __init__(self, hass, name, variable, payload, on_value, off_value):
90 """Initialize the sensor."""
103 """Return the name of the sensor."""
104 return self.
_name_name
108 """Return True if the binary sensor is on."""
112 """Handle received code by the pilight-daemon.
114 If the code matches the defined payload
115 of this sensor the sensor state is changed accordingly.
121 if key
not in call.data:
124 if self.
_payload_payload[key] != call.data[key]:
128 if self.
_variable_variable
not in call.data:
130 value = call.data[self.
_variable_variable]
136 """Representation of a binary sensor that can be updated using Pilight."""
139 self, hass, name, variable, payload, on_value, off_value, rst_dly_sec=30
141 """Initialize the sensor."""
151 self.
_hass_hass = hass
157 """Return the name of the sensor."""
158 return self.
_name_name
162 """Return True if the binary sensor is on."""
171 """Handle received code by the pilight-daemon.
173 If the code matches the defined payload
174 of this sensor the sensor state is changed accordingly.
180 if key
not in call.data:
183 if self.
_payload_payload[key] != call.data[key]:
187 if self.
_variable_variable
not in call.data:
189 value = call.data[self.
_variable_variable]
192 self.
_delay_after_delay_after = dt_util.utcnow() + datetime.timedelta(
def __init__(self, hass, name, variable, payload, on_value, off_value)
def _handle_code(self, call)
def _handle_code(self, call)
def _reset_state(self, call)
def __init__(self, hass, name, variable, payload, on_value, off_value, rst_dly_sec=30)
None schedule_update_ha_state(self, bool force_refresh=False)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)