diff --git a/poetry.toml b/poetry.toml new file mode 100644 index 0000000..ab1033b --- /dev/null +++ b/poetry.toml @@ -0,0 +1,2 @@ +[virtualenvs] +in-project = true diff --git a/src/status_publisher/vehicle/basic_vehicle_status.py b/src/status_publisher/vehicle/basic_vehicle_status.py index f831b64..60cd915 100644 --- a/src/status_publisher/vehicle/basic_vehicle_status.py +++ b/src/status_publisher/vehicle/basic_vehicle_status.py @@ -36,6 +36,13 @@ def on_basic_vehicle_status( is_engine_running or remote_climate_status > 0 or rear_window_heat_state > 0 ) + is_valid_mileage, _ = self._transform_and_publish( + topic=mqtt_topics.DRIVETRAIN_MILEAGE, + value=basic_vehicle_status.mileage, + validator=lambda x: value_in_range(x, 1, 2147483647), + transform=lambda x: x / 10.0, + ) + self._publish( topic=mqtt_topics.DRIVETRAIN_RUNNING, value=is_engine_running, @@ -60,35 +67,30 @@ def on_basic_vehicle_status( transform=lambda x: x / 10.0, ) - self._transform_and_publish( - topic=mqtt_topics.WINDOWS_DRIVER, - value=basic_vehicle_status.driverWindow, - transform=int_to_bool, - ) - - self._transform_and_publish( - topic=mqtt_topics.WINDOWS_DRIVER, - value=basic_vehicle_status.driverWindow, - transform=int_to_bool, - ) + if is_valid_mileage: + self._transform_and_publish( + topic=mqtt_topics.WINDOWS_DRIVER, + value=basic_vehicle_status.driverWindow, + transform=int_to_bool, + ) - self._transform_and_publish( - topic=mqtt_topics.WINDOWS_PASSENGER, - value=basic_vehicle_status.passengerWindow, - transform=int_to_bool, - ) + self._transform_and_publish( + topic=mqtt_topics.WINDOWS_PASSENGER, + value=basic_vehicle_status.passengerWindow, + transform=int_to_bool, + ) - self._transform_and_publish( - topic=mqtt_topics.WINDOWS_REAR_LEFT, - value=basic_vehicle_status.rearLeftWindow, - transform=int_to_bool, - ) + self._transform_and_publish( + topic=mqtt_topics.WINDOWS_REAR_LEFT, + value=basic_vehicle_status.rearLeftWindow, + transform=int_to_bool, + ) - self._transform_and_publish( - topic=mqtt_topics.WINDOWS_REAR_RIGHT, - value=basic_vehicle_status.rearRightWindow, - transform=int_to_bool, - ) + self._transform_and_publish( + topic=mqtt_topics.WINDOWS_REAR_RIGHT, + value=basic_vehicle_status.rearRightWindow, + transform=int_to_bool, + ) self._transform_and_publish( topic=mqtt_topics.WINDOWS_SUN_ROOF, @@ -200,13 +202,6 @@ def on_basic_vehicle_status( validator=lambda x: value_in_range(x, 0, 255), ) - self._transform_and_publish( - topic=mqtt_topics.DRIVETRAIN_MILEAGE, - value=basic_vehicle_status.mileage, - validator=lambda x: value_in_range(x, 1, 2147483647), - transform=lambda x: x / 10.0, - ) - # Standard fossil fuels vehicles self._transform_and_publish( topic=mqtt_topics.DRIVETRAIN_FOSSIL_FUEL_RANGE,