mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Improve energy entities in Teslemetry (#143641)
* Energy fixes * improvements * Add more icons
This commit is contained in:
parent
980216795f
commit
20df183470
@ -428,16 +428,27 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = (
|
||||
)
|
||||
|
||||
|
||||
ENERGY_LIVE_DESCRIPTIONS: tuple[BinarySensorEntityDescription, ...] = (
|
||||
BinarySensorEntityDescription(key="backup_capable"),
|
||||
BinarySensorEntityDescription(key="grid_services_active"),
|
||||
BinarySensorEntityDescription(key="storm_mode_active"),
|
||||
ENERGY_LIVE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = (
|
||||
TeslemetryBinarySensorEntityDescription(
|
||||
key="grid_status",
|
||||
polling_value_fn=lambda x: x == "Active",
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
TeslemetryBinarySensorEntityDescription(
|
||||
key="backup_capable", entity_category=EntityCategory.DIAGNOSTIC
|
||||
),
|
||||
TeslemetryBinarySensorEntityDescription(
|
||||
key="grid_services_active", entity_category=EntityCategory.DIAGNOSTIC
|
||||
),
|
||||
TeslemetryBinarySensorEntityDescription(key="storm_mode_active"),
|
||||
)
|
||||
|
||||
|
||||
ENERGY_INFO_DESCRIPTIONS: tuple[BinarySensorEntityDescription, ...] = (
|
||||
BinarySensorEntityDescription(
|
||||
ENERGY_INFO_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = (
|
||||
TeslemetryBinarySensorEntityDescription(
|
||||
key="components_grid_services_enabled",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
)
|
||||
|
||||
@ -548,12 +559,12 @@ class TeslemetryEnergyLiveBinarySensorEntity(
|
||||
):
|
||||
"""Base class for Teslemetry energy live binary sensors."""
|
||||
|
||||
entity_description: BinarySensorEntityDescription
|
||||
entity_description: TeslemetryBinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: TeslemetryEnergyData,
|
||||
description: BinarySensorEntityDescription,
|
||||
description: TeslemetryBinarySensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the binary sensor."""
|
||||
self.entity_description = description
|
||||
@ -561,7 +572,7 @@ class TeslemetryEnergyLiveBinarySensorEntity(
|
||||
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Update the attributes of the binary sensor."""
|
||||
self._attr_is_on = self._value
|
||||
self._attr_is_on = self.entity_description.polling_value_fn(self._value)
|
||||
|
||||
|
||||
class TeslemetryEnergyInfoBinarySensorEntity(
|
||||
@ -569,12 +580,12 @@ class TeslemetryEnergyInfoBinarySensorEntity(
|
||||
):
|
||||
"""Base class for Teslemetry energy info binary sensors."""
|
||||
|
||||
entity_description: BinarySensorEntityDescription
|
||||
entity_description: TeslemetryBinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: TeslemetryEnergyData,
|
||||
description: BinarySensorEntityDescription,
|
||||
description: TeslemetryBinarySensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the binary sensor."""
|
||||
self.entity_description = description
|
||||
@ -582,4 +593,4 @@ class TeslemetryEnergyInfoBinarySensorEntity(
|
||||
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Update the attributes of the binary sensor."""
|
||||
self._attr_is_on = self._value
|
||||
self._attr_is_on = self.entity_description.polling_value_fn(self._value)
|
||||
|
@ -102,6 +102,30 @@
|
||||
"off": "mdi:hvac-off",
|
||||
"on": "mdi:hvac"
|
||||
}
|
||||
},
|
||||
"backup_capable": {
|
||||
"state": {
|
||||
"off": "mdi:battery-off",
|
||||
"on": "mdi:home-battery"
|
||||
}
|
||||
},
|
||||
"grid_status": {
|
||||
"state": {
|
||||
"off": "mdi:transmission-tower-off",
|
||||
"on": "mdi:transmission-tower"
|
||||
}
|
||||
},
|
||||
"grid_services_active": {
|
||||
"state": {
|
||||
"on": "mdi:sine-wave",
|
||||
"off": "mdi:transmission-tower-off"
|
||||
}
|
||||
},
|
||||
"components_grid_services_enabled": {
|
||||
"state": {
|
||||
"on": "mdi:sine-wave",
|
||||
"off": "mdi:transmission-tower-off"
|
||||
}
|
||||
}
|
||||
},
|
||||
"button": {
|
||||
|
@ -522,7 +522,10 @@ ENERGY_INFO_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
SensorEntityDescription(key="version"),
|
||||
SensorEntityDescription(
|
||||
key="version",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
)
|
||||
|
||||
ENERGY_HISTORY_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = tuple(
|
||||
|
@ -220,6 +220,9 @@
|
||||
},
|
||||
"hvac_auto_mode": {
|
||||
"name": "HVAC auto mode"
|
||||
},
|
||||
"grid_status": {
|
||||
"name": "Grid status"
|
||||
}
|
||||
},
|
||||
"button": {
|
||||
@ -559,7 +562,7 @@
|
||||
"name": "Tire pressure rear right"
|
||||
},
|
||||
"version": {
|
||||
"name": "version"
|
||||
"name": "Version"
|
||||
},
|
||||
"vin": {
|
||||
"name": "Vehicle",
|
||||
|
@ -11,7 +11,7 @@
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.energy_site_backup_capable',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
@ -58,7 +58,7 @@
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_services_active',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
@ -105,7 +105,7 @@
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_services_enabled',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
@ -140,6 +140,54 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensor[binary_sensor.energy_site_grid_status-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_status',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.POWER: 'power'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Grid status',
|
||||
'platform': 'teslemetry',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'grid_status',
|
||||
'unique_id': '123456-grid_status',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensor[binary_sensor.energy_site_grid_status-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'power',
|
||||
'friendly_name': 'Energy Site Grid status',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensor[binary_sensor.energy_site_storm_watch_active-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@ -3068,6 +3116,20 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensor_refresh[binary_sensor.energy_site_grid_status-statealt]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'power',
|
||||
'friendly_name': 'Energy Site Grid status',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.energy_site_grid_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensor_refresh[binary_sensor.energy_site_storm_watch_active-statealt]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
|
@ -2312,7 +2312,7 @@
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.energy_site_version',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
@ -2325,7 +2325,7 @@
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'version',
|
||||
'original_name': 'Version',
|
||||
'platform': 'teslemetry',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
@ -2337,7 +2337,7 @@
|
||||
# name: test_sensors[sensor.energy_site_version-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Energy Site version',
|
||||
'friendly_name': 'Energy Site Version',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.energy_site_version',
|
||||
@ -2350,7 +2350,7 @@
|
||||
# name: test_sensors[sensor.energy_site_version-statealt]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Energy Site version',
|
||||
'friendly_name': 'Energy Site Version',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.energy_site_version',
|
||||
|
Loading…
x
Reference in New Issue
Block a user