mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-22 01:16:14 +00:00
update to dash v2,dbc v1 and fix issue
This commit is contained in:
+3
-2
@@ -57,7 +57,7 @@ class Config(metaclass=Singleton):
|
||||
def start_remote_control(self):
|
||||
if self.args.remote_disable:
|
||||
logger.info("mqtt disabled")
|
||||
elif not self.args.web_conf or path.exists(OTP_CONFIG_NAME):
|
||||
elif not self.args.web_conf or path.isfile(OTP_CONFIG_NAME):
|
||||
if self.myp.mqtt_client is not None:
|
||||
self.myp.mqtt_client.disconnect()
|
||||
self.myp.start_mqtt()
|
||||
@@ -70,9 +70,10 @@ class Config(metaclass=Singleton):
|
||||
my_logger(handler_level=int(self.args.debug))
|
||||
if self.args.config:
|
||||
self.config_name = self.args.config
|
||||
if path.exists(self.config_name):
|
||||
if path.isfile(self.config_name):
|
||||
self.myp = MyPSACC.load_config(name=self.config_name)
|
||||
elif self.args.web_conf:
|
||||
self.is_good = False
|
||||
return False
|
||||
else:
|
||||
raise FileNotFoundError(self.config_name)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import pkg_resources
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class TestRequirements:
|
||||
"""Test availability of required packages."""
|
||||
|
||||
def __init__(self, requirement_path):
|
||||
self.requirement_path = Path(requirement_path)
|
||||
|
||||
def test_requirements(self):
|
||||
"""Test that each required package is available."""
|
||||
# Ref: https://stackoverflow.com/a/45474387/
|
||||
requirements = pkg_resources.parse_requirements(self.requirement_path.open())
|
||||
for requirement in requirements:
|
||||
requirement = str(requirement)
|
||||
pkg_resources.require(requirement)
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
paho-mqtt>=1.5.0
|
||||
dash>=1.18.0
|
||||
dash>=2
|
||||
dash_daq
|
||||
plotly>=4
|
||||
cryptography>=2.6
|
||||
@@ -11,7 +11,7 @@ pytz
|
||||
typing
|
||||
argparse
|
||||
flask
|
||||
dash_bootstrap_components
|
||||
dash_bootstrap_components>=1
|
||||
geojson
|
||||
reverse_geocode
|
||||
androguard
|
||||
|
||||
@@ -2,9 +2,14 @@
|
||||
# pylint: disable=wrong-import-position
|
||||
import sys
|
||||
from threading import Thread
|
||||
|
||||
from libs.requirements import TestRequirements
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
raise RuntimeError("This application requires Python 3.6+")
|
||||
|
||||
TestRequirements("requirements.txt").test_requirements()
|
||||
|
||||
import web.app
|
||||
from libs.config import Config
|
||||
from mylogger import logger
|
||||
|
||||
+8
-8
@@ -2,12 +2,12 @@ from copy import deepcopy
|
||||
from statistics import mean
|
||||
|
||||
import dash_bootstrap_components as dbc
|
||||
import dash_table
|
||||
from dash_table.Format import Format, Scheme, Symbol
|
||||
from dash import html
|
||||
from dash.dash_table import Format, DataTable
|
||||
import plotly.express as px
|
||||
import plotly.graph_objects as go
|
||||
from web.tools.import_dash_html import html
|
||||
from web.tools.import_dash_core import dcc
|
||||
from dash.dash_table.Format import Scheme, Symbol
|
||||
from dash.dcc import Graph
|
||||
|
||||
from libs.car import Car
|
||||
from libs.elec_price import ElecPrice
|
||||
@@ -69,7 +69,7 @@ def get_figures(car: Car):
|
||||
style_cell_conditional.append({'if': {'column_id': 'consumption_fuel_km', }, 'display': 'None', })
|
||||
if car.is_thermal():
|
||||
style_cell_conditional.append({'if': {'column_id': 'consumption_km', }, 'display': 'None', })
|
||||
table_fig = dash_table.DataTable(
|
||||
table_fig = DataTable(
|
||||
id='trips-table',
|
||||
sort_action='custom',
|
||||
sort_by=[{'column_id': 'id', 'direction': 'desc'}],
|
||||
@@ -116,7 +116,7 @@ def get_figures(car: Car):
|
||||
consumption_fig_by_speed.update_layout(xaxis_title="average Speed km/h", yaxis_title="Consumption kWh/100Km")
|
||||
|
||||
# battery_table
|
||||
battery_table = dash_table.DataTable(
|
||||
battery_table = DataTable(
|
||||
id='battery-table',
|
||||
sort_action='custom',
|
||||
sort_by=[{'column_id': 'start_at_str', 'direction': 'desc'}],
|
||||
@@ -199,7 +199,7 @@ def get_battery_curve_fig(row: dict, car: Car):
|
||||
battery_curves.append({"level": row["end_level"], "speed": speed})
|
||||
fig = px.line(battery_curves, x="level", y="speed")
|
||||
fig.update_layout(xaxis_title="Battery %", yaxis_title="Charging speed in kW")
|
||||
return html.Div(dcc.Graph(figure=fig))
|
||||
return html.Div(Graph(figure=fig))
|
||||
|
||||
|
||||
def get_altitude_fig(trip: Trip):
|
||||
@@ -212,4 +212,4 @@ def get_altitude_fig(trip: Trip):
|
||||
fig = px.line(res, x=0, y=1)
|
||||
fig.update_layout(xaxis_title="Distance km", yaxis_title="Altitude m")
|
||||
conn.close()
|
||||
return html.Div(dcc.Graph(figure=fig))
|
||||
return html.Div(Graph(figure=fig))
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
import html
|
||||
|
||||
import dash_bootstrap_components as dbc
|
||||
from dash._utils import create_callback_id
|
||||
from dash.dependencies import Output, Input
|
||||
from web.tools.import_dash_html import html
|
||||
|
||||
from web.app import dash_app
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import dash_bootstrap_components as dbc
|
||||
import dash_daq as daq
|
||||
from web.tools.import_dash_html import html
|
||||
from dash import html
|
||||
from dash.dependencies import Input
|
||||
|
||||
from web.app import dash_app
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import json
|
||||
from logging import DEBUG
|
||||
|
||||
from dash import dcc
|
||||
from dash._utils import create_callback_id
|
||||
from dash.dependencies import Output, Input
|
||||
from web.tools.import_dash_core import dcc
|
||||
|
||||
from mylogger import logger
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import dash_bootstrap_components as dbc
|
||||
from web.tools.import_dash_html import html
|
||||
from dash import html
|
||||
from dash.development.base_component import Component
|
||||
from pandas import DataFrame
|
||||
from pytz import UTC
|
||||
|
||||
+11
-13
@@ -1,4 +1,4 @@
|
||||
from dash import callback_context
|
||||
from dash import callback_context, html, dcc
|
||||
from dash.exceptions import PreventUpdate
|
||||
from flask import request
|
||||
|
||||
@@ -9,14 +9,12 @@ from otp.otp import new_otp_session
|
||||
from web.app import dash_app
|
||||
import dash_bootstrap_components as dbc
|
||||
from dash.dependencies import Output, Input, State
|
||||
from web.tools.import_dash_core import dcc
|
||||
from web.tools.import_dash_html import html
|
||||
|
||||
config = Config()
|
||||
login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, children=[
|
||||
login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, style={"ml": 2}, children=[
|
||||
html.H2('Config'),
|
||||
dbc.Form([
|
||||
dbc.FormGroup([
|
||||
dbc.Row([
|
||||
dbc.Label("Car Brand", html_for="psa-app"),
|
||||
dcc.Dropdown(
|
||||
id="psa-app",
|
||||
@@ -28,7 +26,7 @@ login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, children=[
|
||||
{"label": "Vauxhall", "value": "com.psa.mym.myvauxhall"}
|
||||
],
|
||||
)]),
|
||||
dbc.FormGroup(
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Label("Email", html_for="psa-email"),
|
||||
dbc.Input(type="email", id="psa-email", placeholder="Enter email"),
|
||||
@@ -38,7 +36,7 @@ login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, children=[
|
||||
),
|
||||
]
|
||||
),
|
||||
dbc.FormGroup(
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Label("Password", html_for="psa-password"),
|
||||
dbc.Input(
|
||||
@@ -52,7 +50,7 @@ login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, children=[
|
||||
),
|
||||
]
|
||||
),
|
||||
dbc.FormGroup(
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Label("Country code", html_for="countrycode"),
|
||||
dbc.Input(
|
||||
@@ -66,7 +64,7 @@ login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, children=[
|
||||
)
|
||||
]
|
||||
),
|
||||
dbc.FormGroup([
|
||||
dbc.Row([
|
||||
dbc.Button("Submit", color="primary", id="submit-form"),
|
||||
dbc.FormText(
|
||||
"After submit be patient it can take some time...",
|
||||
@@ -80,21 +78,21 @@ login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, children=[
|
||||
),
|
||||
])]))
|
||||
|
||||
config_otp_layout = dbc.Row(dbc.Col(className="col-md-12 col-lg-2 ml-2", children=[
|
||||
config_otp_layout = dbc.Row(dbc.Col(className="col-md-12 col-lg-2", style={"ml": 2}, children=[
|
||||
html.H2('Config OTP'),
|
||||
dbc.Form([
|
||||
dbc.FormGroup([
|
||||
dbc.Row([
|
||||
dbc.Label("Click to receive a code by SMS", html_for="ask-sms"),
|
||||
dbc.Button("Send SMS", color="info", id="ask-sms"),
|
||||
html.Div(id="sms-demand-result", className="mt-2")
|
||||
]),
|
||||
dbc.FormGroup(
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Label("Write the code you just received by SMS", html_for="psa-email"),
|
||||
dbc.Input(type="text", id="psa-code", placeholder="Enter code"),
|
||||
]
|
||||
),
|
||||
dbc.FormGroup(
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Label("Enter your code PIN", html_for="psa-pin"),
|
||||
dbc.Input(
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import dash_bootstrap_components as dbc
|
||||
from web.tools.import_dash_html import html
|
||||
from dash import html
|
||||
|
||||
from mylogger import logger
|
||||
from web.tools.Button import Button
|
||||
|
||||
+2
-4
@@ -3,6 +3,7 @@ from typing import List
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
import dash_bootstrap_components as dbc
|
||||
from dash import dcc, html
|
||||
from dash.dependencies import Output, Input, State
|
||||
from dash.exceptions import PreventUpdate
|
||||
from flask import jsonify, request, Response as FlaskResponse
|
||||
@@ -23,8 +24,6 @@ from web.utils import diff_dashtable, dash_date_to_datetime
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
from web.tools.figurefilter import FigureFilter
|
||||
from web.tools.import_dash_html import html
|
||||
from web.tools.import_dash_core import dcc
|
||||
from web.utils import create_card
|
||||
from libs.config import Config
|
||||
from web.view.control import get_control_tabs
|
||||
@@ -42,8 +41,7 @@ def add_header(el):
|
||||
return dbc.Row([dbc.Col(dcc.Link(html.H1('My car info'), href="/", style={"text-decoration": "none"})),
|
||||
dbc.Col(dcc.Link(html.Img(src="assets/images/settings.svg", width="30veh"),
|
||||
href="/config",
|
||||
className="float-right"))],
|
||||
className="justify-content-between"), el
|
||||
className="float-end"))]), el
|
||||
|
||||
|
||||
@dash_app.callback(Output('page-content', 'children'),
|
||||
|
||||
Reference in New Issue
Block a user