1 """Binary Sensor platform for Tessie integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from itertools
import chain
10 BinarySensorDeviceClass,
12 BinarySensorEntityDescription,
18 from .
import TessieConfigEntry
19 from .const
import TessieState
20 from .entity
import TessieEnergyEntity, TessieEntity
21 from .models
import TessieEnergyData, TessieVehicleData
26 @dataclass(frozen=True, kw_only=True)
28 """Describes Tessie binary sensor entity."""
30 is_on: Callable[..., bool] =
lambda x: x
33 VEHICLE_DESCRIPTIONS: tuple[TessieBinarySensorEntityDescription, ...] = (
36 device_class=BinarySensorDeviceClass.CONNECTIVITY,
37 is_on=
lambda x: x == TessieState.ONLINE,
40 key=
"climate_state_battery_heater",
41 device_class=BinarySensorDeviceClass.HEAT,
42 entity_category=EntityCategory.DIAGNOSTIC,
45 key=
"charge_state_charging_state",
46 device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
47 is_on=
lambda x: x ==
"Charging",
48 entity_registry_enabled_default=
False,
51 key=
"charge_state_preconditioning_enabled",
52 entity_category=EntityCategory.DIAGNOSTIC,
55 key=
"charge_state_scheduled_charging_pending",
56 entity_category=EntityCategory.DIAGNOSTIC,
59 key=
"charge_state_trip_charging",
60 entity_category=EntityCategory.DIAGNOSTIC,
63 key=
"charge_state_conn_charge_cable",
64 is_on=
lambda x: x !=
"<invalid>",
65 entity_category=EntityCategory.DIAGNOSTIC,
66 device_class=BinarySensorDeviceClass.CONNECTIVITY,
69 key=
"climate_state_auto_seat_climate_left",
70 entity_category=EntityCategory.DIAGNOSTIC,
73 key=
"climate_state_auto_seat_climate_right",
74 entity_category=EntityCategory.DIAGNOSTIC,
77 key=
"climate_state_auto_steering_wheel_heat",
78 entity_category=EntityCategory.DIAGNOSTIC,
81 key=
"climate_state_cabin_overheat_protection",
82 device_class=BinarySensorDeviceClass.RUNNING,
83 is_on=
lambda x: x ==
"On",
84 entity_category=EntityCategory.DIAGNOSTIC,
87 key=
"climate_state_cabin_overheat_protection_actively_cooling",
88 device_class=BinarySensorDeviceClass.HEAT,
89 entity_category=EntityCategory.DIAGNOSTIC,
92 key=
"vehicle_state_dashcam_state",
93 device_class=BinarySensorDeviceClass.RUNNING,
94 is_on=
lambda x: x ==
"Recording",
95 entity_category=EntityCategory.DIAGNOSTIC,
98 key=
"vehicle_state_is_user_present",
99 device_class=BinarySensorDeviceClass.OCCUPANCY,
102 key=
"vehicle_state_tpms_soft_warning_fl",
103 device_class=BinarySensorDeviceClass.PROBLEM,
104 entity_category=EntityCategory.DIAGNOSTIC,
107 key=
"vehicle_state_tpms_soft_warning_fr",
108 device_class=BinarySensorDeviceClass.PROBLEM,
109 entity_category=EntityCategory.DIAGNOSTIC,
112 key=
"vehicle_state_tpms_soft_warning_rl",
113 device_class=BinarySensorDeviceClass.PROBLEM,
114 entity_category=EntityCategory.DIAGNOSTIC,
117 key=
"vehicle_state_tpms_soft_warning_rr",
118 device_class=BinarySensorDeviceClass.PROBLEM,
119 entity_category=EntityCategory.DIAGNOSTIC,
122 key=
"vehicle_state_fd_window",
123 device_class=BinarySensorDeviceClass.WINDOW,
124 entity_category=EntityCategory.DIAGNOSTIC,
127 key=
"vehicle_state_fp_window",
128 device_class=BinarySensorDeviceClass.WINDOW,
129 entity_category=EntityCategory.DIAGNOSTIC,
132 key=
"vehicle_state_rd_window",
133 device_class=BinarySensorDeviceClass.WINDOW,
134 entity_category=EntityCategory.DIAGNOSTIC,
137 key=
"vehicle_state_rp_window",
138 device_class=BinarySensorDeviceClass.WINDOW,
139 entity_category=EntityCategory.DIAGNOSTIC,
142 key=
"vehicle_state_df",
143 device_class=BinarySensorDeviceClass.DOOR,
144 entity_category=EntityCategory.DIAGNOSTIC,
147 key=
"vehicle_state_dr",
148 device_class=BinarySensorDeviceClass.DOOR,
149 entity_category=EntityCategory.DIAGNOSTIC,
152 key=
"vehicle_state_pf",
153 device_class=BinarySensorDeviceClass.DOOR,
154 entity_category=EntityCategory.DIAGNOSTIC,
157 key=
"vehicle_state_pr",
158 device_class=BinarySensorDeviceClass.DOOR,
159 entity_category=EntityCategory.DIAGNOSTIC,
163 ENERGY_LIVE_DESCRIPTIONS: tuple[BinarySensorEntityDescription, ...] = (
170 ENERGY_INFO_DESCRIPTIONS: tuple[BinarySensorEntityDescription, ...] = (
172 key=
"components_grid_services_enabled",
179 entry: TessieConfigEntry,
180 async_add_entities: AddEntitiesCallback,
182 """Set up the Tessie binary sensor platform from a config entry."""
187 for vehicle
in entry.runtime_data.vehicles
188 for description
in VEHICLE_DESCRIPTIONS
192 for energy
in entry.runtime_data.energysites
193 for description
in ENERGY_LIVE_DESCRIPTIONS
197 for vehicle
in entry.runtime_data.energysites
198 for description
in ENERGY_INFO_DESCRIPTIONS
205 """Base class for Tessie binary sensors."""
207 entity_description: TessieBinarySensorEntityDescription
211 vehicle: TessieVehicleData,
212 description: TessieBinarySensorEntityDescription,
214 """Initialize the sensor."""
215 super().
__init__(vehicle, description.key)
220 """Return the state of the binary sensor."""
225 """Base class for Tessie energy live binary sensors."""
227 entity_description: BinarySensorEntityDescription
231 data: TessieEnergyData,
232 description: BinarySensorEntityDescription,
234 """Initialize the binary sensor."""
236 super().
__init__(data, data.live_coordinator, description.key)
239 """Update the attributes of the binary sensor."""
244 """Base class for Tessie energy info binary sensors."""
246 entity_description: BinarySensorEntityDescription
250 data: TessieEnergyData,
251 description: BinarySensorEntityDescription,
253 """Initialize the binary sensor."""
255 super().
__init__(data, data.info_coordinator, description.key)
258 """Update the attributes of the binary sensor."""
None __init__(self, TessieVehicleData vehicle, TessieBinarySensorEntityDescription description)
None __init__(self, TessieEnergyData data, BinarySensorEntityDescription description)
None _async_update_attrs(self)
None __init__(self, TessieEnergyData data, BinarySensorEntityDescription description)
None _async_update_attrs(self)
None async_setup_entry(HomeAssistant hass, TessieConfigEntry entry, AddEntitiesCallback async_add_entities)