mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-21 17:06:18 +00:00
fix: bad mqtt service stop
This commit is contained in:
committed by
Florian BEZANNIER
parent
146fe67fac
commit
1dc4d83e3b
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user