1010from homeassistant .helpers .entity import generate_entity_id
1111from homeassistant .util .dt import (utcnow )
1212from .const import DOMAIN , DATA_COORDINATORS , DATA_SLOTS , COORDINATOR_CHARGESESSIONS , COORDINATOR_ADVANCED , DATA_CLIENT
13- from .coordinator import OhmeChargeSessionsCoordinator , OhmeAdvancedSettingsCoordinator
1413from .utils import in_slot
14+ from .base import OhmeEntity
1515
1616_LOGGER = logging .getLogger (__name__ )
1717
@@ -36,40 +36,14 @@ async def async_setup_entry(
3636
3737
3838class ConnectedBinarySensor (
39- CoordinatorEntity [ OhmeChargeSessionsCoordinator ] ,
39+ OhmeEntity ,
4040 BinarySensorEntity ):
4141 """Binary sensor for if car is plugged in."""
4242
43- _attr_name = "Car Connected"
43+ _attr_translation_key = "car_connected"
44+ _attr_icon = "mdi:ev-plug-type2"
4445 _attr_device_class = BinarySensorDeviceClass .PLUG
4546
46- def __init__ (
47- self ,
48- coordinator : OhmeChargeSessionsCoordinator ,
49- hass : HomeAssistant ,
50- client ):
51- super ().__init__ (coordinator = coordinator )
52-
53- self ._attributes = {}
54- self ._last_updated = None
55- self ._state = False
56- self ._client = client
57-
58- self .entity_id = generate_entity_id (
59- "binary_sensor.{}" , "ohme_car_connected" , hass = hass )
60-
61- self ._attr_device_info = client .get_device_info ()
62-
63- @property
64- def icon (self ):
65- """Icon of the sensor."""
66- return "mdi:ev-plug-type2"
67-
68- @property
69- def unique_id (self ) -> str :
70- """Return the unique ID of the sensor."""
71- return self ._client .get_unique_id ("car_connected" )
72-
7347 @property
7448 def is_on (self ) -> bool :
7549 if self .coordinator .data is None :
@@ -81,24 +55,20 @@ def is_on(self) -> bool:
8155
8256
8357class ChargingBinarySensor (
84- CoordinatorEntity [ OhmeChargeSessionsCoordinator ] ,
58+ OhmeEntity ,
8559 BinarySensorEntity ):
8660 """Binary sensor for if car is charging."""
8761
88- _attr_name = "Car Charging"
62+ _attr_translation_key = "car_charging"
63+ _attr_icon = "mdi:battery-charging-100"
8964 _attr_device_class = BinarySensorDeviceClass .BATTERY_CHARGING
9065
9166 def __init__ (
9267 self ,
9368 coordinator : OhmeChargeSessionsCoordinator ,
9469 hass : HomeAssistant ,
9570 client ):
96- super ().__init__ (coordinator = coordinator )
97-
98- self ._attributes = {}
99- self ._last_updated = None
100- self ._state = False
101- self ._client = client
71+ super ().__init__ (coordinator , hass , client )
10272
10373 # Cache the last power readings
10474 self ._last_reading = None
@@ -107,21 +77,6 @@ def __init__(
10777 # State variables for charge state detection
10878 self ._trigger_count = 0
10979
110- self .entity_id = generate_entity_id (
111- "binary_sensor.{}" , "ohme_car_charging" , hass = hass )
112-
113- self ._attr_device_info = client .get_device_info ()
114-
115- @property
116- def icon (self ):
117- """Icon of the sensor."""
118- return "mdi:battery-charging-100"
119-
120- @property
121- def unique_id (self ) -> str :
122- """Return the unique ID of the sensor."""
123- return self ._client .get_unique_id ("ohme_car_charging" )
124-
12580 @property
12681 def is_on (self ) -> bool :
12782 return self ._state
@@ -208,38 +163,12 @@ def _handle_coordinator_update(self) -> None:
208163
209164
210165class PendingApprovalBinarySensor (
211- CoordinatorEntity [ OhmeChargeSessionsCoordinator ] ,
166+ OhmeEntity ,
212167 BinarySensorEntity ):
213168 """Binary sensor for if a charge is pending approval."""
214169
215- _attr_name = "Pending Approval"
216-
217- def __init__ (
218- self ,
219- coordinator : OhmeChargeSessionsCoordinator ,
220- hass : HomeAssistant ,
221- client ):
222- super ().__init__ (coordinator = coordinator )
223-
224- self ._attributes = {}
225- self ._last_updated = None
226- self ._state = False
227- self ._client = client
228-
229- self .entity_id = generate_entity_id (
230- "binary_sensor.{}" , "ohme_pending_approval" , hass = hass )
231-
232- self ._attr_device_info = client .get_device_info ()
233-
234- @property
235- def icon (self ):
236- """Icon of the sensor."""
237- return "mdi:alert-decagram"
238-
239- @property
240- def unique_id (self ) -> str :
241- """Return the unique ID of the sensor."""
242- return self ._client .get_unique_id ("pending_approval" )
170+ _attr_translation_key = "pending_approval"
171+ _attr_icon = "mdi:alert-decagram"
243172
244173 @property
245174 def is_on (self ) -> bool :
@@ -253,38 +182,12 @@ def is_on(self) -> bool:
253182
254183
255184class CurrentSlotBinarySensor (
256- CoordinatorEntity [ OhmeChargeSessionsCoordinator ] ,
185+ OhmeEntity ,
257186 BinarySensorEntity ):
258187 """Binary sensor for if we are currently in a smart charge slot."""
259188
260- _attr_name = "Charge Slot Active"
261-
262- def __init__ (
263- self ,
264- coordinator : OhmeChargeSessionsCoordinator ,
265- hass : HomeAssistant ,
266- client ):
267- super ().__init__ (coordinator = coordinator )
268-
269- self ._last_updated = None
270- self ._state = False
271- self ._client = client
272- self ._hass = hass
273-
274- self .entity_id = generate_entity_id (
275- "binary_sensor.{}" , "ohme_slot_active" , hass = hass )
276-
277- self ._attr_device_info = client .get_device_info ()
278-
279- @property
280- def icon (self ):
281- """Icon of the sensor."""
282- return "mdi:calendar-check"
283-
284- @property
285- def unique_id (self ) -> str :
286- """Return the unique ID of the sensor."""
287- return self ._client .get_unique_id ("ohme_slot_active" )
189+ _attr_translation_key = "slot_active"
190+ _attr_icon = "mdi:calendar-check"
288191
289192 @property
290193 def extra_state_attributes (self ):
@@ -316,40 +219,14 @@ def _handle_coordinator_update(self) -> None:
316219 self .async_write_ha_state ()
317220
318221class ChargerOnlineBinarySensor (
319- CoordinatorEntity [ OhmeAdvancedSettingsCoordinator ] ,
222+ OhmeEntity ,
320223 BinarySensorEntity ):
321224 """Binary sensor for if charger is online."""
322225
323- _attr_name = "Charger Online"
226+ _attr_translation_key = "charger_online"
227+ _attr_icon = "mdi:web"
324228 _attr_device_class = BinarySensorDeviceClass .CONNECTIVITY
325229
326- def __init__ (
327- self ,
328- coordinator : OhmeAdvancedSettingsCoordinator ,
329- hass : HomeAssistant ,
330- client ):
331- super ().__init__ (coordinator = coordinator )
332-
333- self ._attributes = {}
334- self ._last_updated = None
335- self ._state = None
336- self ._client = client
337-
338- self .entity_id = generate_entity_id (
339- "binary_sensor.{}" , "ohme_charger_online" , hass = hass )
340-
341- self ._attr_device_info = client .get_device_info ()
342-
343- @property
344- def icon (self ):
345- """Icon of the sensor."""
346- return "mdi:web"
347-
348- @property
349- def unique_id (self ) -> str :
350- """Return the unique ID of the sensor."""
351- return self ._client .get_unique_id ("charger_online" )
352-
353230 @property
354231 def is_on (self ) -> bool :
355232 if self .coordinator .data and self .coordinator .data ["online" ]:
0 commit comments