From b07e9df308a2fec26d76ee0ae046c5699d0546d1 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 6 Mar 2024 12:36:44 +0100 Subject: [PATCH] Add icon translations to Starline (#112241) --- .../components/starline/binary_sensor.py | 4 - homeassistant/components/starline/button.py | 1 - .../components/starline/device_tracker.py | 5 -- homeassistant/components/starline/icons.json | 79 +++++++++++++++++++ homeassistant/components/starline/lock.py | 7 -- homeassistant/components/starline/sensor.py | 5 -- homeassistant/components/starline/switch.py | 52 ++---------- 7 files changed, 86 insertions(+), 67 deletions(-) create mode 100644 homeassistant/components/starline/icons.json diff --git a/homeassistant/components/starline/binary_sensor.py b/homeassistant/components/starline/binary_sensor.py index c0fe56df71e..958435bfcfd 100644 --- a/homeassistant/components/starline/binary_sensor.py +++ b/homeassistant/components/starline/binary_sensor.py @@ -19,7 +19,6 @@ BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = ( BinarySensorEntityDescription( key="hbrake", translation_key="hand_brake", - icon="mdi:car-brake-parking", ), BinarySensorEntityDescription( key="hood", @@ -45,19 +44,16 @@ BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = ( key="hfree", translation_key="handsfree", entity_category=EntityCategory.DIAGNOSTIC, - icon="mdi:hand-back-right", ), BinarySensorEntityDescription( key="neutral", translation_key="neutral", entity_category=EntityCategory.DIAGNOSTIC, - icon="mdi:car-shift-pattern", ), BinarySensorEntityDescription( key="arm_moving_pb", translation_key="moving_ban", entity_category=EntityCategory.DIAGNOSTIC, - icon="mdi:car-off", ), ) diff --git a/homeassistant/components/starline/button.py b/homeassistant/components/starline/button.py index af6a05206e0..b46faedcff0 100644 --- a/homeassistant/components/starline/button.py +++ b/homeassistant/components/starline/button.py @@ -14,7 +14,6 @@ BUTTON_TYPES: tuple[ButtonEntityDescription, ...] = ( ButtonEntityDescription( key="poke", translation_key="horn", - icon="mdi:bullhorn-outline", ), ) diff --git a/homeassistant/components/starline/device_tracker.py b/homeassistant/components/starline/device_tracker.py index 1ddcbc9373b..06703c30482 100644 --- a/homeassistant/components/starline/device_tracker.py +++ b/homeassistant/components/starline/device_tracker.py @@ -60,8 +60,3 @@ class StarlineDeviceTracker(StarlineEntity, TrackerEntity, RestoreEntity): def source_type(self) -> SourceType: """Return the source type, eg gps or router, of the device.""" return SourceType.GPS - - @property - def icon(self): - """Return the icon to use in the frontend, if any.""" - return "mdi:map-marker-outline" diff --git a/homeassistant/components/starline/icons.json b/homeassistant/components/starline/icons.json new file mode 100644 index 00000000000..b98c4178af1 --- /dev/null +++ b/homeassistant/components/starline/icons.json @@ -0,0 +1,79 @@ +{ + "entity": { + "binary_sensor": { + "hand_brake": { + "default": "mdi:car-brake-parking" + }, + "handsfree": { + "default": "mdi:hand-back-right" + }, + "neutral": { + "default": "mdi:car-shift-pattern" + }, + "moving_ban": { + "default": "mdi:car-off" + } + }, + "button": { + "horn": { + "default": "mdi:bullhorn-outline" + } + }, + "device_tracker": { + "location": { + "default": "mdi:map-marker-outline" + } + }, + "sensor": { + "balance": { + "default": "mdi:cash-multiple" + }, + "fuel": { + "default": "mdi:fuel" + }, + "errors": { + "default": "mdi:alert-octagon" + }, + "mileage": { + "default": "mdi:counter" + }, + "gps_count": { + "default": "mdi:satellite-variant" + } + }, + "switch": { + "engine": { + "default": "mdi:engine-off-outline", + "state": { + "on": "mdi:engine-outline" + } + }, + "webasto": { + "default": "mdi:radiator-off", + "state": { + "on": "mdi:radiator" + } + }, + "additional_channel": { + "default": "mdi:access-point-network-off", + "state": { + "on": "mdi:access-point-network" + } + }, + "horn": { + "default": "mdi:bullhorn-outline" + }, + "service_mode": { + "default": "mdi:car-wrench", + "state": { + "on": "mdi:wrench-clock" + } + } + } + }, + "services": { + "update_state": "mdi:reload", + "set_scan_interval": "mdi:timer", + "set_scan_obd_interval": "mdi:timer" + } +} diff --git a/homeassistant/components/starline/lock.py b/homeassistant/components/starline/lock.py index f663c472a78..104e807aff0 100644 --- a/homeassistant/components/starline/lock.py +++ b/homeassistant/components/starline/lock.py @@ -62,13 +62,6 @@ class StarlineLock(StarlineEntity, LockEntity): """ return self._device.alarm_state - @property - def icon(self) -> str: - """Icon to use in the frontend, if any.""" - return ( - "mdi:shield-check-outline" if self.is_locked else "mdi:shield-alert-outline" - ) - @property def is_locked(self) -> bool | None: """Return true if lock is locked.""" diff --git a/homeassistant/components/starline/sensor.py b/homeassistant/components/starline/sensor.py index 4f02ee1a1f6..f9e6f7b1e0a 100644 --- a/homeassistant/components/starline/sensor.py +++ b/homeassistant/components/starline/sensor.py @@ -33,7 +33,6 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="balance", translation_key="balance", - icon="mdi:cash-multiple", ), SensorEntityDescription( key="ctemp", @@ -55,12 +54,10 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="fuel", translation_key="fuel", - icon="mdi:fuel", ), SensorEntityDescription( key="errors", translation_key="errors", - icon="mdi:alert-octagon", entity_category=EntityCategory.DIAGNOSTIC, ), SensorEntityDescription( @@ -68,12 +65,10 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( translation_key="mileage", native_unit_of_measurement=UnitOfLength.KILOMETERS, device_class=SensorDeviceClass.DISTANCE, - icon="mdi:counter", ), SensorEntityDescription( key="gps_count", translation_key="gps_count", - icon="mdi:satellite-variant", native_unit_of_measurement="satellites", ), ) diff --git a/homeassistant/components/starline/switch.py b/homeassistant/components/starline/switch.py index ef24dd52c02..13de0272284 100644 --- a/homeassistant/components/starline/switch.py +++ b/homeassistant/components/starline/switch.py @@ -1,7 +1,6 @@ """Support for StarLine switch.""" from __future__ import annotations -from dataclasses import dataclass from typing import Any from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription @@ -14,53 +13,27 @@ from .account import StarlineAccount, StarlineDevice from .const import DOMAIN from .entity import StarlineEntity - -@dataclass(frozen=True) -class StarlineRequiredKeysMixin: - """Mixin for required keys.""" - - icon_on: str - icon_off: str - - -@dataclass(frozen=True) -class StarlineSwitchEntityDescription( - SwitchEntityDescription, StarlineRequiredKeysMixin -): - """Describes Starline switch entity.""" - - -SWITCH_TYPES: tuple[StarlineSwitchEntityDescription, ...] = ( - StarlineSwitchEntityDescription( +SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = ( + SwitchEntityDescription( key="ign", translation_key="engine", - icon_on="mdi:engine-outline", - icon_off="mdi:engine-off-outline", ), - StarlineSwitchEntityDescription( + SwitchEntityDescription( key="webasto", translation_key="webasto", - icon_on="mdi:radiator", - icon_off="mdi:radiator-off", ), - StarlineSwitchEntityDescription( + SwitchEntityDescription( key="out", translation_key="additional_channel", - icon_on="mdi:access-point-network", - icon_off="mdi:access-point-network-off", ), # Deprecated and should be removed in 2024.8 - StarlineSwitchEntityDescription( + SwitchEntityDescription( key="poke", translation_key="horn", - icon_on="mdi:bullhorn-outline", - icon_off="mdi:bullhorn-outline", ), - StarlineSwitchEntityDescription( + SwitchEntityDescription( key="valet", translation_key="service_mode", - icon_on="mdi:wrench-clock", - icon_off="mdi:car-wrench", ), ) @@ -83,15 +56,13 @@ async def async_setup_entry( class StarlineSwitch(StarlineEntity, SwitchEntity): """Representation of a StarLine switch.""" - entity_description: StarlineSwitchEntityDescription - _attr_assumed_state = True def __init__( self, account: StarlineAccount, device: StarlineDevice, - description: StarlineSwitchEntityDescription, + description: SwitchEntityDescription, ) -> None: """Initialize the switch.""" super().__init__(account, device, description.key) @@ -109,15 +80,6 @@ class StarlineSwitch(StarlineEntity, SwitchEntity): return self._account.engine_attrs(self._device) return None - @property - def icon(self): - """Icon to use in the frontend, if any.""" - return ( - self.entity_description.icon_on - if self.is_on - else self.entity_description.icon_off - ) - @property def is_on(self): """Return True if entity is on."""