Coverage for custom_components/autoarm/entity.py: 100%
22 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-26 20:57 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-26 20:57 +0000
1"""Base entity for the AutoArm status entities."""
3from homeassistant.core import Context, callback
4from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
5from homeassistant.helpers.dispatcher import async_dispatcher_connect
6from homeassistant.helpers.entity import Entity, EntityDescription
8from .autoarming import AlarmArmer, AutoArmConfigEntry
9from .const import DOMAIN, SIGNAL_STATUS_UPDATED
12class AutoArmEntity(Entity):
13 """Entity showing AutoArm's own state, updated whenever the armer publishes a change"""
15 _attr_has_entity_name = True
16 _attr_should_poll = False
18 def __init__(self, armer: AlarmArmer, entry: AutoArmConfigEntry, platform: str, description: EntityDescription) -> None:
19 self.armer = armer
20 self.entity_description = description
21 self._attr_unique_id = f"{entry.entry_id}_{description.key}"
22 # fixed entity_id, so it doesn't vary with the system language, and matches the docs
23 self.entity_id = f"{platform}.{DOMAIN}_{description.key}"
24 self._attr_device_info = DeviceInfo(
25 identifiers={(DOMAIN, entry.entry_id)},
26 name="Auto Arm",
27 manufacturer="Rhizomatics",
28 entry_type=DeviceEntryType.SERVICE,
29 )
31 async def async_added_to_hass(self) -> None:
32 self.async_on_remove(async_dispatcher_connect(self.hass, SIGNAL_STATUS_UPDATED, self._on_status_updated))
34 @callback
35 def _on_status_updated(self, context: Context | None = None) -> None:
36 # so the state change can be traced back to what caused it
37 if context is not None:
38 self.async_set_context(context)
39 self.async_write_ha_state()