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