1 """Binary sensor support for Wireless Sensor Tags."""
3 from __future__
import annotations
5 import voluptuous
as vol
8 PLATFORM_SCHEMA
as BINARY_SENSOR_PLATFORM_SCHEMA,
18 from .const
import DOMAIN, SIGNAL_BINARY_EVENT_UPDATE
19 from .entity
import WirelessTagBaseSensor
20 from .util
import async_migrate_unique_id
23 SENSOR_PRESENCE =
"presence"
26 SENSOR_MOTION =
"motion"
44 SENSOR_LIGHT =
"light"
47 SENSOR_MOISTURE =
"moisture"
50 SENSOR_BATTERY =
"battery"
55 SENSOR_PRESENCE:
"Presence",
56 SENSOR_MOTION:
"Motion",
60 SENSOR_DRY:
"Too dry",
61 SENSOR_WET:
"Too wet",
62 SENSOR_LIGHT:
"Light",
63 SENSOR_MOISTURE:
"Leak",
64 SENSOR_BATTERY:
"Low Battery",
68 PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
70 vol.Required(CONF_MONITORED_CONDITIONS, default=[]): vol.All(
71 cv.ensure_list, [vol.In(SENSOR_TYPES)]
80 async_add_entities: AddEntitiesCallback,
81 discovery_info: DiscoveryInfoType |
None =
None,
83 """Set up the platform for a WirelessTags."""
84 platform = hass.data[DOMAIN]
88 for tag
in tags.values():
89 allowed_sensor_types = tag.supported_binary_events_types
90 for sensor_type
in config[CONF_MONITORED_CONDITIONS]:
91 if sensor_type
in allowed_sensor_types:
99 """A binary sensor implementation for WirelessTags."""
102 """Initialize a binary sensor for a Wireless Sensor Tags."""
105 self.
_name_name_name = f
"{self._tag.name} {self.event.human_readable_name}"
109 """Register callbacks."""
110 tag_id = self.
tag_idtag_id
116 SIGNAL_BINARY_EVENT_UPDATE.format(tag_id, event_type, mac),
123 """Return True if the binary sensor is on."""
128 """Return the class of the binary sensor."""
133 """Binary event of tag."""
138 """Return value of tag.
140 Subclasses need override based on type of sensor.
142 return STATE_ON
if self.
eventevent.is_state_on
else STATE_OFF
145 """Use raw princial value."""
150 """Update state from arrived push notification."""
def updated_state_value(self)
def __init__(self, api, tag, sensor_type)
def _on_binary_event_callback(self, new_tag)
None async_added_to_hass(self)
def principal_value(self)
def principal_value(self)
def updated_state_value(self)
str|None device_class(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_migrate_unique_id(HomeAssistant hass, ConfigEntry config_entry, Appliance device)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)