From ea0f7e3c44c24836793521122218e37bb10c92da Mon Sep 17 00:00:00 2001 From: pablobuenaposada Date: Sun, 5 Jan 2025 14:27:12 +0100 Subject: [PATCH] change default setup --- default_setup.json | 64 ++++++++----------- src/bench/demo.py | 2 +- src/devices/setup_updater.py | 52 ++++++++++----- .../setup_updater/test_setup_updater.py | 15 ++++- src/tests/devices/test_setup_file.py | 4 +- 5 files changed, 78 insertions(+), 59 deletions(-) diff --git a/default_setup.json b/default_setup.json index 3451e9b..cc5ae3d 100644 --- a/default_setup.json +++ b/default_setup.json @@ -48,8 +48,13 @@ "sectors": [ { "lo": 0, - "hi": 100, - "color": "#46877f" + "hi": 70, + "color": "#cc2c24" + }, + { + "lo": 86, + "hi": 255, + "color": "#cc2c24" } ] }, @@ -61,13 +66,7 @@ "tag": "gauge7", "label": "CAM", "suffix": "", - "sectors": [ - { - "lo": 0, - "hi": 100, - "color": "#46877f" - } - ] + "sectors": [] }, "bat": { "tag": "gauge6", @@ -77,13 +76,13 @@ "sectors": [ { "lo": 0, - "hi": 12, + "hi": 13, "color": "#cc2c24" }, { - "lo": 12, - "hi": 20, - "color": "#46877f" + "lo": 15, + "hi": 26, + "color": "#cc2c24" } ] }, @@ -95,8 +94,8 @@ "sectors": [ { "lo": 0, - "hi": 100, - "color": "#46877f" + "hi": 110, + "color": "#41748d" } ] }, @@ -107,9 +106,9 @@ "suffix": "", "sectors": [ { - "lo": 0, - "hi": 70, - "color": "#46877f" + "lo": 60, + "hi": 150, + "color": "#cc2c24" } ] }, @@ -120,14 +119,14 @@ "suffix": "", "sectors": [ { - "lo": 94, - "hi": 150, - "color": "#cc2c24" + "lo": -40, + "hi": 60, + "color": "#46877f" }, { - "lo": 0, - "hi": 94, - "color": "#46877f" + "lo": 104, + "hi": 150, + "color": "#cc2c24" } ] }, @@ -140,16 +139,11 @@ "sectors": [ { "lo": 0, - "hi": 12, + "hi": 11.6, "color": "#cc2c24" }, { - "lo": 12, - "hi": 16, - "color": "#46877f" - }, - { - "lo": 16, + "lo": 14.71, "hi": 30, "color": "#cc2c24" } @@ -161,13 +155,7 @@ "decimals": 1, "label": "MAP", "suffix": "", - "sectors": [ - { - "lo": 0, - "hi": 3, - "color": "#46877f" - } - ] + "sectors": [] }, "an0": { "tag": "not use", diff --git a/src/bench/demo.py b/src/bench/demo.py index a4940b1..7c0ee8c 100755 --- a/src/bench/demo.py +++ b/src/bench/demo.py @@ -16,7 +16,7 @@ backend.ecu.ecu.data5 = [0 for _ in range(20)] while True: - numbers = range(random.choice(range(255)), random.choice(range(255))) + numbers = range(255) numbers = numbers if bool(random.getrandbits(1)) else reversed(numbers) for number in numbers: backend.ecu.ecu.data0 = [number for _ in range(38)] diff --git a/src/devices/setup_updater.py b/src/devices/setup_updater.py index 4308371..a567500 100644 --- a/src/devices/setup_updater.py +++ b/src/devices/setup_updater.py @@ -33,6 +33,9 @@ def update(self, setup): setup = self._update_to_3_5_0(setup) if setup["version"] == "3.5.0": setup = self._update_to_3_6_0(setup) + if setup["version"] == "3.6.0": + setup = self._update_to_4_0_0(setup) + return setup @staticmethod @@ -130,21 +133,38 @@ def _update_to_3_6_0(setup): def _update_to_4_0_0(setup): """From 3.6.0 to 4.0.0""" setup["version"] = "4.0.0" - setup["tps"]["tag"] = "bar3" + setup.update() + if "tag" in setup: + setup["tps"]["tag"] = "bar3" setup["template"] = "basic" - setup["o2"].pop("max", None) - setup["map"].pop("max", None) - setup["iat"].pop("max", None) - setup["eth"].pop("max", None) - setup["ect"].pop("max", None) - setup["cam"].pop("max", None) - setup["bat"].pop("max", None) - setup["an0"].pop("max", None) - setup["an1"].pop("max", None) - setup["an2"].pop("max", None) - setup["an3"].pop("max", None) - setup["an4"].pop("max", None) - setup["an5"].pop("max", None) - setup["an6"].pop("max", None) - setup["an7"].pop("max", None) + if "o2" in setup: + setup["o2"].pop("max", None) + if "map" in setup: + setup["map"].pop("max", None) + if "iat" in setup: + setup["iat"].pop("max", None) + if "eth" in setup: + setup["eth"].pop("max", None) + if "ect" in setup: + setup["ect"].pop("max", None) + if "cam" in setup: + setup["cam"].pop("max", None) + if "bat" in setup: + setup["bat"].pop("max", None) + if "an0" in setup: + setup["an0"].pop("max", None) + if "an1" in setup: + setup["an1"].pop("max", None) + if "an2" in setup: + setup["an2"].pop("max", None) + if "an3" in setup: + setup["an3"].pop("max", None) + if "an4" in setup: + setup["an4"].pop("max", None) + if "an5" in setup: + setup["an5"].pop("max", None) + if "an6" in setup: + setup["an6"].pop("max", None) + if "an7" in setup: + setup["an7"].pop("max", None) return setup diff --git a/src/tests/devices/setup_updater/test_setup_updater.py b/src/tests/devices/setup_updater/test_setup_updater.py index dd37860..f01f47a 100644 --- a/src/tests/devices/setup_updater/test_setup_updater.py +++ b/src/tests/devices/setup_updater/test_setup_updater.py @@ -82,10 +82,21 @@ def test_update_3_4_0(self): assert m__update_to_3_5_0.called is True def test_update_3_5_0(self): - assert SetupUpdater().update({"version": "3.5.0"}) == {"version": "3.6.0"} + with mock.patch( + "devices.setup_updater.SetupUpdater._update_to_3_6_0" + ) as m__update_to_3_6_0: + SetupUpdater().update({"version": "3.5.0"}) + assert m__update_to_3_6_0.called is True def test_update_3_6_0(self): - assert SetupUpdater().update({"version": "3.6.0"}) == {"version": "3.6.0"} + with mock.patch( + "devices.setup_updater.SetupUpdater._update_to_4_0_0" + ) as m__update_to_4_0_0: + SetupUpdater().update({"version": "3.6.0"}) + assert m__update_to_4_0_0.called is True + + def test_update_4_0_0(self): + assert SetupUpdater().update({"version": "4.0.0"}) == {"version": "4.0.0"} def test__update_to_2_4_0(self, fixtures_dir): with open(os.path.join(fixtures_dir, "default_setup_2_3_2.json")) as file: diff --git a/src/tests/devices/test_setup_file.py b/src/tests/devices/test_setup_file.py index d2bda43..ddafa21 100644 --- a/src/tests/devices/test_setup_file.py +++ b/src/tests/devices/test_setup_file.py @@ -143,7 +143,7 @@ def test_update_key(self): assert self.setup.get_value("tps") == { "label": "TPS", "max": 100, - "sectors": [{"color": "#46877f", "hi": 100, "lo": 0}], + "sectors": [{"color": "#41748d", "hi": 110, "lo": 0}], "suffix": "", "tag": "bar3", } @@ -151,7 +151,7 @@ def test_update_key(self): assert self.setup.get_value("tps") == { "label": "foo", "max": 100, - "sectors": [{"color": "#46877f", "hi": 100, "lo": 0}], + "sectors": [{"color": "#41748d", "hi": 110, "lo": 0}], "suffix": "", "tag": "bar3", }