From 4ff0a37e3ef7a0dbd55826b9998742f84cf28213 Mon Sep 17 00:00:00 2001 From: Giovanni Condello Date: Wed, 18 Feb 2026 00:39:13 +0100 Subject: [PATCH] fix: preserve meaningful stop reasons for battery heating and charging (#396) The API resets bmsPTCHeatResp and bmsChrgSpRsn back to 0 (NO_REASON) quickly after heating/charging stops. Since the gateway polls periodically, the next poll overwrites the meaningful stop reason with NO_REASON. Skip publishing when the stop reason is NO_REASON so the last meaningful value is preserved as a retained MQTT message. The binary sensors for battery heating and charging status already indicate whether the process is currently active. --- src/status_publisher/charge/chrg_mgmt_data.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/status_publisher/charge/chrg_mgmt_data.py b/src/status_publisher/charge/chrg_mgmt_data.py index d7b2fcf..b0444fc 100644 --- a/src/status_publisher/charge/chrg_mgmt_data.py +++ b/src/status_publisher/charge/chrg_mgmt_data.py @@ -8,7 +8,9 @@ from saic_ismart_client_ng.api.vehicle_charging import ( ChargeCurrentLimitCode, + ChargingStopReason, ChrgMgmtData, + HeatingStopReason, ScheduledChargingMode, TargetBatteryCode, ) @@ -110,6 +112,7 @@ def publish(self, charge_mgmt_data: ChrgMgmtData) -> ChrgMgmtDataProcessingResul self._transform_and_publish( topic=mqtt_topics.DRIVETRAIN_CHARGING_STOP_REASON, value=charge_mgmt_data.charging_stop_reason, + validator=lambda x: x != ChargingStopReason.NO_REASON, transform=lambda x: f"UNKNOWN {charge_mgmt_data.bmsChrgSpRsn}" if x is None else x.name, @@ -149,6 +152,7 @@ def publish(self, charge_mgmt_data: ChrgMgmtData) -> ChrgMgmtDataProcessingResul self._transform_and_publish( topic=mqtt_topics.DRIVETRAIN_BATTERY_HEATING_STOP_REASON, value=charge_mgmt_data.heating_stop_reason, + validator=lambda x: x != HeatingStopReason.NO_REASON, transform=lambda x: f"UNKNOWN ({charge_mgmt_data.bmsPTCHeatResp})" if x is None else x.name,