From 8b812d3625e8d1b9649872b24ce81d827f18561b Mon Sep 17 00:00:00 2001 From: Giovanni Condello Date: Mon, 11 May 2026 21:28:01 +0200 Subject: [PATCH 1/2] feat: add SOC kWh fallback for vehicles without realtimePower For car models (e.g. MGS5) where RvsChargeStatus.realtimePower is always None or 0, DRIVETRAIN_SOC_KWH was never published. Add extract_soc_kwh(charge_status, soc) to the extractors module, following the same pattern as extract_soc / extract_electric_range. It prefers the realtimePower-derived value when valid (> 0), and falls back to soc% * real_total_battery_capacity otherwise. Publishing moves from RvsChargeStatusPublisher to update_data_conflicting_in_vehicle_and_bms in VehicleState, where both the charge result and the resolved SoC% are in scope. --- src/extractors/__init__.py | 39 +++++++++++ .../charge/chrg_mgmt_data_resp.py | 4 ++ .../charge/rvs_charge_status.py | 21 +++--- src/vehicle.py | 9 ++- src/vehicle_info.py | 18 ++++- .../test_rvs_charge_status.py | 69 +++++++++++++++++++ tests/test_extractors.py | 55 +++++++++++++++ tests/test_vehicle_handler.py | 58 ++++++++++++++-- tests/test_vehicle_state.py | 1 + 9 files changed, 257 insertions(+), 17 deletions(-) create mode 100644 tests/status_publisher/test_rvs_charge_status.py create mode 100644 tests/test_extractors.py diff --git a/src/extractors/__init__.py b/src/extractors/__init__.py index 4eb2fd06..2ebd343d 100644 --- a/src/extractors/__init__.py +++ b/src/extractors/__init__.py @@ -39,6 +39,39 @@ def extract_electric_range( return None +def extract_soc_kwh( + charge_status: ChrgMgmtDataRespProcessingResult | None, + soc: float | None, +) -> float | None: + if ( + charge_status is not None + and (raw_soc_kwh := charge_status.soc_kwh) is not None + and (soc_kwh := __validate_and_convert_soc_kwh(raw_soc_kwh)) is not None + ): + LOG.debug("SoC kWh derived from realtimePower") + return soc_kwh + + if ( + soc is not None + and charge_status is not None + and ( + capacity := __validate_and_convert_soc_kwh( + charge_status.real_total_battery_capacity + ) + ) + is not None + ): + LOG.debug( + "SoC kWh computed from SoC%%=%s and capacity=%s kWh", + soc, + capacity, + ) + return round(soc / 100.0 * capacity, 2) + + LOG.warning("Could not extract a valid SoC kWh") + return None + + def extract_soc( vehicle_status: VehicleStatusRespProcessingResult, charge_status: ChrgMgmtDataRespProcessingResult | None, @@ -71,3 +104,9 @@ def __validate_and_convert_soc(raw_value: float) -> float | None: if value_in_range(raw_value, 0, 100.0, is_max_excl=False): return raw_value return None + + +def __validate_and_convert_soc_kwh(raw_value: float) -> float | None: + if raw_value > 0: + return raw_value + return None diff --git a/src/status_publisher/charge/chrg_mgmt_data_resp.py b/src/status_publisher/charge/chrg_mgmt_data_resp.py index 867bd386..a8066f8e 100644 --- a/src/status_publisher/charge/chrg_mgmt_data_resp.py +++ b/src/status_publisher/charge/chrg_mgmt_data_resp.py @@ -41,6 +41,7 @@ class ChrgMgmtDataRespProcessingResult: real_total_battery_capacity: float raw_soc: int | None raw_fuel_range_elec: int | None + soc_kwh: float | None class ChrgMgmtDataRespPublisher( @@ -112,4 +113,7 @@ def publish( raw_fuel_range_elec=charge_status_result.raw_fuel_range_elec if charge_status_result is not None else None, + soc_kwh=charge_status_result.soc_kwh + if charge_status_result is not None + else None, ) diff --git a/src/status_publisher/charge/rvs_charge_status.py b/src/status_publisher/charge/rvs_charge_status.py index 98898cdb..be709ba5 100644 --- a/src/status_publisher/charge/rvs_charge_status.py +++ b/src/status_publisher/charge/rvs_charge_status.py @@ -21,6 +21,7 @@ class RvsChargeStatusProcessingResult: real_total_battery_capacity: float raw_fuel_range_elec: int | None + soc_kwh: float | None class RvsChargeStatusPublisher( @@ -38,7 +39,10 @@ def update_total_mileage(self, raw_mileage: int) -> None: def _is_valid_partial_mileage(self, raw_value: int) -> bool: if not value_in_range(raw_value, 0, 65535): return False - if self._last_total_mileage_raw is not None and raw_value > self._last_total_mileage_raw: + if ( + self._last_total_mileage_raw is not None + and raw_value > self._last_total_mileage_raw + ): LOG.warning( "Partial mileage %d exceeds total mileage %d, skipping", raw_value, @@ -98,13 +102,13 @@ def publish( validator=lambda x: x > 0, ) - self._transform_and_publish( - topic=mqtt_topics.DRIVETRAIN_SOC_KWH, - value=charge_status.realtimePower, - transform=lambda p: round( - (battery_capacity_correction_factor * p) / 10.0, 2 - ), - ) + soc_kwh: float | None = None + if charge_status.realtimePower: + soc_kwh = round( + (battery_capacity_correction_factor * charge_status.realtimePower) + / 10.0, + 2, + ) self._transform_and_publish( topic=mqtt_topics.DRIVETRAIN_LAST_CHARGE_ENDING_POWER, @@ -136,6 +140,7 @@ def publish( return RvsChargeStatusProcessingResult( real_total_battery_capacity=real_total_battery_capacity, raw_fuel_range_elec=charge_status.fuelRangeElec, + soc_kwh=soc_kwh, ) def get_actual_battery_capacity( diff --git a/src/vehicle.py b/src/vehicle.py index 731293d2..8a36e403 100644 --- a/src/vehicle.py +++ b/src/vehicle.py @@ -15,7 +15,7 @@ TargetBatteryCode, ) -from extractors import extract_electric_range, extract_soc +from extractors import extract_electric_range, extract_soc, extract_soc_kwh import mqtt_topics from publisher.core import Publishable from status_publisher.charge.chrg_mgmt_data_resp import ( @@ -659,6 +659,13 @@ def update_data_conflicting_in_vehicle_and_bms( value=soc, ) + soc_kwh = extract_soc_kwh(charge_status, soc) + if soc_kwh is not None: + self.__publish( + topic=mqtt_topics.DRIVETRAIN_SOC_KWH, + value=soc_kwh, + ) + @property def user_timezone(self) -> ZoneInfo | None: return self.__user_timezone diff --git a/src/vehicle_info.py b/src/vehicle_info.py index bd174bf2..684f46f0 100644 --- a/src/vehicle_info.py +++ b/src/vehicle_info.py @@ -64,12 +64,16 @@ def get_ac_temperature_idx(self, remote_ac_temperature: int) -> int: def min_ac_temperature(self) -> int: if self.series.startswith("EH32"): return 17 + elif self.series.startswith("MZS3E"): + return 16 return 16 @property def max_ac_temperature(self) -> int: if self.series.startswith("EH32"): - return 33 + return 31 + elif self.series.startswith("MZS3E"): + return 31 return 28 def __get_property_by_code(self, property_name: str) -> str | None: @@ -122,6 +126,8 @@ def real_battery_capacity(self) -> float | None: result = self.__mg5_real_battery_capacity elif self.series.startswith("ZS EV"): result = self.__zs_ev_real_battery_capacity + elif self.series.startswith("MZS3E"): + result = self.__mgs5_real_battery_capacity if result is None: LOG.warning( @@ -141,6 +147,16 @@ def __mg4_real_battery_capacity(self) -> float | None: # MG4 with LFP battery return 51.0 + @property + def __mgs5_real_battery_capacity(self) -> float | None: + # From the datasheet + # Battery pack type 1 (49kWh) + # Battery pack type 2 (62.2kWh) + # Battery pack type 3 (64kWh) + if self.supports_target_soc: + return 64.0 + return 49.0 + @property def __cyberster_real_battery_capacity(self) -> float | None: # Model: MG Cyberster diff --git a/tests/status_publisher/test_rvs_charge_status.py b/tests/status_publisher/test_rvs_charge_status.py new file mode 100644 index 00000000..27378e18 --- /dev/null +++ b/tests/status_publisher/test_rvs_charge_status.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +import unittest + +import pytest +from saic_ismart_client_ng.api.vehicle.schema import VehicleModelConfiguration, VinInfo +from saic_ismart_client_ng.api.vehicle_charging.schema import RvsChargeStatus + +from configuration import Configuration +from status_publisher.charge.rvs_charge_status import RvsChargeStatusPublisher +from tests.common_mocks import VIN +from tests.mocks import MessageCapturingConsolePublisher +from vehicle_info import VehicleInfo + +# EH32 S with BType=1 → real_battery_capacity = 64.0, raw=72.5 kWh +REAL_CAPACITY = 64.0 +RAW_CAPACITY = 72.5 +CORRECTION = REAL_CAPACITY / RAW_CAPACITY + + +def _make_publisher() -> tuple[ + RvsChargeStatusPublisher, MessageCapturingConsolePublisher +]: + config = Configuration() + config.anonymized_publishing = False + pub = MessageCapturingConsolePublisher(config) + vin_info = VinInfo() + vin_info.vin = VIN + vin_info.series = "EH32 S" + vin_info.modelName = "MG4 Electric" + vin_info.modelYear = "2022" + vin_info.vehicleModelConfiguration = [ + VehicleModelConfiguration("BType", "Battery", "1"), + ] + vehicle_info = VehicleInfo(vin_info, None) + return RvsChargeStatusPublisher(vehicle_info, pub, f"/vehicles/{VIN}"), pub + + +class TestRvsChargeStatusSocKwh(unittest.TestCase): + def setUp(self) -> None: + self.publisher, _ = _make_publisher() + + def test_soc_kwh_present_when_realtime_power_set(self) -> None: + charge_status = RvsChargeStatus( + realtimePower=int((42.0 / CORRECTION) * 10), + totalBatteryCapacity=int(RAW_CAPACITY * 10), + ) + result = self.publisher.publish(charge_status) + + assert result.soc_kwh is not None + assert result.soc_kwh == pytest.approx(42.0, abs=0.1) + + def test_soc_kwh_none_when_realtime_power_is_none(self) -> None: + charge_status = RvsChargeStatus( + realtimePower=None, + totalBatteryCapacity=int(RAW_CAPACITY * 10), + ) + result = self.publisher.publish(charge_status) + + assert result.soc_kwh is None + + def test_soc_kwh_none_when_realtime_power_is_zero(self) -> None: + charge_status = RvsChargeStatus( + realtimePower=0, + totalBatteryCapacity=int(RAW_CAPACITY * 10), + ) + result = self.publisher.publish(charge_status) + + assert result.soc_kwh is None diff --git a/tests/test_extractors.py b/tests/test_extractors.py new file mode 100644 index 00000000..e44be3b2 --- /dev/null +++ b/tests/test_extractors.py @@ -0,0 +1,55 @@ +from __future__ import annotations + +import pytest + +from extractors import extract_soc_kwh +from status_publisher.charge.chrg_mgmt_data_resp import ChrgMgmtDataRespProcessingResult + + +def _make_charge_result( + *, + soc_kwh: float | None = None, + real_total_battery_capacity: float = 64.0, +) -> ChrgMgmtDataRespProcessingResult: + return ChrgMgmtDataRespProcessingResult( + charge_current_limit=None, + target_soc=None, + scheduled_charging=None, + is_charging=None, + remaining_charging_time=None, + power=None, + real_total_battery_capacity=real_total_battery_capacity, + raw_soc=None, + raw_fuel_range_elec=None, + soc_kwh=soc_kwh, + ) + + +class TestExtractSocKwh: + def test_prefers_realtime_power_soc_kwh(self) -> None: + result = extract_soc_kwh(_make_charge_result(soc_kwh=42.0), soc=80.0) + assert result == pytest.approx(42.0) + + def test_fallback_to_soc_times_capacity(self) -> None: + # 80% of 64 kWh = 51.2 kWh + result = extract_soc_kwh(_make_charge_result(soc_kwh=None), soc=80.0) + assert result == pytest.approx(51.2) + + def test_fallback_returns_none_when_soc_is_none(self) -> None: + result = extract_soc_kwh(_make_charge_result(soc_kwh=None), soc=None) + assert result is None + + def test_fallback_returns_none_when_charge_status_is_none(self) -> None: + result = extract_soc_kwh(None, soc=80.0) + assert result is None + + def test_fallback_returns_none_when_capacity_is_zero(self) -> None: + result = extract_soc_kwh( + _make_charge_result(soc_kwh=None, real_total_battery_capacity=0.0), soc=80.0 + ) + assert result is None + + def test_fallback_used_when_soc_kwh_is_zero(self) -> None: + # soc_kwh=0 is not a valid primary reading; fall back to soc * capacity + result = extract_soc_kwh(_make_charge_result(soc_kwh=0.0), soc=80.0) + assert result == pytest.approx(51.2) diff --git a/tests/test_vehicle_handler.py b/tests/test_vehicle_handler.py index 9d77622e..b6247664 100644 --- a/tests/test_vehicle_handler.py +++ b/tests/test_vehicle_handler.py @@ -96,7 +96,7 @@ def setUp(self) -> None: vehicle_info = VehicleInfo(vin_info, None) account_prefix = f"/vehicles/{VIN}" scheduler = BlockingScheduler() - vehicle_state = VehicleState( + self.vehicle_state = VehicleState( self.publisher, scheduler, account_prefix, vehicle_info ) mock_relogin_handler = ReloginHandler( @@ -108,7 +108,7 @@ def setUp(self) -> None: self.saicapi, self.publisher, vehicle_info, - vehicle_state, + self.vehicle_state, ) async def test_update_vehicle_status(self) -> None: @@ -308,10 +308,6 @@ async def test_update_charge_status(self) -> None: ), DRIVETRAIN_MILEAGE_SINCE_LAST_CHARGE, ) - self.assert_mqtt_topic( - TestVehicleHandler.get_topic(mqtt_topics.DRIVETRAIN_SOC_KWH), - DRIVETRAIN_SOC_KWH, - ) self.assert_mqtt_topic( TestVehicleHandler.get_topic(mqtt_topics.DRIVETRAIN_CHARGING_TYPE), DRIVETRAIN_CHARGING_TYPE, @@ -359,7 +355,6 @@ async def test_update_charge_status(self) -> None: "/vehicles/vin10000000000000/drivetrain/remainingChargingTime", "/vehicles/vin10000000000000/refresh/lastChargeState", "/vehicles/vin10000000000000/drivetrain/totalBatteryCapacity", - "/vehicles/vin10000000000000/drivetrain/soc_kwh", "/vehicles/vin10000000000000/drivetrain/lastChargeEndingPower", "/vehicles/vin10000000000000/drivetrain/batteryHeating", "/vehicles/vin10000000000000/drivetrain/chargingCableLock", @@ -397,6 +392,55 @@ async def test_should_not_publish_same_data_twice(self) -> None: f"Some topics have been published from both car state and BMS state: {common_data!s}" ) + async def test_soc_kwh_published_after_full_cycle(self) -> None: + with ( + patch.object(self.saicapi, "get_vehicle_status") as mock_get_vehicle_status, + patch.object( + self.saicapi, "get_vehicle_charging_management_data" + ) as mock_get_charge, + ): + mock_get_vehicle_status.return_value = get_mock_vehicle_status_resp() + mock_get_charge.return_value = get_mock_charge_management_data_resp() + + _, vehicle_result = await self.vehicle_handler.update_vehicle_status() + _, charge_result = await self.vehicle_handler.update_charge_status() + + self.publisher.map.clear() + self.vehicle_state.update_data_conflicting_in_vehicle_and_bms( + vehicle_result, charge_result + ) + + self.assert_mqtt_topic( + TestVehicleHandler.get_topic(mqtt_topics.DRIVETRAIN_SOC_KWH), + DRIVETRAIN_SOC_KWH, + ) + + async def test_soc_kwh_fallback_when_realtime_power_missing(self) -> None: + charge_resp = get_mock_charge_management_data_resp() + charge_resp.rvsChargeStatus.realtimePower = None # type: ignore[union-attr] + + with ( + patch.object(self.saicapi, "get_vehicle_status") as mock_get_vehicle_status, + patch.object( + self.saicapi, "get_vehicle_charging_management_data" + ) as mock_get_charge, + ): + mock_get_vehicle_status.return_value = get_mock_vehicle_status_resp() + mock_get_charge.return_value = charge_resp + + _, vehicle_result = await self.vehicle_handler.update_vehicle_status() + _, charge_result = await self.vehicle_handler.update_charge_status() + + self.publisher.map.clear() + self.vehicle_state.update_data_conflicting_in_vehicle_and_bms( + vehicle_result, charge_result + ) + + soc_kwh_topic = TestVehicleHandler.get_topic(mqtt_topics.DRIVETRAIN_SOC_KWH) + assert soc_kwh_topic in self.publisher.map + # Fallback: DRIVETRAIN_SOC_BMS (96.3%) * 64.0 kWh ≈ 61.6 kWh + assert self.publisher.map[soc_kwh_topic] == pytest.approx(61.6, abs=0.1) + def assert_mqtt_topic(self, topic: str, value: Any) -> None: mqtt_map = self.publisher.map if topic in mqtt_map: diff --git a/tests/test_vehicle_state.py b/tests/test_vehicle_state.py index faff700b..b2c9d070 100644 --- a/tests/test_vehicle_state.py +++ b/tests/test_vehicle_state.py @@ -112,6 +112,7 @@ async def test_update_soc_with_bms_data(self) -> None: "/vehicles/vin10000000000000/refresh/lastActivity", "/vehicles/vin10000000000000/drivetrain/soc", "/vehicles/vin10000000000000/drivetrain/range", + "/vehicles/vin10000000000000/drivetrain/soc_kwh", } assert expected_topics == set(self.publisher.map.keys()) From dd0dc0b05d4971e5ec0905443ce9aa6b10ce2857 Mon Sep 17 00:00:00 2001 From: Giovanni Condello Date: Mon, 11 May 2026 21:35:37 +0200 Subject: [PATCH 2/2] chore: add pre-commit dev dependency and apply linting fixes --- poetry.lock | 207 +++++++++++++++++++++++++++- pyproject.toml | 1 + src/handlers/message.py | 22 ++- src/integrations/openwb/__init__.py | 4 +- src/vehicle_info.py | 6 +- tests/test_ha_discovery_windows.py | 12 +- 6 files changed, 230 insertions(+), 22 deletions(-) diff --git a/poetry.lock b/poetry.lock index 3e6be2d0..04bd68a0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.3.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.4.1 and should not be changed by hand. [[package]] name = "anyio" @@ -71,6 +71,18 @@ files = [ {file = "certifi-2026.2.25.tar.gz", hash = "sha256:e887ab5cee78ea814d3472169153c2d12cd43b14bd03329a39a9c6e2e80bfba7"}, ] +[[package]] +name = "cfgv" +version = "3.5.0" +description = "Validate configuration and produce human readable error messages." +optional = false +python-versions = ">=3.10" +groups = ["dev"] +files = [ + {file = "cfgv-3.5.0-py2.py3-none-any.whl", hash = "sha256:a8dc6b26ad22ff227d2634a65cb388215ce6cc96bbcc5cfde7641ae87e8dacc0"}, + {file = "cfgv-3.5.0.tar.gz", hash = "sha256:d5b1034354820651caa73ede66a6294d6e95c1b00acc5e9b098e917404669132"}, +] + [[package]] name = "colorama" version = "0.4.6" @@ -234,6 +246,30 @@ files = [ graph = ["objgraph (>=1.7.2)"] profile = ["gprof2dot (>=2022.7.29)"] +[[package]] +name = "distlib" +version = "0.4.0" +description = "Distribution utilities" +optional = false +python-versions = "*" +groups = ["dev"] +files = [ + {file = "distlib-0.4.0-py2.py3-none-any.whl", hash = "sha256:9659f7d87e46584a30b5780e43ac7a2143098441670ff0a49d5f9034c54a6c16"}, + {file = "distlib-0.4.0.tar.gz", hash = "sha256:feec40075be03a04501a973d81f633735b4b69f98b05450592310c0f401a4e0d"}, +] + +[[package]] +name = "filelock" +version = "3.29.0" +description = "A platform independent file lock." +optional = false +python-versions = ">=3.10" +groups = ["dev"] +files = [ + {file = "filelock-3.29.0-py3-none-any.whl", hash = "sha256:96f5f6344709aa1572bbf631c640e4ebeeb519e08da902c39a001882f30ac258"}, + {file = "filelock-3.29.0.tar.gz", hash = "sha256:69974355e960702e789734cb4871f884ea6fe50bd8404051a3530bc07809cf90"}, +] + [[package]] name = "gmqtt" version = "0.7.0" @@ -308,6 +344,21 @@ http2 = ["h2 (>=3,<5)"] socks = ["socksio (==1.*)"] zstd = ["zstandard (>=0.18.0)"] +[[package]] +name = "identify" +version = "2.6.19" +description = "File identification library for Python" +optional = false +python-versions = ">=3.10" +groups = ["dev"] +files = [ + {file = "identify-2.6.19-py2.py3-none-any.whl", hash = "sha256:20e6a87f786f768c092a721ad107fc9df0eb89347be9396cadf3f4abbd1fb78a"}, + {file = "identify-2.6.19.tar.gz", hash = "sha256:6be5020c38fcb07da56c53733538a3081ea5aa70d36a156f83044bfbf9173842"}, +] + +[package.extras] +license = ["ukkonen"] + [[package]] name = "idna" version = "3.11" @@ -566,6 +617,18 @@ files = [ {file = "mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"}, ] +[[package]] +name = "nodeenv" +version = "1.10.0" +description = "Node.js virtual environment builder" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +groups = ["dev"] +files = [ + {file = "nodeenv-1.10.0-py2.py3-none-any.whl", hash = "sha256:5bb13e3eed2923615535339b3c620e76779af4cb4c6a90deccc9e36b274d3827"}, + {file = "nodeenv-1.10.0.tar.gz", hash = "sha256:996c191ad80897d076bdfba80a41994c2b47c68e224c542b48feba42ba00f8bb"}, +] + [[package]] name = "packaging" version = "26.0" @@ -624,6 +687,25 @@ files = [ dev = ["pre-commit", "tox"] testing = ["coverage", "pytest", "pytest-benchmark"] +[[package]] +name = "pre-commit" +version = "4.6.0" +description = "A framework for managing and maintaining multi-language pre-commit hooks." +optional = false +python-versions = ">=3.10" +groups = ["dev"] +files = [ + {file = "pre_commit-4.6.0-py2.py3-none-any.whl", hash = "sha256:e2cf246f7299edcabcf15f9b0571fdce06058527f0a06535068a86d38089f29b"}, + {file = "pre_commit-4.6.0.tar.gz", hash = "sha256:718d2208cef53fdc38206e40524a6d4d9576d103eb16f0fec11c875e7716e9d9"}, +] + +[package.dependencies] +cfgv = ">=2.0.0" +identify = ">=1.0.0" +nodeenv = ">=0.11.1" +pyyaml = ">=5.1" +virtualenv = ">=20.10.0" + [[package]] name = "pycryptodome" version = "3.23.0" @@ -795,6 +877,26 @@ pytest = ">=6.2.5" [package.extras] dev = ["pre-commit", "pytest-asyncio", "tox"] +[[package]] +name = "python-discovery" +version = "1.3.0" +description = "Python interpreter discovery" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "python_discovery-1.3.0-py3-none-any.whl", hash = "sha256:441d9ced3dfce36e113beb35ca302c71c7ef06f3c0f9c227a0b9bb3bd49b9e9f"}, + {file = "python_discovery-1.3.0.tar.gz", hash = "sha256:d098f1e86be5d45fe4d14bf1029294aabbd332f4321179dec85e76cddce834b0"}, +] + +[package.dependencies] +filelock = ">=3.15.4" +platformdirs = ">=4.3.6,<5" + +[package.extras] +docs = ["furo (>=2025.12.19)", "sphinx (>=9.1)", "sphinx-autodoc-typehints (>=3.6.3)", "sphinxcontrib-mermaid (>=2)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.5.4)", "pytest (>=8.3.5)", "pytest-mock (>=3.14)", "setuptools (>=75.1)"] + [[package]] name = "python-dotenv" version = "1.2.2" @@ -810,6 +912,89 @@ files = [ [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "pyyaml" +version = "6.0.3" +description = "YAML parser and emitter for Python" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "PyYAML-6.0.3-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:c2514fceb77bc5e7a2f7adfaa1feb2fb311607c9cb518dbc378688ec73d8292f"}, + {file = "PyYAML-6.0.3-cp38-cp38-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9c57bb8c96f6d1808c030b1687b9b5fb476abaa47f0db9c0101f5e9f394e97f4"}, + {file = "PyYAML-6.0.3-cp38-cp38-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:efd7b85f94a6f21e4932043973a7ba2613b059c4a000551892ac9f1d11f5baf3"}, + {file = "PyYAML-6.0.3-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:22ba7cfcad58ef3ecddc7ed1db3409af68d023b7f940da23c6c2a1890976eda6"}, + {file = "PyYAML-6.0.3-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:6344df0d5755a2c9a276d4473ae6b90647e216ab4757f8426893b5dd2ac3f369"}, + {file = "PyYAML-6.0.3-cp38-cp38-win32.whl", hash = "sha256:3ff07ec89bae51176c0549bc4c63aa6202991da2d9a6129d7aef7f1407d3f295"}, + {file = "PyYAML-6.0.3-cp38-cp38-win_amd64.whl", hash = "sha256:5cf4e27da7e3fbed4d6c3d8e797387aaad68102272f8f9752883bc32d61cb87b"}, + {file = "pyyaml-6.0.3-cp310-cp310-macosx_10_13_x86_64.whl", hash = "sha256:214ed4befebe12df36bcc8bc2b64b396ca31be9304b8f59e25c11cf94a4c033b"}, + {file = "pyyaml-6.0.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:02ea2dfa234451bbb8772601d7b8e426c2bfa197136796224e50e35a78777956"}, + {file = "pyyaml-6.0.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b30236e45cf30d2b8e7b3e85881719e98507abed1011bf463a8fa23e9c3e98a8"}, + {file = "pyyaml-6.0.3-cp310-cp310-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:66291b10affd76d76f54fad28e22e51719ef9ba22b29e1d7d03d6777a9174198"}, + {file = "pyyaml-6.0.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0b"}, + {file = "pyyaml-6.0.3-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:418cf3f2111bc80e0933b2cd8cd04f286338bb88bdc7bc8e6dd775ebde60b5e0"}, + {file = "pyyaml-6.0.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:5e0b74767e5f8c593e8c9b5912019159ed0533c70051e9cce3e8b6aa699fcd69"}, + {file = "pyyaml-6.0.3-cp310-cp310-win32.whl", hash = "sha256:28c8d926f98f432f88adc23edf2e6d4921ac26fb084b028c733d01868d19007e"}, + {file = "pyyaml-6.0.3-cp310-cp310-win_amd64.whl", hash = "sha256:bdb2c67c6c1390b63c6ff89f210c8fd09d9a1217a465701eac7316313c915e4c"}, + {file = "pyyaml-6.0.3-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e"}, + {file = "pyyaml-6.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824"}, + {file = "pyyaml-6.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c"}, + {file = "pyyaml-6.0.3-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:850774a7879607d3a6f50d36d04f00ee69e7fc816450e5f7e58d7f17f1ae5c00"}, + {file = "pyyaml-6.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d"}, + {file = "pyyaml-6.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1d37d57ad971609cf3c53ba6a7e365e40660e3be0e5175fa9f2365a379d6095a"}, + {file = "pyyaml-6.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:37503bfbfc9d2c40b344d06b2199cf0e96e97957ab1c1b546fd4f87e53e5d3e4"}, + {file = "pyyaml-6.0.3-cp311-cp311-win32.whl", hash = "sha256:8098f252adfa6c80ab48096053f512f2321f0b998f98150cea9bd23d83e1467b"}, + {file = "pyyaml-6.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:9f3bfb4965eb874431221a3ff3fdcddc7e74e3b07799e0e84ca4a0f867d449bf"}, + {file = "pyyaml-6.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196"}, + {file = "pyyaml-6.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0"}, + {file = "pyyaml-6.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28"}, + {file = "pyyaml-6.0.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c"}, + {file = "pyyaml-6.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc"}, + {file = "pyyaml-6.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e"}, + {file = "pyyaml-6.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea"}, + {file = "pyyaml-6.0.3-cp312-cp312-win32.whl", hash = "sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5"}, + {file = "pyyaml-6.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b"}, + {file = "pyyaml-6.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd"}, + {file = "pyyaml-6.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8"}, + {file = "pyyaml-6.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1"}, + {file = "pyyaml-6.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c"}, + {file = "pyyaml-6.0.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5"}, + {file = "pyyaml-6.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6"}, + {file = "pyyaml-6.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6"}, + {file = "pyyaml-6.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be"}, + {file = "pyyaml-6.0.3-cp313-cp313-win32.whl", hash = "sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26"}, + {file = "pyyaml-6.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c"}, + {file = "pyyaml-6.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb"}, + {file = "pyyaml-6.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac"}, + {file = "pyyaml-6.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310"}, + {file = "pyyaml-6.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7"}, + {file = "pyyaml-6.0.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788"}, + {file = "pyyaml-6.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5"}, + {file = "pyyaml-6.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764"}, + {file = "pyyaml-6.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35"}, + {file = "pyyaml-6.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac"}, + {file = "pyyaml-6.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3"}, + {file = "pyyaml-6.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3"}, + {file = "pyyaml-6.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba"}, + {file = "pyyaml-6.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c"}, + {file = "pyyaml-6.0.3-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702"}, + {file = "pyyaml-6.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c"}, + {file = "pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065"}, + {file = "pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65"}, + {file = "pyyaml-6.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9"}, + {file = "pyyaml-6.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b"}, + {file = "pyyaml-6.0.3-cp39-cp39-macosx_10_13_x86_64.whl", hash = "sha256:b865addae83924361678b652338317d1bd7e79b1f4596f96b96c77a5a34b34da"}, + {file = "pyyaml-6.0.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c3355370a2c156cffb25e876646f149d5d68f5e0a3ce86a5084dd0b64a994917"}, + {file = "pyyaml-6.0.3-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3c5677e12444c15717b902a5798264fa7909e41153cdf9ef7ad571b704a63dd9"}, + {file = "pyyaml-6.0.3-cp39-cp39-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5ed875a24292240029e4483f9d4a4b8a1ae08843b9c54f43fcc11e404532a8a5"}, + {file = "pyyaml-6.0.3-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0150219816b6a1fa26fb4699fb7daa9caf09eb1999f3b70fb6e786805e80375a"}, + {file = "pyyaml-6.0.3-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:fa160448684b4e94d80416c0fa4aac48967a969efe22931448d853ada8baf926"}, + {file = "pyyaml-6.0.3-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:27c0abcb4a5dac13684a37f76e701e054692a9b2d3064b70f5e4eb54810553d7"}, + {file = "pyyaml-6.0.3-cp39-cp39-win32.whl", hash = "sha256:1ebe39cb5fc479422b83de611d14e2c0d3bb2a18bbcb01f229ab3cfbd8fee7a0"}, + {file = "pyyaml-6.0.3-cp39-cp39-win_amd64.whl", hash = "sha256:2e71d11abed7344e42a8849600193d15b6def118602c4c176f748e4583246007"}, + {file = "pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f"}, +] + [[package]] name = "ruff" version = "0.15.5" @@ -928,7 +1113,25 @@ tzdata = {version = "*", markers = "platform_system == \"Windows\""} [package.extras] devenv = ["check-manifest", "pytest (>=4.3)", "pytest-cov", "pytest-mock (>=3.3)", "zest.releaser"] +[[package]] +name = "virtualenv" +version = "21.3.1" +description = "Virtual Python Environment builder" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "virtualenv-21.3.1-py3-none-any.whl", hash = "sha256:d1a71cf58f2f9228fff23a1f6ec15d39785c6b32e03658d104974247145edd35"}, + {file = "virtualenv-21.3.1.tar.gz", hash = "sha256:c2305bc1fddeec40699b8370d13f8d431b0701f00ce895061ce493aeded4426b"}, +] + +[package.dependencies] +distlib = ">=0.3.7,<1" +filelock = {version = ">=3.24.2,<4", markers = "python_version >= \"3.10\""} +platformdirs = ">=3.9.1,<5" +python-discovery = ">=1.2.2" + [metadata] lock-version = "2.1" python-versions = ">=3.12,<4.0" -content-hash = "895b2fe59d35a1326b819dc68c6a88aac237d81fd60c16076a13c4801e17dee2" +content-hash = "ba4f444f330a6cb58a06926a1c2701c544ffeaeda02107641361b7abaa61e4af" diff --git a/pyproject.toml b/pyproject.toml index c191824f..afda254d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ pytest-asyncio = "^1.2.0" pytest-mock = "^3.14.0" mypy = "^1.15.0" pylint = "^4.0.0" +pre-commit = "^4.6.0" [tool.poetry.dependencies] saic-ismart-client-ng = { develop = true } diff --git a/src/handlers/message.py b/src/handlers/message.py index ea43b6fb..64bf508a 100644 --- a/src/handlers/message.py +++ b/src/handlers/message.py @@ -54,10 +54,13 @@ async def __polling(self) -> None: if ( latest_message is not None and latest_message.messageId != self.last_message_id - and ensure_datetime_aware(latest_message.message_time) > self.last_message_ts + and ensure_datetime_aware(latest_message.message_time) + > self.last_message_ts ): self.last_message_id = latest_message.messageId - self.last_message_ts = ensure_datetime_aware(latest_message.message_time) + self.last_message_ts = ensure_datetime_aware( + latest_message.message_time + ) LOG.info( f"{latest_message.title} detected at {latest_message.message_time}" ) @@ -107,7 +110,8 @@ async def __get_all_alarm_messages(self) -> list[MessageEntity]: oldest_message = self.__get_oldest_message(all_messages) if ( oldest_message is not None - and ensure_datetime_aware(oldest_message.message_time) < self.last_message_ts + and ensure_datetime_aware(oldest_message.message_time) + < self.last_message_ts ): return all_messages except SaicLogoutException: @@ -121,7 +125,9 @@ async def __get_all_alarm_messages(self) -> list[MessageEntity]: return all_messages finally: idx = idx + 1 - LOG.warning("Reached max page limit (%d) while fetching alarm messages", max_pages) + LOG.warning( + "Reached max page limit (%d) while fetching alarm messages", max_pages + ) return all_messages async def __delete_message(self, message: MessageEntity) -> None: @@ -174,7 +180,9 @@ def __get_latest_message( ) -> MessageEntity | None: if len(vehicle_start_messages) == 0: return None - return max(vehicle_start_messages, key=lambda m: ensure_datetime_aware(m.message_time)) + return max( + vehicle_start_messages, key=lambda m: ensure_datetime_aware(m.message_time) + ) @staticmethod def __get_oldest_message( @@ -182,4 +190,6 @@ def __get_oldest_message( ) -> MessageEntity | None: if len(vehicle_start_messages) == 0: return None - return min(vehicle_start_messages, key=lambda m: ensure_datetime_aware(m.message_time)) + return min( + vehicle_start_messages, key=lambda m: ensure_datetime_aware(m.message_time) + ) diff --git a/src/integrations/openwb/__init__.py b/src/integrations/openwb/__init__.py index fbf7ea33..ece65830 100644 --- a/src/integrations/openwb/__init__.py +++ b/src/integrations/openwb/__init__.py @@ -65,7 +65,9 @@ def update_openwb( soc_ts_topic = self.__charging_station.soc_ts_topic if soc_ts_topic is not None: soc_ts = int(datetime.datetime.now(tz=datetime.UTC).timestamp()) - LOG.info("OpenWB Integration published SoC timestamp to %s", soc_ts_topic) + LOG.info( + "OpenWB Integration published SoC timestamp to %s", soc_ts_topic + ) self.__publisher.publish_int( key=soc_ts_topic, value=soc_ts, diff --git a/src/vehicle_info.py b/src/vehicle_info.py index 684f46f0..2e4e2f95 100644 --- a/src/vehicle_info.py +++ b/src/vehicle_info.py @@ -64,15 +64,13 @@ def get_ac_temperature_idx(self, remote_ac_temperature: int) -> int: def min_ac_temperature(self) -> int: if self.series.startswith("EH32"): return 17 - elif self.series.startswith("MZS3E"): + if self.series.startswith("MZS3E"): return 16 return 16 @property def max_ac_temperature(self) -> int: - if self.series.startswith("EH32"): - return 31 - elif self.series.startswith("MZS3E"): + if self.series.startswith("EH32") or self.series.startswith("MZS3E"): return 31 return 28 diff --git a/tests/test_ha_discovery_windows.py b/tests/test_ha_discovery_windows.py index 8d2be70d..cff3e6d2 100644 --- a/tests/test_ha_discovery_windows.py +++ b/tests/test_ha_discovery_windows.py @@ -43,9 +43,7 @@ def _make_discovery( configs = [ VehicleModelConfiguration("BATTERY", "BATTERY", "1"), VehicleModelConfiguration("BType", "Battery", "1"), - VehicleModelConfiguration( - "S35", "Sunroof", "1" if has_sunroof else "0" - ), + VehicleModelConfiguration("S35", "Sunroof", "1" if has_sunroof else "0"), ] vin_info.vehicleModelConfiguration = configs vehicle_info = VehicleInfo(vin_info, None) @@ -97,9 +95,7 @@ def test_sunroof_published_as_binary_sensor_when_supported(self) -> None: discovery, publisher = self._make_discovery(has_sunroof=True) discovery.publish_ha_discovery_messages() - sunroof_topic = ( - f"homeassistant/binary_sensor/{VIN}_mg/{VIN}_sun_roof/config" - ) + sunroof_topic = f"homeassistant/binary_sensor/{VIN}_mg/{VIN}_sun_roof/config" assert sunroof_topic in publisher.map payload = json.loads(publisher.map[sunroof_topic]) assert "command_topic" not in payload @@ -109,9 +105,7 @@ def test_sunroof_unpublished_when_not_supported(self) -> None: discovery, publisher = self._make_discovery(has_sunroof=False) discovery.publish_ha_discovery_messages() - sunroof_binary = ( - f"homeassistant/binary_sensor/{VIN}_mg/{VIN}_sun_roof/config" - ) + sunroof_binary = f"homeassistant/binary_sensor/{VIN}_mg/{VIN}_sun_roof/config" assert sunroof_binary in publisher.map, ( "Expected unpublish message for binary_sensor Sun roof" )