Skip to content

Commit

Permalink
Migrate Entity icons to icons.json file (#114)
Browse files Browse the repository at this point in the history
* Migrate all Entity icons to icons.json file

* Fix JSON to have state key as well
  • Loading branch information
WebSpider authored Oct 22, 2024
1 parent a26bff5 commit 6c1b036
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 64 deletions.
30 changes: 0 additions & 30 deletions custom_components/myskoda/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ def is_on(self) -> bool | None: # noqa: D102
if ac := self._air_conditioning():
return ac.charger_connection_state == common.ConnectionState.CONNECTED

@property
def icon(self) -> str: # noqa: D102
if self.is_on:
return "mdi:power-plug"
return "mdi:power-plug-off"


class ChargerLocked(AirConditioningBinarySensor):
"""Detect if the charger is locked on the car, or whether it can be unplugged."""
Expand All @@ -109,12 +103,6 @@ def is_on(self) -> bool | None: # noqa: D102
if ac.charger_lock_state != ChargerLockedState.INVALID:
return ac.charger_lock_state != common.ChargerLockedState.LOCKED

@property
def icon(self) -> str: # noqa: D102
if self.is_on:
return "mdi:lock-open"
return "mdi:lock"


class Locked(StatusBinarySensor):
"""Detects whether the vehicle is fully locked."""
Expand All @@ -133,12 +121,6 @@ def is_on(self) -> bool | None: # noqa: D102
if status := self._status():
return not status.overall.locked == DoorLockedState.LOCKED

@property
def icon(self) -> str: # noqa: D102
if self.is_on:
return "mdi:lock-open"
return "mdi:lock"


class DoorsLocked(StatusBinarySensor):
"""Detect whether the doors are locked."""
Expand All @@ -155,12 +137,6 @@ def is_on(self) -> bool | None: # noqa: D102
if status := self._status():
return not status.overall.doors_locked == DoorLockedState.LOCKED

@property
def icon(self) -> str: # noqa: D102
if self.is_on:
return "mdi:car-door-lock-open"
return "mdi:car-door-lock"


class DoorsOpen(StatusBinarySensor):
"""Detects whether at least one door is open."""
Expand All @@ -169,7 +145,6 @@ class DoorsOpen(StatusBinarySensor):
key="doors_open",
name="Doors",
device_class=BinarySensorDeviceClass.DOOR,
icon="mdi:car-door",
translation_key="doors_open",
)

Expand All @@ -186,7 +161,6 @@ class WindowsOpen(StatusBinarySensor):
key="windows_open",
name="Windows",
device_class=BinarySensorDeviceClass.WINDOW,
icon="mdi:car-door",
translation_key="windows_open",
)

Expand All @@ -203,7 +177,6 @@ class TrunkOpen(StatusBinarySensor):
key="trunk_open",
name="Trunk",
device_class=BinarySensorDeviceClass.OPENING,
icon="mdi:car",
translation_key="trunk_open",
)

Expand All @@ -220,7 +193,6 @@ class BonnetOpen(StatusBinarySensor):
key="bonnet_open",
name="Bonnet",
device_class=BinarySensorDeviceClass.OPENING,
icon="mdi:car",
translation_key="bonnet_open",
)

Expand All @@ -237,7 +209,6 @@ class SunroofOpen(StatusBinarySensor):
key="sunroof_open",
name="Sunroof",
device_class=BinarySensorDeviceClass.OPENING,
icon="mdi:car-select",
)

@property
Expand Down Expand Up @@ -266,7 +237,6 @@ class LightsOn(StatusBinarySensor):
key="lights_on",
name="Lights",
device_class=BinarySensorDeviceClass.LIGHT,
icon="mdi:car-light-high",
translation_key="lights_on",
)

Expand Down
1 change: 0 additions & 1 deletion custom_components/myskoda/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class MySkodaClimate(MySkodaEntity, ClimateEntity):
entity_description = ClimateEntityDescription(
key="climate",
name="Air Conditioning",
icon="mdi:air-conditioner",
translation_key="climate",
)
_attr_temperature_unit = UnitOfTemperature.CELSIUS
Expand Down
139 changes: 139 additions & 0 deletions custom_components/myskoda/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"entity": {
"binary_sensor": {
"bonnet_open": {
"default": "mdi:car"
},
"charger_connected": {
"default": "mdi:power-plug-off",
"state": {
"on": "mdi:power-plug"
}
},
"charger_locked": {
"default": "mdi:lock",
"state": {
"on": "mdi:lock-open"
}
},
"doors_locked": {
"default": "mdi:car-door-lock",
"state": {
"on": "mdi:car-door-lock-open"
}
},
"doors_open": {
"default": "mdi:car-door"
},
"lights_on": {
"default": "mdi:car-light-high"
},
"locked": {
"default": "mdi:lock",
"state": {
"on": "mdi:lock-open"
}
},
"sunroof_open": {
"default": "mdi:car-select"
},
"trunk_open": {
"default": "mdi:car"
},
"windows_open": {
"default": "mdi:car-door"
}
},
"climate": {
"climate": {
"default": "mdi:air-conditioner"
}
},
"device_tracker": {
"device_tracker": {
"default": "mdi:map-marker"
}
},
"number": {
"charge_limit": {
"default": "mdi:battery-lock"
}
},
"sensor": {
"car_captured": {
"default": "mdi:clock"
},
"charge_power": {
"default": "mdi:lightning-bolt"
},
"charging_state": {
"default": "mdi:power-plug",
"state": {
"connect_cable": "mdi:power-plug-off",
"charging": "mdi:power-plug-battery",
"conserving": "mdi:battery-sync",
"ready_for_charging": "mdi:battery-check"
}
},
"charge_type": {
"default": "mdi:ev-plug-type2",
"state": {
"dc": "mdi:ev-plug-ccs2"
}
},
"inspection": {
"default": "mdi:car-wrench"
},
"mileage": {
"default": "mdi:counter"
},
"range": {
"default": "mdi:speedometer"
},
"remaining_charging_time": {
"default": "mdi:timer"
},
"render_url_main": {
"default": "mdi:file-image"
},
"software_version": {
"default": "mdi:update"
},
"target_battery_percentage": {
"default": "mdi:percent"
}
},
"switch": {
"battery_care_mode": {
"default": "mdi:battery-heart-variant",
"state": {
"off": "mdi:battery-plus"
}
},
"charging": {
"default": "mdi:power-plug-battery",
"state": {
"off": "mdi:power-plug-battery-outline"
}
},
"charging_switch": {
"default": "mdi:car-electric",
"state": {
"off": "mdi:car-electric-outline"
}
},
"reduced_current": {
"default": "mdi:current-ac",
"state": {
"on": "mdi:turle"
}
},
"window_heating": {
"default": "mdi:car-defrost-front",
"state": {
"on": "mdi:heat-wave"
}
}
}
}
}
1 change: 0 additions & 1 deletion custom_components/myskoda/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ChargeLimit(MySkodaNumber):
entity_description = NumberEntityDescription(
key="charge_limit",
name="Charge Limit",
icon="mdi:battery-lock",
native_max_value=100,
native_min_value=50,
native_unit_of_measurement=PERCENTAGE,
Expand Down
35 changes: 8 additions & 27 deletions custom_components/myskoda/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, UnitOfLength, UnitOfPower, UnitOfTime
from homeassistant.const import (
PERCENTAGE,
UnitOfLength,
UnitOfPower,
UnitOfTime,
EntityCategory,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import DiscoveryInfoType # pyright: ignore [reportAttributeAccessIssue]
Expand Down Expand Up @@ -59,7 +65,6 @@ class SoftwareVersion(MySkodaSensor):
entity_description = SensorEntityDescription(
key="software_version",
name="Software Version",
icon="mdi:update",
translation_key="software_version",
)

Expand Down Expand Up @@ -145,7 +150,6 @@ class ChargingPower(ChargingSensor):
entity_description = SensorEntityDescription(
key="charging_power",
name="Charging Power",
icon="mdi:lightning-bolt",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
device_class=SensorDeviceClass.POWER,
Expand All @@ -164,7 +168,6 @@ class RemainingDistance(ChargingSensor):
entity_description = SensorEntityDescription(
key="range",
name="Range",
icon="mdi:speedometer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfLength.KILOMETERS,
device_class=SensorDeviceClass.DISTANCE,
Expand All @@ -185,7 +188,6 @@ class TargetBatteryPercentage(ChargingSensor):
name="Target Battery Percentage",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:percent",
device_class=SensorDeviceClass.BATTERY,
translation_key="target_battery_percentage",
)
Expand All @@ -204,7 +206,6 @@ class Mileage(MySkodaSensor):
name="Milage",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfLength.KILOMETERS,
icon="mdi:counter",
device_class=SensorDeviceClass.DISTANCE,
translation_key="mileage",
)
Expand All @@ -227,7 +228,6 @@ class InspectionInterval(MySkodaSensor):
device_class=SensorDeviceClass.DURATION,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.DAYS,
icon="mdi:car-wrench",
translation_key="inspection",
)

Expand All @@ -254,14 +254,6 @@ def native_value(self) -> str | None: # noqa: D102
if status := self._status():
return str(status.charge_type).lower()

@property
def icon(self) -> str: # noqa: D102
if status := self._status():
if status.charge_type == "DC":
return "mdi:ev-plug-ccs2"

return "mdi:ev-plug-type2"


class ChargingState(ChargingSensor):
"""Current state of charging (ready, charging, conserving, ...)."""
Expand All @@ -287,15 +279,6 @@ def native_value(self) -> str | None: # noqa: D102
if status.state:
return str(status.state).lower()

@property
def icon(self) -> str: # noqa: D102
if status := self._status():
if status.state == charging.ChargingState.CONNECT_CABLE:
return "mdi:power-plug-off"
if status.state == charging.ChargingState.CHARGING:
return "mdi:power-plug-battery"
return "mdi:power-plug"


class RemainingChargingTime(ChargingSensor):
"""Estimation on when the vehicle will be fully charged."""
Expand All @@ -305,7 +288,6 @@ class RemainingChargingTime(ChargingSensor):
name="Remaining Charging Time",
device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.MINUTES,
icon="mdi:timer",
translation_key="remaining_charging_time",
)

Expand All @@ -322,7 +304,6 @@ class LastUpdated(MySkodaSensor):
key="car_captured",
name="Last Updated",
device_class=SensorDeviceClass.TIMESTAMP,
icon="mdi:clock",
translation_key="car_captured",
)

Expand All @@ -341,8 +322,8 @@ class MainRender(MySkodaSensor):
entity_description = SensorEntityDescription(
key="render_url_main",
name="Main Render URL",
icon="mdi:file-image",
translation_key="render_url_main",
entity_category=EntityCategory.DIAGNOSTIC,
)

@property
Expand Down
Loading

0 comments on commit 6c1b036

Please sign in to comment.