From 72753b5a097d973b4559d0beb1aeebf409211818 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Sat, 23 Oct 2021 11:05:02 +0200 Subject: [PATCH] fix deprecated and myp not found --- libs/config.py | 1 + web/figures.py | 8 ++++---- web/tools/Button.py | 2 +- web/tools/Switch.py | 2 +- web/tools/figurefilter.py | 7 ++++--- web/tools/import_dash_core.py | 5 +++++ web/tools/import_dash_html.py | 5 +++++ web/utils.py | 2 +- web/view/config_views.py | 5 +++-- web/view/control.py | 2 +- web/view/views.py | 4 ++-- 11 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 web/tools/import_dash_core.py create mode 100644 web/tools/import_dash_html.py diff --git a/libs/config.py b/libs/config.py index f39fd0f..efda32f 100644 --- a/libs/config.py +++ b/libs/config.py @@ -94,6 +94,7 @@ class Config(metaclass=Singleton): logger.info(str(self.myp.get_vehicles())) self.is_good = True else: + self.is_good = False logger.error("Please reconnect by going to config web page") if self.args.refresh: self.myp.info_refresh_rate = self.args.refresh * 60 diff --git a/web/figures.py b/web/figures.py index dd74270..c024fae 100644 --- a/web/figures.py +++ b/web/figures.py @@ -3,11 +3,11 @@ from statistics import mean import dash_bootstrap_components as dbc import dash_table -from dash_core_components import Graph from dash_table.Format import Format, Scheme, Symbol import plotly.express as px import plotly.graph_objects as go -import dash_html_components as html +from web.tools.import_dash_html import html +from web.tools.import_dash_core import dcc from libs.car import Car from libs.elec_price import ElecPrice @@ -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(Graph(figure=fig)) + return html.Div(dcc.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(Graph(figure=fig)) + return html.Div(dcc.Graph(figure=fig)) diff --git a/web/tools/Button.py b/web/tools/Button.py index 582e73c..5292e8d 100644 --- a/web/tools/Button.py +++ b/web/tools/Button.py @@ -1,7 +1,7 @@ import dash_bootstrap_components as dbc from dash._utils import create_callback_id from dash.dependencies import Output, Input -import dash_html_components as html +from web.tools.import_dash_html import html from web.app import dash_app diff --git a/web/tools/Switch.py b/web/tools/Switch.py index 0321688..33e7cab 100644 --- a/web/tools/Switch.py +++ b/web/tools/Switch.py @@ -1,6 +1,6 @@ import dash_bootstrap_components as dbc import dash_daq as daq -import dash_html_components as html +from web.tools.import_dash_html import html from dash.dependencies import Input from web.app import dash_app diff --git a/web/tools/figurefilter.py b/web/tools/figurefilter.py index 722d9f6..3afc56d 100644 --- a/web/tools/figurefilter.py +++ b/web/tools/figurefilter.py @@ -3,7 +3,8 @@ from logging import DEBUG from dash._utils import create_callback_id from dash.dependencies import Output, Input -from dash_core_components import Store +from web.tools.import_dash_core import dcc + from mylogger import logger @@ -135,5 +136,5 @@ class FigureFilter: return False def get_store(self): - return [Store(id='clientside-figure-store', data=self.__get_figures()), - Store(id='clientside-data-store', data=self.src)] + return [dcc.Store(id='clientside-figure-store', data=self.__get_figures()), + dcc.Store(id='clientside-data-store', data=self.src)] diff --git a/web/tools/import_dash_core.py b/web/tools/import_dash_core.py new file mode 100644 index 0000000..153011d --- /dev/null +++ b/web/tools/import_dash_core.py @@ -0,0 +1,5 @@ +# pylint: disable=unused-import +try: + from dash import dcc +except ImportError: + import dash_core_components as dcc diff --git a/web/tools/import_dash_html.py b/web/tools/import_dash_html.py new file mode 100644 index 0000000..3f7d5f4 --- /dev/null +++ b/web/tools/import_dash_html.py @@ -0,0 +1,5 @@ +# pylint: disable=unused-import +try: + from dash import html +except ImportError: + import dash_html_components as html diff --git a/web/utils.py b/web/utils.py index c584bd1..c0e88d5 100644 --- a/web/utils.py +++ b/web/utils.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta import dash_bootstrap_components as dbc -import dash_html_components as html +from web.tools.import_dash_html import html from dash.development.base_component import Component from pandas import DataFrame from pytz import UTC diff --git a/web/view/config_views.py b/web/view/config_views.py index c42ab6c..7baabc6 100644 --- a/web/view/config_views.py +++ b/web/view/config_views.py @@ -9,8 +9,8 @@ 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 -import dash_core_components as dcc -import dash_html_components as html +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=[ @@ -147,6 +147,7 @@ def connectPSA(n_clicks, app_name, email, password, countrycode): # pylint: dis try: res = firstLaunchConfig(app_name, email, password, countrycode) config.load_app() + config.start_remote_control() return dbc.Alert([res, html.A(" Go to otp config", href=request.url_root + "config_otp")], color="success") except Exception as e: res = str(e) diff --git a/web/view/control.py b/web/view/control.py index 3e59568..6386375 100644 --- a/web/view/control.py +++ b/web/view/control.py @@ -1,5 +1,5 @@ import dash_bootstrap_components as dbc -import dash_html_components as html +from web.tools.import_dash_html import html from mylogger import logger from web.tools.Button import Button diff --git a/web/view/views.py b/web/view/views.py index 5c56cc5..ae06b25 100644 --- a/web/view/views.py +++ b/web/view/views.py @@ -5,8 +5,6 @@ from urllib.parse import parse_qs, urlparse import dash_bootstrap_components as dbc from dash.dependencies import Output, Input, State from dash.exceptions import PreventUpdate -import dash_core_components as dcc -import dash_html_components as html from flask import jsonify, request, Response as FlaskResponse import web.utils @@ -25,6 +23,8 @@ 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