diff --git a/homeassistant/components/teslemetry/binary_sensor.py b/homeassistant/components/teslemetry/binary_sensor.py index 155d10e1b57..a62dbe1e00f 100644 --- a/homeassistant/components/teslemetry/binary_sensor.py +++ b/homeassistant/components/teslemetry/binary_sensor.py @@ -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) diff --git a/homeassistant/components/teslemetry/icons.json b/homeassistant/components/teslemetry/icons.json index f7ce0ca1a60..ea6bd360632 100644 --- a/homeassistant/components/teslemetry/icons.json +++ b/homeassistant/components/teslemetry/icons.json @@ -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": { diff --git a/homeassistant/components/teslemetry/sensor.py b/homeassistant/components/teslemetry/sensor.py index e75c4e91f6d..018e450b52f 100644 --- a/homeassistant/components/teslemetry/sensor.py +++ b/homeassistant/components/teslemetry/sensor.py @@ -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( diff --git a/homeassistant/components/teslemetry/strings.json b/homeassistant/components/teslemetry/strings.json index a5bbcf34382..a85d109231e 100644 --- a/homeassistant/components/teslemetry/strings.json +++ b/homeassistant/components/teslemetry/strings.json @@ -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", diff --git a/tests/components/teslemetry/snapshots/test_binary_sensor.ambr b/tests/components/teslemetry/snapshots/test_binary_sensor.ambr index f4656f75b9e..d957bdedcf4 100644 --- a/tests/components/teslemetry/snapshots/test_binary_sensor.ambr +++ b/tests/components/teslemetry/snapshots/test_binary_sensor.ambr @@ -11,7 +11,7 @@ 'device_id': , 'disabled_by': None, 'domain': 'binary_sensor', - 'entity_category': None, + 'entity_category': , 'entity_id': 'binary_sensor.energy_site_backup_capable', 'has_entity_name': True, 'hidden_by': None, @@ -58,7 +58,7 @@ 'device_id': , 'disabled_by': None, 'domain': 'binary_sensor', - 'entity_category': None, + 'entity_category': , 'entity_id': 'binary_sensor.energy_site_grid_services_active', 'has_entity_name': True, 'hidden_by': None, @@ -105,7 +105,7 @@ 'device_id': , 'disabled_by': None, 'domain': 'binary_sensor', - 'entity_category': None, + 'entity_category': , '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': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': , + 'entity_id': 'binary_sensor.energy_site_grid_status', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + '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': , + 'entity_id': 'binary_sensor.energy_site_grid_status', + 'last_changed': , + 'last_reported': , + 'last_updated': , + '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': , + 'entity_id': 'binary_sensor.energy_site_grid_status', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- # name: test_binary_sensor_refresh[binary_sensor.energy_site_storm_watch_active-statealt] StateSnapshot({ 'attributes': ReadOnlyDict({ diff --git a/tests/components/teslemetry/snapshots/test_sensor.ambr b/tests/components/teslemetry/snapshots/test_sensor.ambr index 0a992c213b8..8e9ce51e297 100644 --- a/tests/components/teslemetry/snapshots/test_sensor.ambr +++ b/tests/components/teslemetry/snapshots/test_sensor.ambr @@ -2312,7 +2312,7 @@ 'device_id': , 'disabled_by': None, 'domain': 'sensor', - 'entity_category': None, + 'entity_category': , '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': , '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': , 'entity_id': 'sensor.energy_site_version',