@@ -36,6 +36,13 @@ def on_basic_vehicle_status(
3636 is_engine_running or remote_climate_status > 0 or rear_window_heat_state > 0
3737 )
3838
39+ is_valid_mileage , _ = self ._transform_and_publish (
40+ topic = mqtt_topics .DRIVETRAIN_MILEAGE ,
41+ value = basic_vehicle_status .mileage ,
42+ validator = lambda x : value_in_range (x , 1 , 2147483647 ),
43+ transform = lambda x : x / 10.0 ,
44+ )
45+
3946 self ._publish (
4047 topic = mqtt_topics .DRIVETRAIN_RUNNING ,
4148 value = is_engine_running ,
@@ -60,35 +67,30 @@ def on_basic_vehicle_status(
6067 transform = lambda x : x / 10.0 ,
6168 )
6269
63- self ._transform_and_publish (
64- topic = mqtt_topics .WINDOWS_DRIVER ,
65- value = basic_vehicle_status .driverWindow ,
66- transform = int_to_bool ,
67- )
68-
69- self ._transform_and_publish (
70- topic = mqtt_topics .WINDOWS_DRIVER ,
71- value = basic_vehicle_status .driverWindow ,
72- transform = int_to_bool ,
73- )
70+ if is_valid_mileage :
71+ self ._transform_and_publish (
72+ topic = mqtt_topics .WINDOWS_DRIVER ,
73+ value = basic_vehicle_status .driverWindow ,
74+ transform = int_to_bool ,
75+ )
7476
75- self ._transform_and_publish (
76- topic = mqtt_topics .WINDOWS_PASSENGER ,
77- value = basic_vehicle_status .passengerWindow ,
78- transform = int_to_bool ,
79- )
77+ self ._transform_and_publish (
78+ topic = mqtt_topics .WINDOWS_PASSENGER ,
79+ value = basic_vehicle_status .passengerWindow ,
80+ transform = int_to_bool ,
81+ )
8082
81- self ._transform_and_publish (
82- topic = mqtt_topics .WINDOWS_REAR_LEFT ,
83- value = basic_vehicle_status .rearLeftWindow ,
84- transform = int_to_bool ,
85- )
83+ self ._transform_and_publish (
84+ topic = mqtt_topics .WINDOWS_REAR_LEFT ,
85+ value = basic_vehicle_status .rearLeftWindow ,
86+ transform = int_to_bool ,
87+ )
8688
87- self ._transform_and_publish (
88- topic = mqtt_topics .WINDOWS_REAR_RIGHT ,
89- value = basic_vehicle_status .rearRightWindow ,
90- transform = int_to_bool ,
91- )
89+ self ._transform_and_publish (
90+ topic = mqtt_topics .WINDOWS_REAR_RIGHT ,
91+ value = basic_vehicle_status .rearRightWindow ,
92+ transform = int_to_bool ,
93+ )
9294
9395 self ._transform_and_publish (
9496 topic = mqtt_topics .WINDOWS_SUN_ROOF ,
@@ -200,13 +202,6 @@ def on_basic_vehicle_status(
200202 validator = lambda x : value_in_range (x , 0 , 255 ),
201203 )
202204
203- self ._transform_and_publish (
204- topic = mqtt_topics .DRIVETRAIN_MILEAGE ,
205- value = basic_vehicle_status .mileage ,
206- validator = lambda x : value_in_range (x , 1 , 2147483647 ),
207- transform = lambda x : x / 10.0 ,
208- )
209-
210205 # Standard fossil fuels vehicles
211206 self ._transform_and_publish (
212207 topic = mqtt_topics .DRIVETRAIN_FOSSIL_FUEL_RANGE ,
0 commit comments