1 """Contains binary sensors exposed by the Starlink integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
9 BinarySensorDeviceClass,
11 BinarySensorEntityDescription,
18 from .const
import DOMAIN
19 from .coordinator
import StarlinkData
20 from .entity
import StarlinkEntity
24 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
26 """Set up all binary sensors for this entry."""
27 coordinator = hass.data[DOMAIN][entry.entry_id]
31 for description
in BINARY_SENSORS
35 @dataclass(frozen=True, kw_only=True)
37 """Describes a Starlink binary sensor entity."""
39 value_fn: Callable[[StarlinkData], bool |
None]
43 """A BinarySensorEntity for Starlink devices. Handles creating unique IDs."""
45 entity_description: StarlinkBinarySensorEntityDescription
49 """Calculate the binary sensor value from the entity description."""
56 device_class=BinarySensorDeviceClass.UPDATE,
57 value_fn=
lambda data: data.alert[
"alert_install_pending"],
61 translation_key=
"roaming",
62 value_fn=
lambda data: data.alert[
"alert_roaming"],
65 key=
"currently_obstructed",
66 translation_key=
"currently_obstructed",
67 device_class=BinarySensorDeviceClass.PROBLEM,
68 value_fn=
lambda data: data.status[
"currently_obstructed"],
72 translation_key=
"heating",
73 entity_category=EntityCategory.DIAGNOSTIC,
74 value_fn=
lambda data: data.alert[
"alert_is_heating"],
77 key=
"power_save_idle",
78 translation_key=
"power_save_idle",
79 entity_category=EntityCategory.DIAGNOSTIC,
80 value_fn=
lambda data: data.alert[
"alert_is_power_save_idle"],
83 key=
"mast_near_vertical",
84 translation_key=
"mast_near_vertical",
85 device_class=BinarySensorDeviceClass.PROBLEM,
86 entity_category=EntityCategory.DIAGNOSTIC,
87 value_fn=
lambda data: data.alert[
"alert_mast_not_near_vertical"],
91 translation_key=
"motors_stuck",
92 device_class=BinarySensorDeviceClass.PROBLEM,
93 entity_category=EntityCategory.DIAGNOSTIC,
94 value_fn=
lambda data: data.alert[
"alert_motors_stuck"],
98 translation_key=
"slow_ethernet",
99 device_class=BinarySensorDeviceClass.PROBLEM,
100 entity_category=EntityCategory.DIAGNOSTIC,
101 value_fn=
lambda data: data.alert[
"alert_slow_ethernet_speeds"],
104 key=
"thermal_throttle",
105 translation_key=
"thermal_throttle",
106 device_class=BinarySensorDeviceClass.PROBLEM,
107 entity_category=EntityCategory.DIAGNOSTIC,
108 value_fn=
lambda data: data.alert[
"alert_thermal_throttle"],
111 key=
"unexpected_location",
112 translation_key=
"unexpected_location",
113 device_class=BinarySensorDeviceClass.PROBLEM,
114 entity_category=EntityCategory.DIAGNOSTIC,
115 value_fn=
lambda data: data.alert[
"alert_unexpected_location"],
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)