flobz / psa_car_controller

Control psa car with connected_car v4 API.
GNU General Public License v3.0
419 stars 221 forks source link

Mileage error in get_vehicleinfo #306

Closed DreamT80 closed 2 years ago

DreamT80 commented 2 years ago

Describe the bug An error in get_vehicleinfo throws an error regarding mileage:

To Reproduce Steps to reproduce the behavior:

  1. what command did you use get_vehicleinfo (with cache=0)

  2. when the bug append ? Always when calling the command with cache=0

  3. Does it persist after restarting the program? Yes

  4. Does it persist after recreate config by going to http://server_address:port/config? Yes

Config file Can't see the config file in HA

Environment (please complete the following information):

"GET /get_vehicleinfo/VIN?from_cache=1 HTTP/1.1" 200 - 2021-12-29 00:03:07,237 :: INFO :: level_fuel fixed with last real value 36.000000 for VIN 2021-12-29 00:03:07,356 :: INFO :: new position recorded for VIN 2021-12-29 00:03:07,486 :: INFO :: update_data 2021-12-29 00:03:07,494 :: ERROR :: refresh_vehicle_info: Traceback (most recent call last): File "/psa_car_controller/my_psacc.py", line 119, in __refresh_vehicle_info self.get_vehicle_info(car.vin) File "/psa_car_controller/my_psacc.py", line 106, in get_vehicle_info self.record_info(car) File "/psa_car_controller/my_psacc.py", line 191, in record_info Database.record_position(self.weather_api, car.vin, mileage, latitude, longitude, altitude, date, level, File "/psa_car_controller/web/db.py", line 264, in record_position conn.close() File "/psa_car_controller/web/db.py", line 45, in close self.execute_callbacks() File "/psa_car_controller/web/db.py", line 41, in execute_callbacks callback() File "/psa_car_controller/web/view/views.py", line 256, in update_trips trips_by_vin = Trips.get_trips(Cars([car])) File "/psa_car_controller/trip.py", line 177, in get_trips distance = next_el["mileage"] - end["mileage"] # km TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

Additional context Problem probably related to that the API doesn't return mileage for my car model (there has been other fixes for this earlier).

Snellingen commented 2 years ago

I have the same issue. I can't get data from my car as this bug seem to short circuit the processing of the data.

Log:

2022-01-09 19:01:55,681 :: INFO :: new position recorded for {REMOVED_VIN}
2022-01-09 19:01:55,687 :: INFO :: update_data
2022-01-09 19:01:55,697 :: ERROR :: refresh_vehicle_info:
Traceback (most recent call last):
File "/psa_car_controller/my_psacc.py", line 119, in __refresh_vehicle_info
self.get_vehicle_info(car.vin)
File "/psa_car_controller/my_psacc.py", line 106, in get_vehicle_info
self.record_info(car)
File "/psa_car_controller/my_psacc.py", line 191, in record_info
Database.record_position(self.weather_api, car.vin, mileage, latitude, longitude, altitude, date, level,
File "/psa_car_controller/web/db.py", line 264, in record_position
conn.close()
File "/psa_car_controller/web/db.py", line 45, in close
self.execute_callbacks()
File "/psa_car_controller/web/db.py", line 41, in execute_callbacks
callback()
File "/psa_car_controller/web/view/views.py", line 256, in update_trips
trips_by_vin = Trips.get_trips(Cars([car]))
File "/psa_car_controller/trip.py", line 177, in get_trips
distance = next_el["mileage"] - end["mileage"] # km
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

Probably need some try catch block on line 177 - 178 in trip.py:

distance = next_el["mileage"] - end["mileage"]  # km
duration = (next_el["Timestamp"] - end["Timestamp"]).total_seconds() / 3600
flobz commented 2 years ago

fixed in last version

DreamT80 commented 2 years ago

fixed in last version

Ok! Updated now, and unfortunately got another error. Maybe I need to add battery capacity in the config?

the web UI gives “502 bad gateway” though.

File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/battery_charge_curve.py", line 26, in dto_to_battery_curve km_by_kw = 0.8 * battery_curves_dto[-1].autonomy / battery_capacity ZeroDivisionError: float division by zero

DreamT80 commented 2 years ago

fixed in last version

Ok! Updated now, and unfortunately got another error. Maybe I need to add battery capacity in the config?

the web UI gives “502 bad gateway” though.

File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/battery_charge_curve.py", line 26, in dto_to_battery_curve km_by_kw = 0.8 * battery_curves_dto[-1].autonomy / battery_capacity ZeroDivisionError: float division by zero

I did a reinstall, and it worked then. So I don’t know if this is upgrade related.

flobz commented 2 years ago

I did an hot fix on the develop branch. Can you try please ?

DreamT80 commented 2 years ago

I did an hot fix on the develop branch. Can you try please ?

I'm sorry, i don't know to make a Docker image of it, much less how I get it into HA. I can have a look at it tonight (I have to learn it anyway), but that would be at least 12 hours away.

DreamT80 commented 2 years ago

I did an hot fix on the develop branch. Can you try please ?

I'm not able (right now) to build the Docker image, getting an error when building which probably have to do with my lack of knowledge. So I'm not able to test right now, unfortunately.