1 """Binary sensor platform for mobile_app."""
14 ATTR_SENSOR_ATTRIBUTES,
15 ATTR_SENSOR_DEVICE_CLASS,
16 ATTR_SENSOR_ENTITY_CATEGORY,
21 ATTR_SENSOR_TYPE_BINARY_SENSOR
as ENTITY_TYPE,
22 ATTR_SENSOR_UNIQUE_ID,
25 from .entity
import MobileAppEntity
30 config_entry: ConfigEntry,
31 async_add_entities: AddEntitiesCallback,
33 """Set up mobile app binary sensor from a config entry."""
36 webhook_id = config_entry.data[CONF_WEBHOOK_ID]
38 entity_registry = er.async_get(hass)
39 entries = er.async_entries_for_config_entry(entity_registry, config_entry.entry_id)
41 if entry.domain != ENTITY_TYPE
or entry.disabled_by:
43 config: dict[str, Any] = {
44 ATTR_SENSOR_ATTRIBUTES: {},
45 ATTR_SENSOR_DEVICE_CLASS: entry.device_class
or entry.original_device_class,
46 ATTR_SENSOR_ICON: entry.original_icon,
47 ATTR_SENSOR_NAME: entry.original_name,
48 ATTR_SENSOR_STATE:
None,
49 ATTR_SENSOR_TYPE: entry.domain,
50 ATTR_SENSOR_UNIQUE_ID: entry.unique_id,
51 ATTR_SENSOR_ENTITY_CATEGORY: entry.entity_category,
58 def handle_sensor_registration(data):
59 if data[CONF_WEBHOOK_ID] != webhook_id:
66 f
"{DOMAIN}_{ENTITY_TYPE}_register",
67 handle_sensor_registration,
72 """Representation of a mobile app binary sensor."""
75 """Restore previous state."""
77 self.
_config_config[ATTR_SENSOR_STATE] = last_state.state == STATE_ON
82 """Update the entity from the config."""
None async_restore_last_state(self, State last_state)
None _async_update_attr_from_config(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)