Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change range to work with all car types, make icon car-type dependant #268

Merged
merged 10 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions custom_components/myskoda/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@
"oil_service_in_km": {
"default": "mdi:oil"
},
"range": {
"default": "mdi:speedometer"
},
"remaining_charging_time": {
"default": "mdi:timer"
},
Expand Down
28 changes: 22 additions & 6 deletions custom_components/myskoda/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +47,7 @@ async def async_setup_entry(
LastUpdated,
Mileage,
RemainingChargingTime,
RemainingDistance,
Range,
SoftwareVersion,
TargetBatteryPercentage,
InspectionInterval,
Expand Down Expand Up @@ -166,8 +167,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",
Expand All @@ -177,11 +178,26 @@ class RemainingDistance(ChargingSensor):
translation_key="range",
)

@property
def icon(self) -> str: # noqa: D102
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:
return "mdi:ev-station"
else:
return "mdi:gas-station"

@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:
prvakt marked this conversation as resolved.
Show resolved Hide resolved
return range.total_range_in_km

def required_capabilities(self) -> list[CapabilityId]:
return [CapabilityId.STATE]


class TargetBatteryPercentage(ChargingSensor):
Expand Down