mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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, ...] = (
|
ENERGY_LIVE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = (
|
||||||
BinarySensorEntityDescription(key="backup_capable"),
|
TeslemetryBinarySensorEntityDescription(
|
||||||
BinarySensorEntityDescription(key="grid_services_active"),
|
key="grid_status",
|
||||||
BinarySensorEntityDescription(key="storm_mode_active"),
|
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, ...] = (
|
ENERGY_INFO_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = (
|
||||||
BinarySensorEntityDescription(
|
TeslemetryBinarySensorEntityDescription(
|
||||||
key="components_grid_services_enabled",
|
key="components_grid_services_enabled",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -548,12 +559,12 @@ class TeslemetryEnergyLiveBinarySensorEntity(
|
|||||||
):
|
):
|
||||||
"""Base class for Teslemetry energy live binary sensors."""
|
"""Base class for Teslemetry energy live binary sensors."""
|
||||||
|
|
||||||
entity_description: BinarySensorEntityDescription
|
entity_description: TeslemetryBinarySensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
data: TeslemetryEnergyData,
|
data: TeslemetryEnergyData,
|
||||||
description: BinarySensorEntityDescription,
|
description: TeslemetryBinarySensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the binary sensor."""
|
"""Initialize the binary sensor."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
@ -561,7 +572,7 @@ class TeslemetryEnergyLiveBinarySensorEntity(
|
|||||||
|
|
||||||
def _async_update_attrs(self) -> None:
|
def _async_update_attrs(self) -> None:
|
||||||
"""Update the attributes of the binary sensor."""
|
"""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(
|
class TeslemetryEnergyInfoBinarySensorEntity(
|
||||||
@ -569,12 +580,12 @@ class TeslemetryEnergyInfoBinarySensorEntity(
|
|||||||
):
|
):
|
||||||
"""Base class for Teslemetry energy info binary sensors."""
|
"""Base class for Teslemetry energy info binary sensors."""
|
||||||
|
|
||||||
entity_description: BinarySensorEntityDescription
|
entity_description: TeslemetryBinarySensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
data: TeslemetryEnergyData,
|
data: TeslemetryEnergyData,
|
||||||
description: BinarySensorEntityDescription,
|
description: TeslemetryBinarySensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the binary sensor."""
|
"""Initialize the binary sensor."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
@ -582,4 +593,4 @@ class TeslemetryEnergyInfoBinarySensorEntity(
|
|||||||
|
|
||||||
def _async_update_attrs(self) -> None:
|
def _async_update_attrs(self) -> None:
|
||||||
"""Update the attributes of the binary sensor."""
|
"""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",
|
"off": "mdi:hvac-off",
|
||||||
"on": "mdi:hvac"
|
"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": {
|
"button": {
|
||||||
|
@ -522,7 +522,10 @@ ENERGY_INFO_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
|
|||||||
device_class=SensorDeviceClass.BATTERY,
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(key="version"),
|
SensorEntityDescription(
|
||||||
|
key="version",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
ENERGY_HISTORY_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = tuple(
|
ENERGY_HISTORY_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = tuple(
|
||||||
|
@ -220,6 +220,9 @@
|
|||||||
},
|
},
|
||||||
"hvac_auto_mode": {
|
"hvac_auto_mode": {
|
||||||
"name": "HVAC auto mode"
|
"name": "HVAC auto mode"
|
||||||
|
},
|
||||||
|
"grid_status": {
|
||||||
|
"name": "Grid status"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
@ -559,7 +562,7 @@
|
|||||||
"name": "Tire pressure rear right"
|
"name": "Tire pressure rear right"
|
||||||
},
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"name": "version"
|
"name": "Version"
|
||||||
},
|
},
|
||||||
"vin": {
|
"vin": {
|
||||||
"name": "Vehicle",
|
"name": "Vehicle",
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
'domain': 'binary_sensor',
|
'domain': 'binary_sensor',
|
||||||
'entity_category': None,
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
'entity_id': 'binary_sensor.energy_site_backup_capable',
|
'entity_id': 'binary_sensor.energy_site_backup_capable',
|
||||||
'has_entity_name': True,
|
'has_entity_name': True,
|
||||||
'hidden_by': None,
|
'hidden_by': None,
|
||||||
@ -58,7 +58,7 @@
|
|||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
'domain': 'binary_sensor',
|
'domain': 'binary_sensor',
|
||||||
'entity_category': None,
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
'entity_id': 'binary_sensor.energy_site_grid_services_active',
|
'entity_id': 'binary_sensor.energy_site_grid_services_active',
|
||||||
'has_entity_name': True,
|
'has_entity_name': True,
|
||||||
'hidden_by': None,
|
'hidden_by': None,
|
||||||
@ -105,7 +105,7 @@
|
|||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
'domain': 'binary_sensor',
|
'domain': 'binary_sensor',
|
||||||
'entity_category': None,
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
'entity_id': 'binary_sensor.energy_site_grid_services_enabled',
|
'entity_id': 'binary_sensor.energy_site_grid_services_enabled',
|
||||||
'has_entity_name': True,
|
'has_entity_name': True,
|
||||||
'hidden_by': None,
|
'hidden_by': None,
|
||||||
@ -140,6 +140,54 @@
|
|||||||
'state': 'off',
|
'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]
|
# name: test_binary_sensor[binary_sensor.energy_site_storm_watch_active-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
@ -3068,6 +3116,20 @@
|
|||||||
'state': 'off',
|
'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]
|
# name: test_binary_sensor_refresh[binary_sensor.energy_site_storm_watch_active-statealt]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
|
@ -2312,7 +2312,7 @@
|
|||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
'domain': 'sensor',
|
'domain': 'sensor',
|
||||||
'entity_category': None,
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
'entity_id': 'sensor.energy_site_version',
|
'entity_id': 'sensor.energy_site_version',
|
||||||
'has_entity_name': True,
|
'has_entity_name': True,
|
||||||
'hidden_by': None,
|
'hidden_by': None,
|
||||||
@ -2325,7 +2325,7 @@
|
|||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': None,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'version',
|
'original_name': 'Version',
|
||||||
'platform': 'teslemetry',
|
'platform': 'teslemetry',
|
||||||
'previous_unique_id': None,
|
'previous_unique_id': None,
|
||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
@ -2337,7 +2337,7 @@
|
|||||||
# name: test_sensors[sensor.energy_site_version-state]
|
# name: test_sensors[sensor.energy_site_version-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Energy Site version',
|
'friendly_name': 'Energy Site Version',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.energy_site_version',
|
'entity_id': 'sensor.energy_site_version',
|
||||||
@ -2350,7 +2350,7 @@
|
|||||||
# name: test_sensors[sensor.energy_site_version-statealt]
|
# name: test_sensors[sensor.energy_site_version-statealt]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Energy Site version',
|
'friendly_name': 'Energy Site Version',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.energy_site_version',
|
'entity_id': 'sensor.energy_site_version',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user