Merge pull request #115 from flobz/develop

add from_cache option & always put electric energy first in the array
This commit is contained in:
Florian BEZANNIER
2021-05-10 20:45:33 +02:00
committed by GitHub
4 changed files with 24 additions and 14 deletions
+3
View File
@@ -33,6 +33,9 @@ For information on configuring the psa_car_controller Docker container [see this
2.1 Get the car state :
http://localhost:5000/get_vehicleinfo/YOURVIN
2.2 Get the car state from cache to avoid to use psa api too much
http://localhost:5000/get_vehicleinfo/YOURVIN?from_cache=1
2.2 Stop charge
http://localhost:5000/charge_now/YOURVIN/0
+3
View File
@@ -23,6 +23,9 @@ class CarStatus(Status):
properties=PositionProperties(updated_at=None))
if self.kinetic is None:
self.kinetic = Kinetic()
# always put electric energy first
if len(self._energy) == 2 and self._energy[0].type != 'Electric':
self._energy = self._energy[::-1]
def is_moving(self):
try:
+16 -13
View File
@@ -134,21 +134,24 @@ class MyPSACC:
self.manager.proxies = self._proxies
Otp.set_proxies(proxies)
def get_vehicle_info(self, vin):
def get_vehicle_info(self, vin, cache=False):
res = None
car = self.vehicles_list.get_car_by_vin(vin)
for _ in range(0, 2):
try:
res = self.api().get_vehicle_status(car.vehicle_id, extension=["odometer"])
if res is not None:
car.status = res
if self._record_enabled:
self.record_info(car)
return res
except (ApiException, InvalidHeader) as ex:
logger.error("get_vehicle_info: ApiException: %s", ex)
logger.debug(exc_info=True)
car.status = res
if cache and car.status is not None:
res = car.status
else:
for _ in range(0, 2):
try:
res = self.api().get_vehicle_status(car.vehicle_id, extension=["odometer"])
if res is not None:
car.status = res
if self._record_enabled:
self.record_info(car)
return res
except (ApiException, InvalidHeader) as ex:
logger.error("get_vehicle_info: ApiException: %s", ex)
logger.debug(exc_info=True)
car.status = res
return res
def refresh_vehicle_info(self):
+2 -1
View File
@@ -151,8 +151,9 @@ def get_vehicules():
@app.route('/get_vehicleinfo/<string:vin>')
def get_vehicle_info(vin):
from_cache = int(request.args.get('from_cache', 0)) == 1
response = app.response_class(
response=json.dumps(myp.get_vehicle_info(vin).to_dict(), default=str),
response=json.dumps(myp.get_vehicle_info(vin, from_cache).to_dict(), default=str),
status=200,
mimetype='application/json'
)