diff --git a/Dockerfile b/Dockerfile index 582aa54..83278b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,8 +18,8 @@ COPY --from=builder /var/lib/apt /var/lib/apt COPY --from=builder /var/cache/apt/ /var/cache/apt/ COPY --from=builder /usr/local/lib /usr/local/lib COPY --from=builder /usr/local/bin/ /usr/local/bin/ -RUN apt-get install -y --no-install-recommends $PYTHON_DEP && \ +RUN apt-get install -y --no-install-recommends $PYTHON_DEP curl && \ apt-get clean ; \ rm -rf /var/lib/apt/lists/* COPY /docker_files/init.sh /init.sh -CMD /init.sh \ No newline at end of file +CMD /init.sh diff --git a/docs/psacc_api.md b/docs/psacc_api.md index c06bb41..8400c18 100644 --- a/docs/psacc_api.md +++ b/docs/psacc_api.md @@ -60,3 +60,11 @@ 15. Get battery SOH http://localhost:5000/battery/soh/YOURVIN + +16. Get the vehicle charging sessions + + http://localhost:5000/vehicles/chargings + +17. Get the vehicle trips: + + http://localhost:5000/vehicles/trips diff --git a/psa_car_controller/web/view/api.py b/psa_car_controller/web/view/api.py index d416d24..45654c7 100644 --- a/psa_car_controller/web/view/api.py +++ b/psa_car_controller/web/view/api.py @@ -8,6 +8,11 @@ from psa_car_controller.psacc.application.car_controller import PSACarController from psa_car_controller.psacc.repository.db import Database from psa_car_controller.web.app import app +from psa_car_controller.psacc.model.car import Cars +from psa_car_controller.psacc.repository.trips import Trips + +from psa_car_controller.psacc.application.charging import Charging + import json from psa_car_controller.web.tools.utils import convert_to_number_if_number_else_return_str @@ -181,6 +186,27 @@ def settings_section(section: str): APP.config.write_config() return json_response(config_section.json()) +@app.route('/vehicles/trips') +def get_trips(): + try: + car = APP.myp.vehicles_list[0] + trips_by_vin = Trips.get_trips(Cars([car])) + trips = trips_by_vin[car.vin] + trips_as_dict = trips.get_trips_as_dict() + return jsonify(trips_as_dict) + except (IndexError, TypeError): + logger.debug("Failed to get trips, there is probably not enough data yet:", exc_info=True) + return jsonify([]) + + +@app.route('/vehicles/chargings') +def get_chargings(): + try: + chargings = Charging.get_chargings() + return jsonify(chargings) + except (IndexError, TypeError): + logger.debug("Failed to get chargings, there is probably not enough data yet:", exc_info=True) + return jsonify([]) @app.route('/settings') def settings():