Skip to content

Commit

Permalink
Change mainrender sensor to image (#131)
Browse files Browse the repository at this point in the history
* Convert main render from sensor to image
  • Loading branch information
WebSpider authored Oct 23, 2024
1 parent 06ce0ea commit 1533cb6
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 24 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ repos:
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.385
hooks:
- id: pyright
- repo: https://github.com/python-poetry/poetry
rev: 1.8.3
hooks:
Expand Down
1 change: 1 addition & 0 deletions custom_components/myskoda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Platform.SWITCH,
Platform.NUMBER,
Platform.BINARY_SENSOR,
Platform.IMAGE,
]


Expand Down
8 changes: 5 additions & 3 deletions custom_components/myskoda/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"default": "mdi:battery-lock"
}
},
"image": {
"render_url_main": {
"default": "mdi:file-image"
}
},
"sensor": {
"car_captured": {
"default": "mdi:clock"
Expand Down Expand Up @@ -93,9 +98,6 @@
"remaining_charging_time": {
"default": "mdi:timer"
},
"render_url_main": {
"default": "mdi:file-image"
},
"software_version": {
"default": "mdi:update"
},
Expand Down
74 changes: 74 additions & 0 deletions custom_components/myskoda/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Images for the MySkoda integration."""

import logging

from homeassistant.components.image import (
ImageEntity,
ImageEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
EntityCategory,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import DiscoveryInfoType # pyright: ignore [reportAttributeAccessIssue]

from .const import COORDINATORS, DOMAIN
from .coordinator import MySkodaDataUpdateCoordinator
from .entity import MySkodaEntity

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant,
config: ConfigEntry,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the image platform."""

entities = []
for vin in hass.data[DOMAIN][config.entry_id][COORDINATORS]:
for SensorClass in [MainRenderImage]:
entities.append(
SensorClass(
hass.data[DOMAIN][config.entry_id][COORDINATORS][vin], vin, hass
)
)

async_add_entities(entities)


class MySkodaImage(MySkodaEntity, ImageEntity):
"""Representation of an Image for MySkoda."""

vin: str
coordinator: MySkodaDataUpdateCoordinator
hass: HomeAssistant

def __init__(
self,
coordinator: MySkodaDataUpdateCoordinator,
vin: str,
hass: HomeAssistant,
) -> None:
"""Initialize the Image for MySkoda."""
ImageEntity.__init__(self, hass)
super().__init__(coordinator, vin)


class MainRenderImage(MySkodaImage):
"""Main render of the vehicle."""

entity_description = ImageEntityDescription(
key="render_vehicle_main",
name="Main Vehicle Render",
translation_key="render_vehicle_main",
entity_category=EntityCategory.DIAGNOSTIC,
)

@property
def image_url(self) -> str | None:
return self.get_renders().get("main")
17 changes: 0 additions & 17 deletions custom_components/myskoda/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
UnitOfLength,
UnitOfPower,
UnitOfTime,
EntityCategory,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -43,7 +42,6 @@ async def async_setup_entry(
ChargingPower,
ChargingState,
LastUpdated,
MainRender,
Mileage,
RemainingChargingTime,
RemainingDistance,
Expand Down Expand Up @@ -314,18 +312,3 @@ def native_value(self) -> datetime | None: # 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",
translation_key="render_url_main",
entity_category=EntityCategory.DIAGNOSTIC,
)

@property
def native_value(self): # noqa: D102
return self.get_renders().get("main")
5 changes: 5 additions & 0 deletions custom_components/myskoda/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
"name": "Charge Limit"
}
},
"image": {
"render_vehicle_main": {
"name": "Main Render of Vehicle"
}
},
"sensor": {
"software_version": {
"name": "Software Version"
Expand Down

0 comments on commit 1533cb6

Please sign in to comment.