@@ -86,26 +86,17 @@ def __publish_ha_discovery_messages_real(self) -> None:
8686 self .__publish_climate_sensors ()
8787
8888 # Complex sensors
89- self .__publish_scheduled_charging ()
9089 self .__publish_scheduled_battery_heating ()
9190
9291 # Switches
93- self ._publish_switch (mqtt_topics .DRIVETRAIN_CHARGING , "Charging" )
9492 self ._publish_switch (
9593 mqtt_topics .DRIVETRAIN_BATTERY_HEATING ,
9694 "Battery heating" ,
9795 icon = "mdi:heat-wave" ,
9896 )
9997 self .__publish_windows_sensors ()
100-
101- # Locks
10298 self .__publish_doors_sensors ()
103-
104- self ._publish_lock (
105- mqtt_topics .DRIVETRAIN_CHARGING_CABLE_LOCK ,
106- "Charging Cable Lock" ,
107- icon = "mdi:lock" ,
108- )
99+ self .__publish_drivetrain_charging_sensors ()
109100
110101 # Target SoC
111102 self ._publish_number (
@@ -189,75 +180,6 @@ def __publish_ha_discovery_messages_real(self) -> None:
189180 icon = "mdi:battery-charging-70" ,
190181 )
191182
192- self ._publish_sensor (
193- mqtt_topics .DRIVETRAIN_REMAINING_CHARGING_TIME ,
194- "Remaining charging time" ,
195- device_class = "duration" ,
196- state_class = "measurement" ,
197- unit_of_measurement = "s" ,
198- )
199- self ._publish_sensor (
200- mqtt_topics .DRIVETRAIN_REMAINING_CHARGING_TIME ,
201- "Charging finished" ,
202- device_class = "timestamp" ,
203- value_template = "{{ (now() + timedelta(seconds = value | int)).isoformat() }}" ,
204- custom_availability = HaCustomAvailabilityConfig (
205- rules = [
206- self .__system_availability ,
207- self .__vehicle_availability ,
208- HaCustomAvailabilityEntry (
209- topic = self .__get_vehicle_topic (
210- mqtt_topics .DRIVETRAIN_REMAINING_CHARGING_TIME
211- ),
212- template = "{{ 'online' if (value | int) > 0 else 'offline' }}" ,
213- ),
214- ]
215- ),
216- )
217- self ._publish_sensor (
218- mqtt_topics .DRIVETRAIN_CHARGING_LAST_START ,
219- "Last Charge Start Time" ,
220- device_class = "timestamp" ,
221- icon = "mdi:clock-start" ,
222- value_template = "{{ value | int | timestamp_utc }}" ,
223- custom_availability = HaCustomAvailabilityConfig (
224- rules = [
225- self .__system_availability ,
226- self .__vehicle_availability ,
227- HaCustomAvailabilityEntry (
228- topic = self .__get_vehicle_topic (
229- mqtt_topics .DRIVETRAIN_CHARGING_LAST_START
230- ),
231- template = "{{ 'online' if (value | int) > 0 else 'offline' }}" ,
232- ),
233- ]
234- ),
235- )
236- self ._publish_sensor (
237- mqtt_topics .DRIVETRAIN_CHARGING_LAST_END ,
238- "Last Charge End Time" ,
239- device_class = "timestamp" ,
240- icon = "mdi:clock-end" ,
241- value_template = "{{ value | int | timestamp_utc }}" ,
242- custom_availability = HaCustomAvailabilityConfig (
243- rules = [
244- self .__system_availability ,
245- self .__vehicle_availability ,
246- HaCustomAvailabilityEntry (
247- topic = self .__get_vehicle_topic (
248- mqtt_topics .DRIVETRAIN_CHARGING_LAST_END
249- ),
250- template = "{{ 'online' if (value | int) > 0 else 'offline' }}" ,
251- ),
252- ]
253- ),
254- )
255- self ._publish_sensor (
256- mqtt_topics .DRIVETRAIN_CHARGING_TYPE ,
257- "Charging Mode" ,
258- enabled = False ,
259- entity_category = "diagnostic" ,
260- )
261183 self ._publish_sensor (
262184 mqtt_topics .BMS_CHARGE_STATUS ,
263185 "BMS Charge Status" ,
@@ -370,18 +292,6 @@ def __publish_ha_discovery_messages_real(self) -> None:
370292 device_class = "power" ,
371293 icon = "mdi:battery-check" ,
372294 )
373- self ._publish_binary_sensor (
374- mqtt_topics .DRIVETRAIN_CHARGING ,
375- "Battery Charging" ,
376- device_class = "battery_charging" ,
377- icon = "mdi:battery-charging" ,
378- )
379- self ._publish_sensor (
380- mqtt_topics .DRIVETRAIN_CHARGING_STOP_REASON ,
381- "Battery charging stop reason" ,
382- icon = "mdi:battery-charging" ,
383- enabled = False ,
384- )
385295 self ._publish_binary_sensor (
386296 mqtt_topics .DRIVETRAIN_BATTERY_HEATING ,
387297 "Battery heating" ,
@@ -403,6 +313,96 @@ def __publish_ha_discovery_messages_real(self) -> None:
403313
404314 LOG .debug ("Completed publishing Home Assistant discovery messages" )
405315
316+ def __publish_drivetrain_charging_sensors (self ) -> None :
317+ self ._publish_switch (mqtt_topics .DRIVETRAIN_CHARGING , "Charging" )
318+ self ._publish_binary_sensor (
319+ mqtt_topics .DRIVETRAIN_CHARGING ,
320+ "Battery Charging" ,
321+ device_class = "battery_charging" ,
322+ icon = "mdi:battery-charging" ,
323+ )
324+ self ._publish_sensor (
325+ mqtt_topics .DRIVETRAIN_CHARGING_STOP_REASON ,
326+ "Battery charging stop reason" ,
327+ icon = "mdi:battery-charging" ,
328+ enabled = False ,
329+ )
330+ self ._publish_sensor (
331+ mqtt_topics .DRIVETRAIN_CHARGING_LAST_START ,
332+ "Last Charge Start Time" ,
333+ device_class = "timestamp" ,
334+ icon = "mdi:clock-start" ,
335+ value_template = "{{ value | int | timestamp_utc }}" ,
336+ custom_availability = HaCustomAvailabilityConfig (
337+ rules = [
338+ self .__system_availability ,
339+ self .__vehicle_availability ,
340+ HaCustomAvailabilityEntry (
341+ topic = self .__get_vehicle_topic (
342+ mqtt_topics .DRIVETRAIN_CHARGING_LAST_START
343+ ),
344+ template = "{{ 'online' if (value | int) > 0 else 'offline' }}" ,
345+ ),
346+ ]
347+ ),
348+ )
349+ self ._publish_sensor (
350+ mqtt_topics .DRIVETRAIN_CHARGING_LAST_END ,
351+ "Last Charge End Time" ,
352+ device_class = "timestamp" ,
353+ icon = "mdi:clock-end" ,
354+ value_template = "{{ value | int | timestamp_utc }}" ,
355+ custom_availability = HaCustomAvailabilityConfig (
356+ rules = [
357+ self .__system_availability ,
358+ self .__vehicle_availability ,
359+ HaCustomAvailabilityEntry (
360+ topic = self .__get_vehicle_topic (
361+ mqtt_topics .DRIVETRAIN_CHARGING_LAST_END
362+ ),
363+ template = "{{ 'online' if (value | int) > 0 else 'offline' }}" ,
364+ ),
365+ ]
366+ ),
367+ )
368+ self ._publish_sensor (
369+ mqtt_topics .DRIVETRAIN_CHARGING_TYPE ,
370+ "Charging Mode" ,
371+ enabled = False ,
372+ entity_category = "diagnostic" ,
373+ )
374+ self ._publish_lock (
375+ mqtt_topics .DRIVETRAIN_CHARGING_CABLE_LOCK ,
376+ "Charging Cable Lock" ,
377+ icon = "mdi:lock" ,
378+ )
379+ self ._publish_sensor (
380+ mqtt_topics .DRIVETRAIN_REMAINING_CHARGING_TIME ,
381+ "Remaining charging time" ,
382+ device_class = "duration" ,
383+ state_class = "measurement" ,
384+ unit_of_measurement = "s" ,
385+ )
386+ self ._publish_sensor (
387+ mqtt_topics .DRIVETRAIN_REMAINING_CHARGING_TIME ,
388+ "Charging finished" ,
389+ device_class = "timestamp" ,
390+ value_template = "{{ (now() + timedelta(seconds = value | int)).isoformat() }}" ,
391+ custom_availability = HaCustomAvailabilityConfig (
392+ rules = [
393+ self .__system_availability ,
394+ self .__vehicle_availability ,
395+ HaCustomAvailabilityEntry (
396+ topic = self .__get_vehicle_topic (
397+ mqtt_topics .DRIVETRAIN_REMAINING_CHARGING_TIME
398+ ),
399+ template = "{{ 'online' if (value | int) > 0 else 'offline' }}" ,
400+ ),
401+ ]
402+ ),
403+ )
404+ self .__publish_scheduled_charging ()
405+
406406 def __publish_location_sensors (self ) -> None :
407407 self .__publish_vehicle_tracker ()
408408 self ._publish_sensor (
0 commit comments