Skip to content

Commit

Permalink
feat: add door state mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeallanic committed Sep 21, 2024
1 parent 90af522 commit 6fd87c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions psa_car_controller/psa/RemoteClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"])
Expand Down
12 changes: 12 additions & 0 deletions psa_car_controller/web/view/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def get_vehicle_info(vin):
)
return response

@app.route('/get_doors_state/<string:vin>')
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}")

Check notice on line 59 in psa_car_controller/web/view/api.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

psa_car_controller/web/view/api.py#L59

Use lazy % formatting in logging functions (logging-fstring-interpolation)
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():
Expand Down

0 comments on commit 6fd87c1

Please sign in to comment.