Migrate Starline to entity name (#96176)
This commit is contained in:
parent
c853010f80
commit
fdb69efd67
7 changed files with 114 additions and 85 deletions
|
@ -1,8 +1,6 @@
|
|||
"""Reads vehicle status from StarLine API."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
|
@ -16,45 +14,30 @@ from .account import StarlineAccount, StarlineDevice
|
|||
from .const import DOMAIN
|
||||
from .entity import StarlineEntity
|
||||
|
||||
|
||||
@dataclass
|
||||
class StarlineRequiredKeysMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
name_: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class StarlineBinarySensorEntityDescription(
|
||||
BinarySensorEntityDescription, StarlineRequiredKeysMixin
|
||||
):
|
||||
"""Describes Starline binary_sensor entity."""
|
||||
|
||||
|
||||
BINARY_SENSOR_TYPES: tuple[StarlineBinarySensorEntityDescription, ...] = (
|
||||
StarlineBinarySensorEntityDescription(
|
||||
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
||||
BinarySensorEntityDescription(
|
||||
key="hbrake",
|
||||
name_="Hand Brake",
|
||||
translation_key="hand_brake",
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
),
|
||||
StarlineBinarySensorEntityDescription(
|
||||
BinarySensorEntityDescription(
|
||||
key="hood",
|
||||
name_="Hood",
|
||||
translation_key="hood",
|
||||
device_class=BinarySensorDeviceClass.DOOR,
|
||||
),
|
||||
StarlineBinarySensorEntityDescription(
|
||||
BinarySensorEntityDescription(
|
||||
key="trunk",
|
||||
name_="Trunk",
|
||||
translation_key="trunk",
|
||||
device_class=BinarySensorDeviceClass.DOOR,
|
||||
),
|
||||
StarlineBinarySensorEntityDescription(
|
||||
BinarySensorEntityDescription(
|
||||
key="alarm",
|
||||
name_="Alarm",
|
||||
translation_key="alarm",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
),
|
||||
StarlineBinarySensorEntityDescription(
|
||||
BinarySensorEntityDescription(
|
||||
key="door",
|
||||
name_="Doors",
|
||||
translation_key="doors",
|
||||
device_class=BinarySensorDeviceClass.LOCK,
|
||||
),
|
||||
)
|
||||
|
@ -78,16 +61,14 @@ async def async_setup_entry(
|
|||
class StarlineSensor(StarlineEntity, BinarySensorEntity):
|
||||
"""Representation of a StarLine binary sensor."""
|
||||
|
||||
entity_description: StarlineBinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
account: StarlineAccount,
|
||||
device: StarlineDevice,
|
||||
description: StarlineBinarySensorEntityDescription,
|
||||
description: BinarySensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize sensor."""
|
||||
super().__init__(account, device, description.key, description.name_)
|
||||
super().__init__(account, device, description.key)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
|
|
|
@ -25,9 +25,11 @@ async def async_setup_entry(
|
|||
class StarlineDeviceTracker(StarlineEntity, TrackerEntity, RestoreEntity):
|
||||
"""StarLine device tracker."""
|
||||
|
||||
_attr_translation_key = "location"
|
||||
|
||||
def __init__(self, account: StarlineAccount, device: StarlineDevice) -> None:
|
||||
"""Set up StarLine entity."""
|
||||
super().__init__(account, device, "location", "Location")
|
||||
super().__init__(account, device, "location")
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
|
|
|
@ -12,15 +12,15 @@ class StarlineEntity(Entity):
|
|||
"""StarLine base entity class."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self, account: StarlineAccount, device: StarlineDevice, key: str, name: str
|
||||
self, account: StarlineAccount, device: StarlineDevice, key: str
|
||||
) -> None:
|
||||
"""Initialize StarLine entity."""
|
||||
self._account = account
|
||||
self._device = device
|
||||
self._key = key
|
||||
self._name = name
|
||||
self._unsubscribe_api: Callable | None = None
|
||||
|
||||
@property
|
||||
|
@ -33,11 +33,6 @@ class StarlineEntity(Entity):
|
|||
"""Return the unique ID of the entity."""
|
||||
return f"starline-{self._key}-{self._device.device_id}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the entity."""
|
||||
return f"{self._device.name} {self._name}"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
|
|
|
@ -30,9 +30,11 @@ async def async_setup_entry(
|
|||
class StarlineLock(StarlineEntity, LockEntity):
|
||||
"""Representation of a StarLine lock."""
|
||||
|
||||
_attr_translation_key = "security"
|
||||
|
||||
def __init__(self, account: StarlineAccount, device: StarlineDevice) -> None:
|
||||
"""Initialize the lock."""
|
||||
super().__init__(account, device, "lock", "Security")
|
||||
super().__init__(account, device, "lock")
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Reads vehicle status from StarLine API."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
|
@ -24,63 +22,48 @@ from .account import StarlineAccount, StarlineDevice
|
|||
from .const import DOMAIN
|
||||
from .entity import StarlineEntity
|
||||
|
||||
|
||||
@dataclass
|
||||
class StarlineRequiredKeysMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
name_: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class StarlineSensorEntityDescription(
|
||||
SensorEntityDescription, StarlineRequiredKeysMixin
|
||||
):
|
||||
"""Describes Starline binary_sensor entity."""
|
||||
|
||||
|
||||
SENSOR_TYPES: tuple[StarlineSensorEntityDescription, ...] = (
|
||||
StarlineSensorEntityDescription(
|
||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
SensorEntityDescription(
|
||||
key="battery",
|
||||
name_="Battery",
|
||||
translation_key="battery",
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||
),
|
||||
StarlineSensorEntityDescription(
|
||||
SensorEntityDescription(
|
||||
key="balance",
|
||||
name_="Balance",
|
||||
translation_key="balance",
|
||||
icon="mdi:cash-multiple",
|
||||
),
|
||||
StarlineSensorEntityDescription(
|
||||
SensorEntityDescription(
|
||||
key="ctemp",
|
||||
name_="Interior Temperature",
|
||||
translation_key="interior_temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
StarlineSensorEntityDescription(
|
||||
SensorEntityDescription(
|
||||
key="etemp",
|
||||
name_="Engine Temperature",
|
||||
translation_key="engine_temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
StarlineSensorEntityDescription(
|
||||
SensorEntityDescription(
|
||||
key="gsm_lvl",
|
||||
name_="GSM Signal",
|
||||
translation_key="gsm_signal",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
StarlineSensorEntityDescription(
|
||||
SensorEntityDescription(
|
||||
key="fuel",
|
||||
name_="Fuel Volume",
|
||||
translation_key="fuel",
|
||||
icon="mdi:fuel",
|
||||
),
|
||||
StarlineSensorEntityDescription(
|
||||
SensorEntityDescription(
|
||||
key="errors",
|
||||
name_="OBD Errors",
|
||||
translation_key="errors",
|
||||
icon="mdi:alert-octagon",
|
||||
),
|
||||
StarlineSensorEntityDescription(
|
||||
SensorEntityDescription(
|
||||
key="mileage",
|
||||
name_="Mileage",
|
||||
translation_key="mileage",
|
||||
native_unit_of_measurement=UnitOfLength.KILOMETERS,
|
||||
device_class=SensorDeviceClass.DISTANCE,
|
||||
icon="mdi:counter",
|
||||
|
@ -106,16 +89,14 @@ async def async_setup_entry(
|
|||
class StarlineSensor(StarlineEntity, SensorEntity):
|
||||
"""Representation of a StarLine sensor."""
|
||||
|
||||
entity_description: StarlineSensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
account: StarlineAccount,
|
||||
device: StarlineDevice,
|
||||
description: StarlineSensorEntityDescription,
|
||||
description: SensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize StarLine sensor."""
|
||||
super().__init__(account, device, description.key, description.name_)
|
||||
super().__init__(account, device, description.key)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
|
|
|
@ -38,6 +38,75 @@
|
|||
"error_auth_mfa": "Incorrect code"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"hand_brake": {
|
||||
"name": "Hand brake"
|
||||
},
|
||||
"hood": {
|
||||
"name": "Hood"
|
||||
},
|
||||
"trunk": {
|
||||
"name": "Trunk"
|
||||
},
|
||||
"alarm": {
|
||||
"name": "Alarm"
|
||||
},
|
||||
"doors": {
|
||||
"name": "Doors"
|
||||
}
|
||||
},
|
||||
"device_tracker": {
|
||||
"location": {
|
||||
"name": "Location"
|
||||
}
|
||||
},
|
||||
"lock": {
|
||||
"security": {
|
||||
"name": "Security"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"battery": {
|
||||
"name": "[%key:component::sensor::entity_component::battery::name%]"
|
||||
},
|
||||
"balance": {
|
||||
"name": "Balance"
|
||||
},
|
||||
"interior_temperature": {
|
||||
"name": "Interior temperature"
|
||||
},
|
||||
"engine_temperature": {
|
||||
"name": "Engine temperature"
|
||||
},
|
||||
"gsm_signal": {
|
||||
"name": "GSM signal"
|
||||
},
|
||||
"fuel": {
|
||||
"name": "Fuel volume"
|
||||
},
|
||||
"errors": {
|
||||
"name": "OBD errors"
|
||||
},
|
||||
"mileage": {
|
||||
"name": "Mileage"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"engine": {
|
||||
"name": "Engine"
|
||||
},
|
||||
"webasto": {
|
||||
"name": "Webasto"
|
||||
},
|
||||
"additional_channel": {
|
||||
"name": "Additional channel"
|
||||
},
|
||||
"horn": {
|
||||
"name": "Horn"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"update_state": {
|
||||
"name": "Update state",
|
||||
|
|
|
@ -18,7 +18,6 @@ from .entity import StarlineEntity
|
|||
class StarlineRequiredKeysMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
name_: str
|
||||
icon_on: str
|
||||
icon_off: str
|
||||
|
||||
|
@ -33,25 +32,25 @@ class StarlineSwitchEntityDescription(
|
|||
SWITCH_TYPES: tuple[StarlineSwitchEntityDescription, ...] = (
|
||||
StarlineSwitchEntityDescription(
|
||||
key="ign",
|
||||
name_="Engine",
|
||||
translation_key="engine",
|
||||
icon_on="mdi:engine-outline",
|
||||
icon_off="mdi:engine-off-outline",
|
||||
),
|
||||
StarlineSwitchEntityDescription(
|
||||
key="webasto",
|
||||
name_="Webasto",
|
||||
translation_key="webasto",
|
||||
icon_on="mdi:radiator",
|
||||
icon_off="mdi:radiator-off",
|
||||
),
|
||||
StarlineSwitchEntityDescription(
|
||||
key="out",
|
||||
name_="Additional Channel",
|
||||
translation_key="additional_channel",
|
||||
icon_on="mdi:access-point-network",
|
||||
icon_off="mdi:access-point-network-off",
|
||||
),
|
||||
StarlineSwitchEntityDescription(
|
||||
key="poke",
|
||||
name_="Horn",
|
||||
translation_key="horn",
|
||||
icon_on="mdi:bullhorn-outline",
|
||||
icon_off="mdi:bullhorn-outline",
|
||||
),
|
||||
|
@ -85,7 +84,7 @@ class StarlineSwitch(StarlineEntity, SwitchEntity):
|
|||
description: StarlineSwitchEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the switch."""
|
||||
super().__init__(account, device, description.key, description.name_)
|
||||
super().__init__(account, device, description.key)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue