From 6fd87c14f7217e3acd62cb2befabfcc13df8e80e Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Sat, 21 Sep 2024 13:53:15 +0200 Subject: [PATCH 1/4] feat: add door state mqtt --- psa_car_controller/psa/RemoteClient.py | 2 ++ psa_car_controller/web/view/api.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/psa_car_controller/psa/RemoteClient.py b/psa_car_controller/psa/RemoteClient.py index b4704001..caf3872b 100644 --- a/psa_car_controller/psa/RemoteClient.py +++ b/psa_car_controller/psa/RemoteClient.py @@ -34,6 +34,7 @@ def __init__(self, account_info: AccountInformation, vehicles_list: Cars, manage self.remoteCredentials: RemoteCredentials = remoteCredentials self.manager = manager self.precond_programs = {} + self.doors_state = {} self.account_info = account_info self.headers = { "x-introspect-realm": self.account_info.realm, @@ -83,6 +84,7 @@ def _on_mqtt_message(self, client, userdata, msg): # pylint: disable=unused-arg elif msg.topic.startswith(MQTT_EVENT_TOPIC): charge_info = data["charging_state"] programs = data["precond_state"].get("programs", None) + self.doors_state[data["vin"]] = data["doors_state"] if programs: self.precond_programs[data["vin"]] = data["precond_state"]["programs"] self._fix_not_updated_api(charge_info, data["vin"]) diff --git a/psa_car_controller/web/view/api.py b/psa_car_controller/web/view/api.py index 0269e68b..e79821e7 100644 --- a/psa_car_controller/web/view/api.py +++ b/psa_car_controller/web/view/api.py @@ -51,6 +51,18 @@ def get_vehicle_info(vin): ) return response +@app.route('/get_doors_state/') +def get_doors_state(vin): + doors_state = APP.myp.remote_client.doors_state.get(vin) + if doors_state is None: + return jsonify({"error": "VIN not in list"}) + logger.log(10, f"doors_state: {doors_state}") + response = app.response_class( + response=json.dumps(doors_state, default=str), + status=200, + mimetype='application/json' + ) + return response @app.route("/style.json") def get_style(): From 75368d8f46d702b4207f03adc9865dd809271711 Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Sat, 21 Sep 2024 13:55:44 +0200 Subject: [PATCH 2/4] chore: add documentation for new api --- docs/psacc_api.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/psacc_api.md b/docs/psacc_api.md index eab54906..19e3eea5 100644 --- a/docs/psacc_api.md +++ b/docs/psacc_api.md @@ -68,3 +68,7 @@ 17. Get the vehicle trips: http://localhost:5000/vehicles/trips + +18. Get vehicle doors state + + http://localhost:5000/get_doors_state/YOURVIN \ No newline at end of file From 0b06c56a2859a37f000cd4314f57988648a19c9d Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Tue, 5 Nov 2024 08:08:28 +0100 Subject: [PATCH 3/4] Update psa_car_controller/psa/RemoteClient.py Co-authored-by: Florian BEZANNIER <48728684+flobz@users.noreply.github.com> --- psa_car_controller/psa/RemoteClient.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/psa_car_controller/psa/RemoteClient.py b/psa_car_controller/psa/RemoteClient.py index caf3872b..83f44c16 100644 --- a/psa_car_controller/psa/RemoteClient.py +++ b/psa_car_controller/psa/RemoteClient.py @@ -84,7 +84,8 @@ def _on_mqtt_message(self, client, userdata, msg): # pylint: disable=unused-arg elif msg.topic.startswith(MQTT_EVENT_TOPIC): charge_info = data["charging_state"] programs = data["precond_state"].get("programs", None) - self.doors_state[data["vin"]] = data["doors_state"] + if "door_state" in data: + self.doors_state[data["vin"]] = data["doors_state"] if programs: self.precond_programs[data["vin"]] = data["precond_state"]["programs"] self._fix_not_updated_api(charge_info, data["vin"]) From 067b3d6d8acbc8c1444eb2eadf806bfd6595a87d Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Tue, 5 Nov 2024 08:13:45 +0100 Subject: [PATCH 4/4] Update api.py --- psa_car_controller/web/view/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/psa_car_controller/web/view/api.py b/psa_car_controller/web/view/api.py index e79821e7..dca7cfb8 100644 --- a/psa_car_controller/web/view/api.py +++ b/psa_car_controller/web/view/api.py @@ -51,6 +51,9 @@ def get_vehicle_info(vin): ) return response +/** + @return {'doors_opening_state': number[]; 'doors_locking_state': number} +*/ @app.route('/get_doors_state/') def get_doors_state(vin): doors_state = APP.myp.remote_client.doors_state.get(vin)