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 all 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
3 changes: 3 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,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)
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"])
Expand Down
15 changes: 15 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,21 @@
)
return response

/**

Check notice on line 54 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#L54

Parsing failed: 'invalid syntax (<unknown>, line 54)' (syntax-error)

Check notice on line 54 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#L54

expected 2 blank lines after class or function definition, found 1 (E305)
@return {'doors_opening_state': number[]; 'doors_locking_state': number}

Check notice on line 55 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#L55

unexpected indentation (E113)
*/
@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