flobz / psa_car_controller

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

After upgrade from 3.3.1 to 3.3.2 trips, position or charges don't get registered anymore. #744

Closed sod75 closed 6 months ago

sod75 commented 7 months ago

Describe the bug After upgrade from 3.3.1 to 3.3.2 trips, position or chargings don't get registered anymore.

To Reproduce Steps to reproduce the behavior: Upgrade from 3.3.1 to 3.3.2 via docker

  1. what command did you use docker-compose stop psa, docker-compose pull psa; docker-compose up -d psa

  2. when the bug append ? After the update

  3. Does it persist after restarting the program? Yes

  4. Does it persist after recreate config by going to http://server_address:port/config? not tried, but downgrading to 3.3.1 again solves the issue. It ran fine for days again, I gave the 3.3.2 another go, same issue again.

Config file

[General]
currency = €
# define format for data export, can be csv or xlsx
export_format = csv
# minimum trip length in km so it's added to stats and map in website
minimum trip length = 1
# for future use
length unit = km
export format = csv
[Electricity config]
# price by kw/h
day price = 0.35
night price
# ex: 22h30
night hour start
# ex: 6h00
night hour end
dc charge price
high speed dc charge price
# minimum power in kW that should be delivered during a charge so it can be considered as a high speed charger
high speed dc charge threshold
charger efficiency = 0.8942

Environment (please complete the following information):

this is what I get in 3.3.1

2024-01-24 14:50:39,596 :: INFO :: 192.168.0.91 - - [24/Jan/2024 14:50:39] "^[[37mGET /charge_control?vin=VF3M4DGZUPS&?always_check=true HTTP/1.1^[[0m" 200 -
2024-01-24 14:51:11,431 :: INFO :: ask wakeup to VF3M4DGZUPS
2024-01-24 14:51:11,432 :: INFO :: topic: psa/RemoteServices/from/cid/AP-ACNT200008553362/VehCharge/state: {'action': 'state'}
2024-01-24 14:51:12,431 :: INFO :: save config change
2024-01-24 14:51:12,697 :: INFO :: mqtt msg received: psa/RemoteServices/to/cid/AP-ACNT200008553362/VehCharge/state/ProcessManagement b'{"process_date":"2024-01-24T13:51:12Z","vin":"VF3M4DGZUPS","correlation_id":"148b8402a3204e5b83bd5457d23150e020240124135112432","process_code":"900","process_message":"[process.900.request.accepted.key]"}'
2024-01-24 14:51:12,864 :: INFO :: mqtt msg received: psa/RemoteServices/to/cid/AP-ACNT200008553362/VehCharge/state/ProcessManagement b'{"process_date":"2024-01-24T13:51:12Z","vin":"VF3M4DGZUPS","correlation_id":"148b8402a3204e5b83bd5457d23150e020240124135112432","process_code":"901","process_message":"[process.901.vehicle.asleep.key]"}'
2024-01-24 14:51:33,556 :: INFO :: mqtt msg received: psa/RemoteServices/to/cid/AP-ACNT200008553362/VehCharge/state/ProcessManagement b'{"process_date":"2024-01-24T13:51:33Z","vin":"VF3M4DGZUPS","correlation_id":"148b8402a3204e5b83bd5457d23150e020240124135112432","process_code":"903","process_message":"[process.903.request.forwarded.to.vehicle.key]"}'
2024-01-24 14:51:33,774 :: INFO :: mqtt msg received: psa/RemoteServices/to/cid/AP-ACNT200008553362/VehCharge/state b'{"resp_date":"2024-01-24T13:51:33Z","vin":"VF3M4DGZUPS","correlation_id":"148b8402a3204e5b83bd5457d23150e020240124135112432","return_code":"0"}'
2024-01-24 14:51:39,596 :: INFO :: 192.168.0.91 - - [24/Jan/2024 14:51:39] "^[[37mGET /get_vehicleinfo/VF3M4DGZUPS?from_cache=1 HTTP/1.1^[[0m" 200 -
2024-01-24 14:51:39,598 :: INFO :: <Request 'http://192.168.0.91:3000/charge_control?vin=VF3M4DGZUPS&%3Falways_check=true' [GET]>
2024-01-24 14:51:39,599 :: INFO :: 192.168.0.91 - - [24/Jan/2024 14:51:39] "^[[37mGET /charge_control?vin=VF3M4DGZUPS&?always_check=true HTTP/1.1^[[0m" 200 -
2024-01-24 14:52:39,597 :: INFO :: 192.168.0.91 - - [24/Jan/2024 14:52:39] "^[[37mGET /get_vehicleinfo/VF3M4DGZUPS?from_cache=1 HTTP/1.1^[[0m" 200 -
2024-01-24 14:52:39,599 :: INFO :: <Request 'http://192.168.0.91:3000/charge_control?vin=VF3M4DGZUPS&%3Falways_check=true' [GET]>
2024-01-24 14:52:39,600 :: INFO :: 192.168.0.91 - - [24/Jan/2024 14:52:39] "^[[37mGET /charge_control?vin=VF3M4DGZUPS&?always_check=true HTTP/1.1^[[0m" 200 -
2024-01-24 14:53:11,318 :: ERROR :: Unable to get temperature from openweathermap :
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/utils/utils.py", line 19, in get_temp
    temp = weather_rep.json()["current"]["temp"]
KeyError: 'current'
2024-01-24 14:53:11,647 :: INFO :: new position recorded for VF3M4DGZUPS
2024-01-24 14:53:11,648 :: INFO :: update_data
2024-01-24 14:53:39,598 :: INFO :: 192.168.0.91 - - [24/Jan/2024 14:53:39] "^[[37mGET /get_vehicleinfo/VF3M4DGZUPS?from_cache=1 HTTP/1.1^[[0m" 200 -
2024-01-24 14:53:39,600 :: INFO :: <Request 'http://192.168.0.91:3000/charge_control?vin=VF3M4DGZUPS&%3Falways_check=true' [GET]>
2024-01-24 14:53:39,601 :: INFO :: 192.168.0.91 - - [24/Jan/2024 14:53:39] "^[[37mGET /charge_control?vin=VF3M4DGZUPS&?always_check=true HTTP/1.1^[[0m" 200 -

Additional context Add any other context about the problem here.

sod75 commented 7 months ago

I tried http://192.168.0.91:3000/get_vehicleinfo/VF3M4DGZUPSxxxxxx from a browserwindow and it gives an Internal Server Error. the log is a bit more verbose.

2024-01-25 17:27:16,051 :: ERROR :: Exception on /get_vehicleinfo/VF3M4DGZUP[GET]
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/web/view/api.py", line 43, in get_vehicle_info
    response=json.dumps(APP.myp.get_vehicle_info(vin, from_cache).to_dict(), default=str),
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py", line 109, in get_vehicle_info
    self.record_info(car)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py", line 195, in record_info
    Database.record_position(self.weather_api, car.vin, mileage, latitude, longitude, altitude, date, level,
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/repository/db.py", line 257, in record_position
    temp = get_temp(latitude, longitude, weather_api)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/utils/utils.py", line 20, in get_temp
    temp = weather_res_json.get("current", weather_res_json.get("main"))["temp"]
TypeError: 'NoneType' object is not subscriptable
2024-01-25 17:27:16,051 :: ERROR :: Exception on /get_vehicleinfo/VF3M4DGZUPS [GET]
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/web/view/api.py", line 43, in get_vehicle_info
    response=json.dumps(APP.myp.get_vehicle_info(vin, from_cache).to_dict(), default=str),
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py", line 109, in get_vehicle_info
    self.record_info(car)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py", line 195, in record_info
    Database.record_position(self.weather_api, car.vin, mileage, latitude, longitude, altitude, date, level,
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/repository/db.py", line 257, in record_position
    temp = get_temp(latitude, longitude, weather_api)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/utils/utils.py", line 20, in get_temp
    temp = weather_res_json.get("current", weather_res_json.get("main"))["temp"]
TypeError: 'NoneType' object is not subscriptable
2024-01-25 17:27:16,052 :: INFO :: 172.18.0.1 - - [25/Jan/2024 17:27:16] "GET /get_vehicleinfo/VF3M4DGZUPS HTTP/1.1" 500 -
2024-01-25 17:27:38,299 :: ERROR :: refresh_vehicle_info: 
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py", line 126, in __refresh_vehicle_info
    self.get_vehicle_info(car.vin)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py", line 109, in get_vehicle_info
    self.record_info(car)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py", line 195, in record_info
    Database.record_position(self.weather_api, car.vin, mileage, latitude, longitude, altitude, date, level,
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/repository/db.py", line 257, in record_position
    temp = get_temp(latitude, longitude, weather_api)
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/utils/utils.py", line 20, in get_temp
    temp = weather_res_json.get("current", weather_res_json.get("main"))["temp"]
TypeError: 'NoneType' object is not subscriptable
2024-01-25 17:27:42,789 :: INFO :: 192.168.0.91 - - [25/Jan/2024 17:27:42] "GET /get_vehicleinfo/VF3M4DGZUPS?from_cache=1 HTTP/1.1" 200 -
mdino-gh commented 7 months ago

Hi, I have observed the same issue, the database info.db isn't updated anymore with version 3.3.2. As soon as I downgrade to version 3.3.1 is see that database is updated again.

mdino-gh commented 7 months ago

The issue might be related to this error message TypeError: 'NoneType' object is not subscriptable. At least the error messages disappeared after rolling back to version 3.3.1.

2024-02-05T13:08:40.454181+01:00 mdha02-n psa-car-controller[1666030]: 2024-02-05 13:08:40,452 :: DEBUG :: vin:VINxxxxxxxxxxxxxx longitude:x.xxxxx latitude:yy.yyyyy date:2024-02-05 11:36:51+00:00 mileage:20672.5 level:27.0 charge_date:2024-02-05 11:37:47+00:00 level_fuel:None moving:False 2024-02-05T13:08:40.672681+01:00 mdha02-n psa-car-controller[1666030]: 2024-02-05 13:08:40,669 :: ERROR :: refresh_vehicle_info: 2024-02-05T13:08:40.672869+01:00 mdha02-n psa-car-controller[1666030]: Traceback (most recent call last): 2024-02-05T13:08:40.672944+01:00 mdha02-n psa-car-controller[1666030]: File "/opt/psa-car-controller/lib/python3.11/site-packages/psa_car_controller/psacc/application/psa_client.py", line 126, in __refresh_vehicle_info 2024-02-05T13:08:40.673003+01:00 mdha02-n psa-car-controller[1666030]: self.get_vehicle_info(car.vin) 2024-02-05T13:08:40.673064+01:00 mdha02-n psa-car-controller[1666030]: File "/opt/psa-car-controller/lib/python3.11/site-packages/psa_car_controller/psacc/application/psa_client.py", line 109, in get_vehicle_info 2024-02-05T13:08:40.673119+01:00 mdha02-n psa-car-controller[1666030]: self.record_info(car) 2024-02-05T13:08:40.673168+01:00 mdha02-n psa-car-controller[1666030]: File "/opt/psa-car-controller/lib/python3.11/site-packages/psa_car_controller/psacc/application/psa_client.py", line 195, in record_info 2024-02-05T13:08:40.673261+01:00 mdha02-n psa-car-controller[1666030]: Database.record_position(self.weather_api, car.vin, mileage, latitude, longitude, altitude, date, level, 2024-02-05T13:08:40.673318+01:00 mdha02-n psa-car-controller[1666030]: File "/opt/psa-car-controller/lib/python3.11/site-packages/psa_car_controller/psacc/repository/db.py", line 257, in record_position 2024-02-05T13:08:40.673372+01:00 mdha02-n psa-car-controller[1666030]: temp = get_temp(latitude, longitude, weather_api) 2024-02-05T13:08:40.673418+01:00 mdha02-n psa-car-controller[1666030]:
2024-02-05T13:08:40.673471+01:00 mdha02-n psa-car-controller[1666030]: File "/opt/psa-car-controller/lib/python3.11/site-packages/psa_car_controller/psacc/utils/utils.py", line 20, in get_temp 2024-02-05T13:08:40.673524+01:00 mdha02-n psa-car-controller[1666030]: temp = weather_res_json.get("current", weather_res_json.get("main"))["temp"] 2024-02-05T13:08:40.673578+01:00 mdha02-n psa-car-controller[1666030]:
2024-02-05T13:08:40.673625+01:00 mdha02-n psa-car-controller[1666030]: TypeError: 'NoneType' object is not subscriptable

sod75 commented 6 months ago

It seems fixed to me, in the sense that the error again no longer "crashes" the program.

I again have a similar error as with v3.3.1

2024-03-06 17:51:06,952 :: INFO :: 172.18.0.1 - - [06/Mar/2024 17:51:06] "GET /assets/images/battery-soh.svg HTTP/1.1" 200 -
2024-03-06 17:51:06,955 :: INFO :: 172.18.0.1 - - [06/Mar/2024 17:51:06] "GET /assets/images/battery-charge.svg HTTP/1.1" 200 -
2024-03-06 17:51:06,957 :: INFO :: 172.18.0.1 - - [06/Mar/2024 17:51:06] "GET /assets/images/mileage.svg HTTP/1.1" 200 -
2024-03-06 17:51:17,904 :: ERROR :: Unable to get temperature from openweathermap :
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/utils/utils.py", line 20, in get_temp
    temp = weather_res_json.get("current", weather_res_json.get("main"))["temp"]
TypeError: 'NoneType' object is not subscriptable
2024-03-06 17:51:18,394 :: INFO :: new position recorded for VF3M4DGZUPxxxxxx
2024-03-06 17:51:18,573 :: INFO :: update_data

happy to close this bug and have this error as a new one if that's the preference.

sod75 commented 6 months ago

ok, I just realized the error is due to me not have set up the "paid" plan for openweathermap. not the cleanest error message, but that's irrelevant. Closing