diff --git a/custom_components/myskoda/device_tracker.py b/custom_components/myskoda/device_tracker.py index cbdf2e4..ad8f1d4 100644 --- a/custom_components/myskoda/device_tracker.py +++ b/custom_components/myskoda/device_tracker.py @@ -9,8 +9,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import DiscoveryInfoType + from myskoda.models.info import CapabilityId -from myskoda.models.position import Position, PositionType, Positions +from myskoda.models.position import Position, Positions, PositionType from .const import COORDINATORS, DOMAIN from .coordinator import MySkodaDataUpdateCoordinator @@ -80,5 +81,14 @@ def longitude(self) -> float | None: # noqa: D102 return None return position.gps_coordinates.longitude + @property + def extra_state_attributes(self) -> dict: + """Return extra state attributes.""" + attributes = {} + if render := self.get_renders().get("main"): + attributes["entity_picture"] = render + + return attributes + def required_capabilities(self) -> list[CapabilityId]: return [CapabilityId.PARKING_POSITION] diff --git a/custom_components/myskoda/entity.py b/custom_components/myskoda/entity.py index 9153b21..e00afad 100644 --- a/custom_components/myskoda/entity.py +++ b/custom_components/myskoda/entity.py @@ -2,6 +2,7 @@ from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity + from myskoda import Vehicle from myskoda.models.info import CapabilityId @@ -48,3 +49,11 @@ def is_supported(self) -> bool: return all( self.vehicle.has_capability(cap) for cap in self.required_capabilities() ) + + def get_renders(self) -> dict[str, str]: + """Return a dict of all vehicle image render URLs, keyed by view_point. + + E.g. + {"main": "https://ip-modcwp.azureedge.net/path/render.png"} + """ + return {render.view_point: render.url for render in self.vehicle.info.renders} diff --git a/custom_components/myskoda/sensor.py b/custom_components/myskoda/sensor.py index 941dd72..ef457eb 100644 --- a/custom_components/myskoda/sensor.py +++ b/custom_components/myskoda/sensor.py @@ -11,6 +11,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import DiscoveryInfoType + from myskoda.models import charging from myskoda.models.charging import Charging, ChargingStatus from myskoda.models.info import CapabilityId @@ -30,16 +31,17 @@ async def async_setup_entry( """Set up the sensor platform.""" add_supported_entities( available_entities=[ - SoftwareVersion, - RemainingDistance, - Mileage, - LastUpdated, - TargetBatteryPercentage, + BatteryPercentage, ChargeType, + ChargingPower, ChargingState, + LastUpdated, + MainRender, + Mileage, RemainingChargingTime, - BatteryPercentage, - ChargingPower, + RemainingDistance, + SoftwareVersion, + TargetBatteryPercentage, ], coordinators=hass.data[DOMAIN][config.entry_id][COORDINATORS], async_add_entities=async_add_entities, @@ -317,3 +319,18 @@ def native_value(self): # noqa: D102 def required_capabilities(self) -> list[CapabilityId]: return [CapabilityId.STATE] + + +class MainRender(MySkodaSensor): + """URL of the main image render of the vehicle.""" + + entity_description = SensorEntityDescription( + key="render_url_main", + name="Main Render URL", + icon="mdi:file-image", + translation_key="render_url_main", + ) + + @property + def native_value(self): # noqa: D102 + return self.get_renders().get("main")