flobz / psa_car_controller

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

Trips aren't recorded: " unsupported operand type(s) for -: 'NoneType' and 'NoneType'` " (mileage?) #205

Closed DreamT80 closed 3 years ago

DreamT80 commented 3 years ago

Describe the bug Bug when recording trips. Trips aren't saved. Probably related to that my vehicle doesn't support mileage.

See this in the log:

2021-08-21 20:35:20,521 :: INFO :: new position recorded for xxx 2021-08-21 20:35:20,591 :: INFO :: update_data 2021-08-21 20:35:20,596 :: ERROR :: refresh_vehicle_info: Traceback (most recent call last): File "/psa_car_controller/my_psacc.py", line 170, in __refresh_vehicle_info self.get_vehicle_info(car.vin) File "/psa_car_controller/my_psacc.py", line 156, in get_vehicle_info self.record_info(car) File "/psa_car_controller/my_psacc.py", line 479, in record_info level_fuel, moving) File "/psa_car_controller/web/db.py", line 262, 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/views.py", line 246, in update_trips trips_by_vin = Trips.get_trips(Cars([car])) File "/psa_car_controller/trip.py", line 162, in get_trips distance = end["mileage"] - start["mileage"] TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

To Reproduce Steps to reproduce the behavior:

  1. what command did you use: I used the web interface
  2. when the bug append ? See above
  3. Does it persist after restarting the program? Yes

Config file Cannot access the config file since it's containerised.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

flobz commented 3 years ago

The algo use mileage to create the trips list, it can't be done without it.

DreamT80 commented 3 years ago

Ok, I understand. But I guess that it still would be good to handle the error in the code?

flobz commented 3 years ago

Yeah I did.

DreamT80 commented 3 years ago

Ok, I see :). Thank you!

DreamT80 commented 3 years ago

Hi again,

Can you to update the HA repo so that it's possible to download the update via the add-on store? Thank you in advance.

flobz commented 3 years ago

Done

DreamT80 commented 3 years ago

Thank you! Unfortunately I got the problem below. Is it a bug? Or maybe I should test and reinstall the add-on?

Containerised psa_car_controller loading... /usr/local/lib/python3.7/dist-packages/dash_bootstrap_components/_table.py:5: UserWarning: The dash_html_components package is deprecated. Please replace import dash_html_components as htmlwithfrom dash import html import dash_html_components as html 2021-09-05 17:46:32,158 :: INFO :: save config change 2021-09-05 17:46:33,309 :: INFO :: ["{'vin': '...', 'vehicle_id': '...', 'label': 'Grandland X Hybrid', 'brand': 'C', 'abrp_name': None, 'battery_power': 13.2, 'fuel_capacity': 43, 'max_elec_consumption': 70, 'max_fuel_consumption': 30}"] 2021-09-05 17:46:33,884 :: INFO :: save config change 2021-09-05 17:46:33,885 :: ERROR :: remote_refresh_token isn't defined 2021-09-05 17:46:33,890 :: WARNING :: Can't get language /psa_car_controller/web/views.py:7: UserWarning: The dash_core_components package is deprecated. Please replace import dash_core_components as dccwithfrom dash import dcc import dash_core_components as dcc /psa_car_controller/web/figures.py:4: UserWarning: The dash_table package is deprecated. Please replace import dash_tablewithfrom dash import dash_table Also, if you're using any of the table format helpers (e.g. Group), replace from dash_table.Format import Groupwith from dash.dash_table.Format import Group import dash_table 2021-09-05 17:46:34,732 :: INFO :: update_data 2021-09-05 17:46:34,995 :: ERROR :: Bad value : Traceback (most recent call last): File "/psa_car_controller/trip.py", line 163, in get_trips distance = end["mileage"] - start["mileage"] TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType' Exception in thread Thread-3: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/psa_car_controller/web/app.py", line 46, in start_app run(config_flask(*args, **kwargs)) File "/psa_car_controller/web/app.py", line 76, in config_flask importlib.import_module(view) File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/psa_car_controller/web/views.py", line 397, in <module> update_trips() File "/psa_car_controller/web/views.py", line 246, in update_trips trips_by_vin = Trips.get_trips(Cars([car])) File "/psa_car_controller/trip.py", line 173, in get_trips if TripParser.is_low_speed(speed_average, duration) or trip_parser.is_refuel(start, end, distance): UnboundLocalError: local variable 'duration' referenced before assignment 2021-09-05 17:48:34,573 :: INFO :: charging status of ... is Stopped, battery level: 21