mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Add energy binary sensors to Tessie (#121349)
This commit is contained in:
parent
f29094f41d
commit
696ae91c35
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from itertools import chain
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
@ -16,8 +17,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import TessieConfigEntry
|
||||
from .const import TessieState
|
||||
from .entity import TessieEntity
|
||||
from .models import TessieVehicleData
|
||||
from .entity import TessieEnergyEntity, TessieEntity
|
||||
from .models import TessieEnergyData, TessieVehicleData
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
@ -27,7 +28,7 @@ class TessieBinarySensorEntityDescription(BinarySensorEntityDescription):
|
||||
is_on: Callable[..., bool] = lambda x: x
|
||||
|
||||
|
||||
DESCRIPTIONS: tuple[TessieBinarySensorEntityDescription, ...] = (
|
||||
VEHICLE_DESCRIPTIONS: tuple[TessieBinarySensorEntityDescription, ...] = (
|
||||
TessieBinarySensorEntityDescription(
|
||||
key="state",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
@ -157,6 +158,18 @@ DESCRIPTIONS: tuple[TessieBinarySensorEntityDescription, ...] = (
|
||||
),
|
||||
)
|
||||
|
||||
ENERGY_LIVE_DESCRIPTIONS: tuple[BinarySensorEntityDescription, ...] = (
|
||||
BinarySensorEntityDescription(key="backup_capable"),
|
||||
BinarySensorEntityDescription(key="grid_services_active"),
|
||||
)
|
||||
|
||||
|
||||
ENERGY_INFO_DESCRIPTIONS: tuple[BinarySensorEntityDescription, ...] = (
|
||||
BinarySensorEntityDescription(
|
||||
key="components_grid_services_enabled",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@ -164,12 +177,24 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Tessie binary sensor platform from a config entry."""
|
||||
data = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
TessieBinarySensorEntity(vehicle, description)
|
||||
for vehicle in data.vehicles
|
||||
for description in DESCRIPTIONS
|
||||
chain(
|
||||
(
|
||||
TessieBinarySensorEntity(vehicle, description)
|
||||
for vehicle in entry.runtime_data.vehicles
|
||||
for description in VEHICLE_DESCRIPTIONS
|
||||
),
|
||||
(
|
||||
TessieEnergyLiveBinarySensorEntity(energy, description)
|
||||
for energy in entry.runtime_data.energysites
|
||||
for description in ENERGY_LIVE_DESCRIPTIONS
|
||||
),
|
||||
(
|
||||
TessieEnergyInfoBinarySensorEntity(vehicle, description)
|
||||
for vehicle in entry.runtime_data.energysites
|
||||
for description in ENERGY_INFO_DESCRIPTIONS
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@ -191,3 +216,41 @@ class TessieBinarySensorEntity(TessieEntity, BinarySensorEntity):
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state of the binary sensor."""
|
||||
return self.entity_description.is_on(self._value)
|
||||
|
||||
|
||||
class TessieEnergyLiveBinarySensorEntity(TessieEnergyEntity, BinarySensorEntity):
|
||||
"""Base class for Tessie energy live binary sensors."""
|
||||
|
||||
entity_description: BinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: TessieEnergyData,
|
||||
description: BinarySensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the binary sensor."""
|
||||
self.entity_description = description
|
||||
super().__init__(data, data.live_coordinator, description.key)
|
||||
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Update the attributes of the binary sensor."""
|
||||
self._attr_is_on = self._value
|
||||
|
||||
|
||||
class TessieEnergyInfoBinarySensorEntity(TessieEnergyEntity, BinarySensorEntity):
|
||||
"""Base class for Tessie energy info binary sensors."""
|
||||
|
||||
entity_description: BinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: TessieEnergyData,
|
||||
description: BinarySensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the binary sensor."""
|
||||
self.entity_description = description
|
||||
super().__init__(data, data.info_coordinator, description.key)
|
||||
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Update the attributes of the binary sensor."""
|
||||
self._attr_is_on = self._value
|
||||
|
@ -22,6 +22,9 @@
|
||||
"climate_state_auto_steering_wheel_heat": {
|
||||
"default": "mdi:steering"
|
||||
},
|
||||
"grid_services_power": {
|
||||
"default": "mdi:transmission-tower"
|
||||
},
|
||||
"vehicle_state_dashcam_state": {
|
||||
"default": "mdi:camera-off",
|
||||
"state": {
|
||||
|
@ -303,6 +303,9 @@
|
||||
}
|
||||
},
|
||||
"binary_sensor": {
|
||||
"backup_capable": {
|
||||
"name": "Backup capable"
|
||||
},
|
||||
"state": {
|
||||
"name": "Status"
|
||||
},
|
||||
@ -345,6 +348,12 @@
|
||||
"climate_state_cabin_overheat_protection_actively_cooling": {
|
||||
"name": "Cabin overheat protection actively cooling"
|
||||
},
|
||||
"components_grid_services_enabled": {
|
||||
"name": "Grid services enabled"
|
||||
},
|
||||
"grid_services_active": {
|
||||
"name": "Grid services active"
|
||||
},
|
||||
"vehicle_state_dashcam_state": {
|
||||
"name": "Dashcam"
|
||||
},
|
||||
|
@ -1,4 +1,142 @@
|
||||
# serializer version: 1
|
||||
# name: test_binary_sensors[binary_sensor.energy_site_backup_capable-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.energy_site_backup_capable',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Backup capable',
|
||||
'platform': 'tessie',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'backup_capable',
|
||||
'unique_id': '123456-backup_capable',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.energy_site_backup_capable-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Energy Site Backup capable',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.energy_site_backup_capable',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.energy_site_grid_services_active-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_services_active',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Grid services active',
|
||||
'platform': 'tessie',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'grid_services_active',
|
||||
'unique_id': '123456-grid_services_active',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.energy_site_grid_services_active-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Energy Site Grid services active',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_services_active',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.energy_site_grid_services_enabled-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_services_enabled',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Grid services enabled',
|
||||
'platform': 'tessie',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'components_grid_services_enabled',
|
||||
'unique_id': '123456-components_grid_services_enabled',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.energy_site_grid_services_enabled-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Energy Site Grid services enabled',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_services_enabled',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.test_auto_seat_climate_left-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
Loading…
x
Reference in New Issue
Block a user