1 """Reads vehicle status from StarLine API."""
3 from __future__
import annotations
6 BinarySensorDeviceClass,
8 BinarySensorEntityDescription,
15 from .account
import StarlineAccount, StarlineDevice
16 from .const
import DOMAIN
17 from .entity
import StarlineEntity
19 BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
22 translation_key=
"hand_brake",
26 translation_key=
"hood",
27 device_class=BinarySensorDeviceClass.DOOR,
31 translation_key=
"trunk",
32 device_class=BinarySensorDeviceClass.DOOR,
36 translation_key=
"alarm",
37 device_class=BinarySensorDeviceClass.PROBLEM,
41 translation_key=
"doors",
42 device_class=BinarySensorDeviceClass.LOCK,
46 translation_key=
"is_running",
47 device_class=BinarySensorDeviceClass.RUNNING,
51 translation_key=
"handsfree",
52 entity_category=EntityCategory.DIAGNOSTIC,
56 translation_key=
"neutral",
57 entity_category=EntityCategory.DIAGNOSTIC,
61 translation_key=
"moving_ban",
62 entity_category=EntityCategory.DIAGNOSTIC,
68 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
70 """Set up the StarLine sensors."""
71 account: StarlineAccount = hass.data[DOMAIN][entry.entry_id]
74 for device
in account.api.devices.values()
75 for description
in BINARY_SENSOR_TYPES
76 if description.key
in device.car_state
77 if (sensor :=
StarlineSensor(account, device, description)).is_on
is not None
83 """Representation of a StarLine binary sensor."""
87 account: StarlineAccount,
88 device: StarlineDevice,
89 description: BinarySensorEntityDescription,
91 """Initialize sensor."""
92 super().
__init__(account, device, description.key)
97 """Return the state of the binary sensor."""
98 return self.
_device_device.car_state.get(self.
_key_key)
None __init__(self, StarlineAccount account, StarlineDevice device, BinarySensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)