fix: bad mqtt service stop

This commit is contained in:
Florian Bezannier
2025-10-01 09:12:13 +02:00
committed by Florian BEZANNIER
parent 146fe67fac
commit 1dc4d83e3b
2 changed files with 10 additions and 4 deletions
+9 -3
View File
@@ -44,6 +44,7 @@ class RemoteClient:
self.mqtt_client = None
self.otp = None
self._lock = threading.Lock()
self.update_thread: threading.Timer = None
def __on_mqtt_connect(self, client, userdata, result_code, _): # pylint: disable=unused-argument
logger.info("Connected with result code %s", result_code)
@@ -118,6 +119,11 @@ class RemoteClient:
logger.error("Can't configure MQTT Client")
return False
def stop(self):
self.mqtt_client.on_disconnect = None
self.mqtt_client.disconnect()
self.update_thread.cancel()
def __keep_mqtt(self): # avoid token expiration
timeout = 3600 * 24 # 1 day
if len(self.vehicles_list) > 0:
@@ -125,9 +131,9 @@ class RemoteClient:
self.wakeup(self.vehicles_list[0].vin)
except RateLimitException:
logger.exception("__keep_mqtt")
t = threading.Timer(timeout, self.__keep_mqtt)
t.daemon = True
t.start()
self.update_thread = threading.Timer(timeout, self.__keep_mqtt)
self.update_thread.daemon = True
self.update_thread.start()
def veh_charge_request(self, vin, hour, minute, charge_type):
msg = self.mqtt_request(vin, {"program": {"hour": hour, "minute": minute}, "type": charge_type}, "/VehCharge")
@@ -60,7 +60,7 @@ class PSACarController(metaclass=Singleton):
logger.info("mqtt disabled")
elif not self.args.web_conf or path.isfile(OTP_CONFIG_NAME):
if self.myp.remote_client.mqtt_client is not None:
self.myp.remote_client.mqtt_client.disconnect()
self.myp.remote_client.stop()
try:
self.myp.remote_client.start()
if self.args.charge_control: