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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue