mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-21 17:06:18 +00:00
Merge pull request #795 from GewoonJaap/feature/more-data-as-api-endpoint
Add vehicle chargings and trips API endpoint
This commit is contained in:
+2
-2
@@ -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
|
||||
CMD /init.sh
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user