Merge branch 'master' into patch-1

This commit is contained in:
Florian BEZANNIER
2023-11-25 13:15:04 +01:00
committed by GitHub
11 changed files with 63 additions and 10 deletions
+4
View File
@@ -148,3 +148,7 @@ config.json
test.json
charge_config.json
cars.json
certs/
*.log.*
.vscode/
@@ -15,6 +15,7 @@ from psa_car_controller.psacc.utils.utils import Singleton
from .psa_client import PSAClient
from psa_car_controller.common.mylogger import my_logger
from psa_car_controller.psa.otp.otp import CONFIG_NAME as OTP_CONFIG_NAME, ConfigException
from psa_car_controller import __version__
DEFAULT_NAME = "config.json"
@@ -75,6 +76,8 @@ class PSACarController(metaclass=Singleton):
def load_app(self) -> bool:
# pylint: disable=too-many-branches
my_logger(handler_level=int(self.args.debug))
logger.info("App version %s", __version__)
if self.args.config:
self.config_name = self.args.config
if path.isfile(self.config_name):
@@ -20,10 +20,10 @@ class Charging:
@staticmethod
def get_chargings() -> List[dict]:
conn = Database.get_db()
res = conn.execute("select * from battery ORDER BY start_at").fetchall()
conn.close()
return list(map(dict, res))
charge_db = Database.get_all_charge()
charge_list = list(map(dict, charge_db))
Charging._calculated_fields(charge_list)
return charge_list
@staticmethod
def get_battery_curve(conn, charge, car) -> List[BatteryChargeCurve]:
@@ -97,3 +97,15 @@ class Charging:
Charging.update_chargings(conn, last_charge, car)
conn.commit()
conn.close()
@staticmethod
def _calculated_fields(charge_list: list):
for c in charge_list:
if c.get("stop_at") and c.get("start_at"):
c.update(
{
"duration_min": (c.get("stop_at") - c.get("start_at")).total_seconds()
/ 60,
"duration_str": str((c.get("stop_at") - c.get("start_at"))),
}
)
@@ -102,7 +102,7 @@ class PSAClient:
else:
for _ in range(0, 2):
try:
res = self.api().get_vehicle_status(car.vehicle_id, extension=["odometer"])
res = self.api().get_vehicle_status(car.vehicle_id)
if res is not None:
car.status = res
if self._record_enabled:
@@ -321,6 +321,13 @@ class Database:
charges.append(Charge(**dict_key_to_lower_case(**row)))
return charges
@staticmethod
def get_all_charge() -> List[Charge]:
conn = Database.get_db()
res = conn.execute("select * from battery ORDER BY start_at").fetchall()
conn.close()
return res
@staticmethod
def update_charge(charge: Charge):
# we don't need to update mileage, since it should be inserted at beginning of charge,
@@ -477,3 +477,11 @@
fuel_capacity: 53
abrp_name:
reg: VR7ARHPYEP.*
- !CarModel
name: Peugeot Rifter
battery_power: 0
fuel_capacity: 50
abrp_name:
reg: VR3ECYHYCK.*
max_elec_consumption: 0
max_fuel_consumption: 30
+2 -1
View File
@@ -76,7 +76,8 @@ def config_flask(title, base_path, debug: bool, host, port, reloader=False, # p
else:
application = DispatcherMiddleware(Flask('dummy_app'), {base_path: app})
requests_pathname_prefix = base_path + "/"
dash_app = DashCustom(external_stylesheets=[dbc.themes.BOOTSTRAP], external_scripts=locale_url, title=title,
dash_app = DashCustom(external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.BOOTSTRAP],
external_scripts=locale_url, title=title,
server=app, requests_pathname_prefix=requests_pathname_prefix,
suppress_callback_exceptions=True, serve_locally=False)
dash_app.enable_dev_tools(debug)
+4 -1
View File
@@ -139,6 +139,9 @@ def get_figures(car: Car):
sort_by=[{'column_id': 'start_at_str', 'direction': 'desc'}],
columns=[{'id': 'start_at_str', 'name': 'start at', 'type': 'datetime'},
{'id': 'stop_at_str', 'name': 'stop at', 'type': 'datetime'},
{'id': 'duration_str', 'name': 'duration', 'type': 'text'},
{'id': 'duration_min', 'name': 'duration (min)', 'type': 'numeric',
'format': deepcopy(nb_format).symbol_suffix(" min").precision(0)},
{'id': 'start_level', 'name': 'start level', 'type': 'numeric'},
{'id': 'end_level', 'name': 'end level', 'type': 'numeric'},
{'id': 'co2', 'name': 'CO2', 'type': 'numeric',
@@ -147,7 +150,7 @@ def get_figures(car: Car):
'format': deepcopy(nb_format).symbol_suffix(" kWh").precision(2)},
{'id': 'price', 'name': 'price', 'type': 'numeric',
'format': deepcopy(nb_format).symbol_suffix(" " + CURRENCY).precision(2), 'editable': True},
{'id': 'charging_mode', 'name': 'charging mode', 'type': 'string'},
{'id': 'charging_mode', 'name': 'charging mode', 'type': 'text'},
{'id': 'mileage', 'name': 'mileage', 'type': 'numeric', 'format': nb_format},
],
data=[],
+13 -2
View File
@@ -30,6 +30,7 @@ from psa_car_controller.web.view.config_views import log_layout, config_layout
from psa_car_controller.web.tools.figurefilter import FigureFilter
from psa_car_controller.web.view.control import get_control_tabs
from psa_car_controller import __version__
logger = CustomLogger.getLogger(__name__)
EMPTY_DIV = "empty-div"
@@ -46,11 +47,21 @@ def get_default_car() -> Car:
def add_header(el):
version = "v" + __version__
github_url= "https://github.com/flobz/psa_car_controller/releases/tag/"+version
dbc_version = dbc.Button(html.I(version, className="m-1"),
size='sm',
color="secondary",
className="me-1 bi bi-github",
external_link =True, href=github_url)
return dbc.Row([dbc.Col(dcc.Link(html.H1('My car info'), href=dash_app.requests_pathname_external_prefix,
style={"TextDecoration": "none"})),
dbc.Col(dcc.Link(html.Img(src="assets/images/settings.svg", width="30veh"),
dbc.Col(html.Div([dbc_version,
dcc.Link(html.Img(src="assets/images/settings.svg", width="30veh"),
href=dash_app.requests_pathname_external_prefix + "config",
className="float-end"))]), el
className="float-end")],
className="d-grid gap-2 d-md-flex justify-content-md-end",))],
className='align-items-center'), el
@dash_app.callback(Output('page-content', 'children'),
+3 -1
View File
@@ -33,7 +33,7 @@ from psa_car_controller.psacc.repository.trips import Trips
from psa_car_controller.psacc.utils.utils import get_temp
from tests.data.car_status import FUEL_CAR_STATUS, ELECTRIC_CAR_STATUS, ELECTRIC_CAR_STATUS_V2
from tests.utils import DATA_DIR, record_position, latitude, longitude, date0, date1, date2, date3, record_charging, \
vehicule_list, get_new_test_db, get_date, date4, compare_dict
vehicule_list, get_new_test_db, get_date, date4, compare_dict, duration_min, duration_str
from psa_car_controller.web.figures import get_figures, get_battery_curve_fig, get_altitude_fig
dummy_value = 0
@@ -237,6 +237,8 @@ class TestUnit(unittest.TestCase):
assert isinstance(co2, float)
assert compare_dict(chargings, [{'start_at': date0,
'stop_at': date3,
'duration_str': duration_str,
'duration_min' :duration_min,
'VIN': 'VR3UHZKX',
'start_level': 40,
'end_level': 85,
+2
View File
@@ -21,6 +21,8 @@ date2 = date3 - timedelta(minutes=20)
date1 = date3 - timedelta(minutes=40)
date0 = date3 - timedelta(minutes=60)
date4 = date3 + timedelta(minutes=1)
duration_min = (date3 - date0).seconds / 60
duration_str = str(date3 - date0)
vehicule_list = Cars()
vehicule_list.extend(