From fe8b0fd41ae72fef4a84eabb9c1ab99e3bdc1155 Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Tue, 12 Nov 2024 20:13:41 +0100 Subject: [PATCH 1/9] Change range to use driving_range.total_range_in_km Changed range to use value from driving_range.total_range_in_km instead of a value from charging (so it can be used by all engine types) --- custom_components/myskoda/sensor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/custom_components/myskoda/sensor.py b/custom_components/myskoda/sensor.py index c34f437..a441efb 100644 --- a/custom_components/myskoda/sensor.py +++ b/custom_components/myskoda/sensor.py @@ -176,9 +176,11 @@ class RemainingDistance(ChargingSensor): @property def native_value(self) -> int | float | None: # noqa: D102 - if status := self._status(): - if status.battery.remaining_cruising_range_in_meters is not None: - return status.battery.remaining_cruising_range_in_meters / 1000 + if range := self.vehicle.driving_range: + return range.total_range_in_km + + def required_capabilities(self) -> list[CapabilityId]: + return [CapabilityId.STATE] class TargetBatteryPercentage(ChargingSensor): From 43cda207a694bdd884d99e42724d10eaca3b7a12 Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 09:34:56 +0100 Subject: [PATCH 2/9] fixed lint error, changed to MySkodaSensor, icon based on engine --- custom_components/myskoda/icons.json | 3 --- custom_components/myskoda/sensor.py | 14 +++++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/custom_components/myskoda/icons.json b/custom_components/myskoda/icons.json index 756d0fa..5afebf3 100644 --- a/custom_components/myskoda/icons.json +++ b/custom_components/myskoda/icons.json @@ -92,9 +92,6 @@ "mileage": { "default": "mdi:counter" }, - "range": { - "default": "mdi:speedometer" - }, "remaining_charging_time": { "default": "mdi:timer" }, diff --git a/custom_components/myskoda/sensor.py b/custom_components/myskoda/sensor.py index a441efb..b861587 100644 --- a/custom_components/myskoda/sensor.py +++ b/custom_components/myskoda/sensor.py @@ -23,6 +23,7 @@ from myskoda.models import charging from myskoda.models.charging import Charging, ChargingStatus from myskoda.models.info import CapabilityId +from myskoda.models.driving_range import EngineType from .const import COORDINATORS, DOMAIN from .entity import MySkodaEntity @@ -46,7 +47,7 @@ async def async_setup_entry( LastUpdated, Mileage, RemainingChargingTime, - RemainingDistance, + Range, SoftwareVersion, TargetBatteryPercentage, InspectionInterval, @@ -163,8 +164,8 @@ def native_value(self) -> float | None: # noqa: D102 return status.charge_power_in_kw -class RemainingDistance(ChargingSensor): - """Estimated range of an electric vehicle in km.""" +class Range(MySkodaSensor): + """Estimated range of vehicle in km.""" entity_description = SensorEntityDescription( key="range", @@ -174,6 +175,13 @@ class RemainingDistance(ChargingSensor): translation_key="range", ) + @property + def icon(self) -> str: # noqa: D102 + if self.vehicle.driving_range.car_type == EngineType.ELECTRIC: + return "mdi:ev-station" + else: + return "mdi:gas-station" + @property def native_value(self) -> int | float | None: # noqa: D102 if range := self.vehicle.driving_range: From 938425b93341c4088e194de2579f187f21a9b4ee Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 10:40:13 +0100 Subject: [PATCH 3/9] fixing merge conflict --- custom_components/myskoda/icons.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/custom_components/myskoda/icons.json b/custom_components/myskoda/icons.json index 5afebf3..893865a 100644 --- a/custom_components/myskoda/icons.json +++ b/custom_components/myskoda/icons.json @@ -89,9 +89,18 @@ "inspection": { "default": "mdi:car-wrench" }, + "inspection_in_km": { + "default": "mdi:car-wrench" + }, "mileage": { "default": "mdi:counter" }, + "oil_service_in_days": { + "default": "mdi:oil" + }, + "oil_service_in_km": { + "default": "mdi:oil" + }, "remaining_charging_time": { "default": "mdi:timer" }, From b74b699a81605cb536979ee296036ddf51660b78 Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 10:54:10 +0100 Subject: [PATCH 4/9] fixing merge conflict --- custom_components/myskoda/icons.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom_components/myskoda/icons.json b/custom_components/myskoda/icons.json index 893865a..b4a5edf 100644 --- a/custom_components/myskoda/icons.json +++ b/custom_components/myskoda/icons.json @@ -101,6 +101,9 @@ "oil_service_in_km": { "default": "mdi:oil" }, + "range": { + "default": "mdi:speedometer" + }, "remaining_charging_time": { "default": "mdi:timer" }, From 2351ce503010d42e96b08bfc373267a82a3592ef Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 10:56:18 +0100 Subject: [PATCH 5/9] removed range icon from icons.json --- custom_components/myskoda/icons.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/custom_components/myskoda/icons.json b/custom_components/myskoda/icons.json index cd80795..852de18 100644 --- a/custom_components/myskoda/icons.json +++ b/custom_components/myskoda/icons.json @@ -101,9 +101,6 @@ "oil_service_in_km": { "default": "mdi:oil" }, - "range": { - "default": "mdi:speedometer" - }, "remaining_charging_time": { "default": "mdi:timer" }, From 2e0a18201f6c093f1279a99828ddaaa19abe8e70 Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 11:07:06 +0100 Subject: [PATCH 6/9] fixed lint error --- custom_components/myskoda/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/myskoda/sensor.py b/custom_components/myskoda/sensor.py index 79ff414..d857f25 100644 --- a/custom_components/myskoda/sensor.py +++ b/custom_components/myskoda/sensor.py @@ -189,7 +189,7 @@ def icon(self) -> str: # noqa: D102 def native_value(self) -> int | float | None: # noqa: D102 if range := self.vehicle.driving_range: return range.total_range_in_km - + def required_capabilities(self) -> list[CapabilityId]: return [CapabilityId.STATE] From 37a20763b2973b916c8eab002241ec7436e9a7f8 Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 11:25:26 +0100 Subject: [PATCH 7/9] added default icon if car_type not defined --- custom_components/myskoda/sensor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/custom_components/myskoda/sensor.py b/custom_components/myskoda/sensor.py index d857f25..ca7f51b 100644 --- a/custom_components/myskoda/sensor.py +++ b/custom_components/myskoda/sensor.py @@ -180,10 +180,13 @@ class Range(MySkodaSensor): @property def icon(self) -> str: # noqa: D102 - if self.vehicle.driving_range.car_type == EngineType.ELECTRIC: - return "mdi:ev-station" - else: + if vehicle.vehicle.driving_range is None or vehicle.vehicle.driving_range.car_type is None: return "mdi:gas-station" + else: + if self.vehicle.driving_range.car_type == EngineType.ELECTRIC: + return "mdi:ev-station" + else: + return "mdi:gas-station" @property def native_value(self) -> int | float | None: # noqa: D102 From b486e6b6669ee5fba5e792d3d834f212011048e4 Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 11:33:39 +0100 Subject: [PATCH 8/9] fixed code --- custom_components/myskoda/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/myskoda/sensor.py b/custom_components/myskoda/sensor.py index ca7f51b..b84d6bc 100644 --- a/custom_components/myskoda/sensor.py +++ b/custom_components/myskoda/sensor.py @@ -180,7 +180,7 @@ class Range(MySkodaSensor): @property def icon(self) -> str: # noqa: D102 - if vehicle.vehicle.driving_range is None or vehicle.vehicle.driving_range.car_type is None: + if self.vehicle.driving_range is None or self.vehicle.driving_range.car_type is None: return "mdi:gas-station" else: if self.vehicle.driving_range.car_type == EngineType.ELECTRIC: From 3ccbb574f2c40aca39281a41713bd02b3846db94 Mon Sep 17 00:00:00 2001 From: Tomas Prvak Date: Wed, 13 Nov 2024 11:53:59 +0100 Subject: [PATCH 9/9] fixed lint error --- custom_components/myskoda/sensor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/myskoda/sensor.py b/custom_components/myskoda/sensor.py index b84d6bc..5e2a3b3 100644 --- a/custom_components/myskoda/sensor.py +++ b/custom_components/myskoda/sensor.py @@ -180,7 +180,10 @@ class Range(MySkodaSensor): @property def icon(self) -> str: # noqa: D102 - if self.vehicle.driving_range is None or self.vehicle.driving_range.car_type is None: + if ( + self.vehicle.driving_range is None + or self.vehicle.driving_range.car_type is None + ): return "mdi:gas-station" else: if self.vehicle.driving_range.car_type == EngineType.ELECTRIC: