From 9e3f708d36f82193d56dd649061ded4e6156cc23 Mon Sep 17 00:00:00 2001 From: Romain Fafet Date: Sun, 7 Feb 2021 16:37:43 +0100 Subject: [PATCH 01/11] fix Value Error for position/ --- web/callback.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/callback.py b/web/callback.py index 5158688..613fc8a 100644 --- a/web/callback.py +++ b/web/callback.py @@ -77,9 +77,9 @@ def preconditioning(vin, activate): @app.route('/position/') def get_position(vin): res = myp.get_vehicle_info(vin) - longitude, latitude = res.last_position.geometry.coordinates + longitude, latitude, altitude = res.last_position.geometry.coordinates return jsonify( - {"longitude": longitude, "latitude": latitude, "url": f"http://maps.google.com/maps?q={latitude},{longitude}"}) + {"longitude": longitude, "latitude": latitude, "altitude": altitude, "url": f"http://maps.google.com/maps?q={latitude},{longitude}"}) # Set a battery threshold and schedule an hour to stop the charge From 4458df212e25f40473c286c4361d017ddd22f804 Mon Sep 17 00:00:00 2001 From: Romain Fafet Date: Tue, 9 Feb 2021 00:34:03 +0100 Subject: [PATCH 02/11] fix case when there is no altitude --- web/callback.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/callback.py b/web/callback.py index 613fc8a..74ae744 100644 --- a/web/callback.py +++ b/web/callback.py @@ -77,9 +77,16 @@ def preconditioning(vin, activate): @app.route('/position/') def get_position(vin): res = myp.get_vehicle_info(vin) - longitude, latitude, altitude = res.last_position.geometry.coordinates - return jsonify( - {"longitude": longitude, "latitude": latitude, "altitude": altitude, "url": f"http://maps.google.com/maps?q={latitude},{longitude}"}) + coordinates=res.last_position.geometry.coordinates + if len(coordinates)==3: # altitude is not always availlable + longitude, latitude, altitude = coordinates + return jsonify( + {"longitude": longitude, "latitude": latitude, "altitude": altitude, "url": f"http://maps.google.com/maps?q={latitude},{longitude}"}) + else: + longitude, latitude = coordinates + return jsonify( + {"longitude": longitude, "latitude": latitude, "url": f"http://maps.google.com/maps?q={latitude},{longitude}"}) + # Set a battery threshold and schedule an hour to stop the charge From 3155208001dfdd15753da0788f0b0fe7c280fa45 Mon Sep 17 00:00:00 2001 From: jlayec Date: Sun, 21 Feb 2021 22:49:20 +0000 Subject: [PATCH 03/11] fix charge_control web/callback --- server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 88f2950..3cf0fc8 100755 --- a/server.py +++ b/server.py @@ -66,4 +66,6 @@ if __name__ == "__main__": if args.charge_control: web.app.chc = ChargeControls.load_config(web.app.myp, name=args.charge_control) web.app.chc.start() - save_config(web.app.myp) \ No newline at end of file + save_config(web.app.myp) + t1 = Thread(target=start_app, args=["My car info", args.base_path, args.debug < 20, args.listen, int(args.port)]) + t1.start() From 34b600bc71dc744bb225ad5d085c6d1767c02dfd Mon Sep 17 00:00:00 2001 From: jlayec Date: Mon, 22 Feb 2021 22:13:42 +0100 Subject: [PATCH 04/11] re-fix charge_control web/callback --- server.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/server.py b/server.py index 3cf0fc8..b19aa10 100755 --- a/server.py +++ b/server.py @@ -57,8 +57,6 @@ if __name__ == "__main__": client_password = input("mypeugeot password: ") web.app.myp.connect(client_email, client_password) logger.info(web.app.myp.get_vehicles()) - t1 = Thread(target=start_app, args=["My car info", args.base_path, args.debug < 20, args.listen, int(args.port)]) - t1.start() if args.remote_disable: logger.info("mqtt disabled") else: From 6de8cf8cd265c89517984f0813936194a5aef10c Mon Sep 17 00:00:00 2001 From: Florian BEZANNIER <48728684+flobz@users.noreply.github.com> Date: Sun, 28 Feb 2021 19:13:37 +0100 Subject: [PATCH 05/11] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 752a636..3ad7b29 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -12,9 +12,8 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: -1. what solution did you use (solution 1 or 2) -2. what command did you use -3. when the bug append ? +1. what command did you use +2. when the bug append ? **Config file** Give the anonymize content of the config file From 7c62d5f6eb10bbc5bde44cc22dfb6c91ab939955 Mon Sep 17 00:00:00 2001 From: jlayec Date: Thu, 4 Mar 2021 07:18:45 +0000 Subject: [PATCH 06/11] fix realm to get otp --- MyPSACC.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyPSACC.py b/MyPSACC.py index 3c48dac..fc8be6c 100644 --- a/MyPSACC.py +++ b/MyPSACC.py @@ -233,7 +233,7 @@ class MyPSACC: headers={ "Connection": "Keep-Alive", "User-Agent": "okhttp/4.8.0", - "x-introspect-realm": "clientsB2CPeugeot" + "x-introspect-realm": self.realm }) return res From 5cac905cfdf75b8a76cf7b65c96bd0491c39c7df Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Sat, 6 Mar 2021 16:53:15 +0100 Subject: [PATCH 07/11] handle error in get_charge_hour --- MyPSACC.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/MyPSACC.py b/MyPSACC.py index fc8be6c..53a6d4f 100644 --- a/MyPSACC.py +++ b/MyPSACC.py @@ -366,13 +366,17 @@ class MyPSACC: reg = r"PT([0-9]{1,2})H([0-9]{1,2})?" data = self.get_vehicle_info(vin) hour_str = data.energy[0].charging.next_delayed_time - hour = re.findall(reg, hour_str)[0] - h = int(hour[0]) - if hour[1] == '': - m = 0 - else: - m = hour[1] - return h, m + try: + hour = re.findall(reg, hour_str)[0] + h = int(hour[0]) + if hour[1] == '': + m = 0 + else: + m = hour[1] + return h, m + except IndexError: + logger.error(traceback.format_exc()) + logger.error(f"Can't get charge hour: {hour_str}") def get_charge_status(self, vin): data = self.get_vehicle_info(vin) From 0ea9d603ba66f6e07d17d13f7cefe35d59c98c3a Mon Sep 17 00:00:00 2001 From: Florian BEZANNIER <48728684+flobz@users.noreply.github.com> Date: Sat, 6 Mar 2021 16:56:44 +0100 Subject: [PATCH 08/11] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 3ad7b29..a301ba4 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -21,6 +21,7 @@ Give the anonymize content of the config file **Environment (please complete the following information):** - OS: [e.g. Windows] - Android app Version [e.g. 26.0] + - Brand and model of car **Additional context** Add any other context about the problem here. From cb608af3878368481b1ee6c529e4cee01ccdc465 Mon Sep 17 00:00:00 2001 From: jlayec Date: Sat, 6 Mar 2021 18:07:45 +0000 Subject: [PATCH 09/11] add C5 Aircross in ENERGY_CAPACITY table for hybrid cars --- Car.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Car.py b/Car.py index dffaf42..5106842 100644 --- a/Car.py +++ b/Car.py @@ -3,6 +3,7 @@ import json from MyLogger import logger ENERGY_CAPACITY = {'SUV 3008': {'BATTERY_POWER': 10.8, 'FUEL_CAPACITY': 43}, + 'C5 Aircross': {'BATTERY_POWER': 10.8, 'FUEL_CAPACITY': 43}, 'e-208': {'BATTERY_POWER': 46, 'FUEL_CAPACITY': 0}, 'e-2008': {'BATTERY_POWER': 46, 'FUEL_CAPACITY': 0} } From ed5b33ed238b79d0b81742ec32c9b90b0c69b996 Mon Sep 17 00:00:00 2001 From: jlayec Date: Sat, 6 Mar 2021 18:46:36 +0000 Subject: [PATCH 10/11] fix units --- Trip.py | 4 ++-- web/callback.py | 2 +- web/figures.py | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Trip.py b/Trip.py index aff7954..88102b3 100644 --- a/Trip.py +++ b/Trip.py @@ -143,7 +143,7 @@ class Trips(list): elif distance == 0 and charge > 2: end_trip = True if DEBUG: - logger.debug(f"charge detected {charge}") + logger.debug(f"charge detected") elif speed_average < 0.2 and duration > 0.05: # (distance == 0 and duration > 0.08) or duration > 2 or # check the speed to handle missing point @@ -183,7 +183,7 @@ class Trips(list): if DEBUG: logger.debug( f"Trip: {tr.start_at} -> {tr.end_at} {tr.distance:.1f}km {tr.duration:.2f}h {tr.speed_average:.0f}km/h " - f"{tr.consumption:.2f}kw {tr.consumption_km:.2f}kw/100km {tr.consumption_fuel}L {tr.consumption_fuel_km}L/100km " + f"{tr.consumption:.2f}kWh {tr.consumption_km:.2f}kWh/100km {tr.consumption_fuel}L {tr.consumption_fuel_km}L/100km " f"{tr.mileage:.1f}km") # filter bad value if tr.consumption_km < 70 and ( diff --git a/web/callback.py b/web/callback.py index 3e04325..ab5ccd6 100644 --- a/web/callback.py +++ b/web/callback.py @@ -36,7 +36,7 @@ def display_value(value): filtered_trips.append(trip) filtered_chargings = MyPSACC.get_chargings(min,max) figures.get_figures(filtered_trips,filtered_chargings) - consumption = "Average consumption: {:.1f} kW/100km".format(float(figures.consumption_df.mean(numeric_only=True))) + consumption = "Average consumption: {:.1f} kWh/100km".format(float(figures.consumption_df.mean(numeric_only=True))) return figures.trips_map, figures.consumption_fig, figures.consumption_fig_by_speed, consumption, figures.table_fig, figures.battery_info diff --git a/web/figures.py b/web/figures.py index 88d2bd8..beb2eb8 100644 --- a/web/figures.py +++ b/web/figures.py @@ -77,7 +77,7 @@ def get_figures(trips: List[Trip], charging: List[dict]): {'id': 'speed_average', 'name': 'average speed', 'type': 'numeric', 'format': deepcopy(nb_format).symbol_suffix(" km/h").precision(0)}, {'id': 'consumption_km', 'name': 'average consumption', 'type': 'numeric', - 'format': deepcopy(nb_format).symbol_suffix(" kw/100km")}, + 'format': deepcopy(nb_format).symbol_suffix(" kWh/100km")}, {'id': 'consumption_fuel_km', 'name': 'average consumption fuel', 'type': 'numeric', 'format': deepcopy(nb_format).symbol_suffix(" L/100km")}, {'id': 'distance', 'name': 'distance', 'type': 'numeric', 'format': nb_format.symbol_suffix(" km").precision(1)}, @@ -100,7 +100,7 @@ def get_figures(trips: List[Trip], charging: List[dict]): name="Trips")) consumption_fig_by_speed.update_layout(xaxis_title="average Speed km/h", yaxis_title="Consumption kWh/100Km") kw_per_km = float(consumption_df.mean(numeric_only=True)) - info = "Average consumption: {:.1f} kW/100km".format(kw_per_km) + info = "Average consumption: {:.1f} kWh/100km".format(kw_per_km) # charging charging_data = DataFrame.from_records(charging) @@ -118,6 +118,7 @@ def get_figures(trips: List[Trip], charging: List[dict]): charge_speed = 0 except KeyError: # when there is no data yet: charge_speed = 0 - battery_info = html.Div(children=[html.P("Average gC02/kW: {:.1f}".format(co2_per_kw)), - html.P("Average gC02/km: {:1f}".format(co2_per_km)), - html.P("Average Charge SPEED {:1f} kW/h".format(charge_speed))]) + battery_info = html.Div(children=[ + html.P("Average C02 emission: {:.1f} g/kWh".format(co2_per_kw)), + html.P("Average CO2 emission: {:.1f} g/km".format(co2_per_km)), + html.P("Average charge speed: {:.3f} kW".format(charge_speed))]) From f3e85ebdac37038e121ecf24ff9d7cde67a6b5c3 Mon Sep 17 00:00:00 2001 From: jlayec Date: Sat, 6 Mar 2021 18:50:50 +0000 Subject: [PATCH 11/11] update .gitignore with *.apk and cars.json --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 24a1e98..7b2f69c 100644 --- a/.gitignore +++ b/.gitignore @@ -139,9 +139,11 @@ cython_debug/ .idea/ backup.ab +*.apk info.db otp.bin charge_config1.json config.json test.json charge_config.json +cars.json