Skip to content

Commit

Permalink
Add image render sensor and in device tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
dvx76 committed Oct 15, 2024
1 parent a965c90 commit 4a5de6e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
12 changes: 11 additions & 1 deletion custom_components/myskoda/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
9 changes: 9 additions & 0 deletions custom_components/myskoda/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}
31 changes: 24 additions & 7 deletions custom_components/myskoda/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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")

0 comments on commit 4a5de6e

Please sign in to comment.