Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Door State MQTT #963

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/psacc_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"]
maximeallanic marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document possible value for door_state ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?

/**
    @return {'doors_opening_state': number[]; 'doors_locking_state': number}
*/

Have you an example of documentation? And where i set? Thank you

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():
Expand Down