diff --git a/homeassistant/components/bsblan/coordinator.py b/homeassistant/components/bsblan/coordinator.py index f708b05de5e..ebe46e036f4 100644 --- a/homeassistant/components/bsblan/coordinator.py +++ b/homeassistant/components/bsblan/coordinator.py @@ -29,8 +29,13 @@ if TYPE_CHECKING: # Filter lists for optimized API calls - only fetch parameters we actually use # This significantly reduces response time (~0.2s per parameter saved) -STATE_INCLUDE = ["current_temperature", "target_temperature", "hvac_mode"] -SENSOR_INCLUDE = ["current_temperature", "outside_temperature"] +STATE_INCLUDE = [ + "current_temperature", + "target_temperature", + "hvac_mode", + "hvac_action", +] +SENSOR_INCLUDE = ["current_temperature", "outside_temperature", "total_energy"] DHW_STATE_INCLUDE = [ "operating_mode", "nominal_setpoint", diff --git a/homeassistant/components/bsblan/sensor.py b/homeassistant/components/bsblan/sensor.py index 1556e44a3d5..c0a5aa2d25c 100644 --- a/homeassistant/components/bsblan/sensor.py +++ b/homeassistant/components/bsblan/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorEntityDescription, SensorStateClass, ) -from homeassistant.const import UnitOfTemperature +from homeassistant.const import UnitOfEnergy, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.typing import StateType @@ -58,6 +58,19 @@ SENSOR_TYPES: tuple[BSBLanSensorEntityDescription, ...] = ( ), exists_fn=lambda data: data.sensor.outside_temperature is not None, ), + BSBLanSensorEntityDescription( + key="total_energy", + translation_key="total_energy", + device_class=SensorDeviceClass.ENERGY, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda data: ( + data.sensor.total_energy.value + if data.sensor.total_energy is not None + else None + ), + exists_fn=lambda data: data.sensor.total_energy is not None, + ), ) diff --git a/homeassistant/components/bsblan/strings.json b/homeassistant/components/bsblan/strings.json index f7a53654ab3..aed80c0c55b 100644 --- a/homeassistant/components/bsblan/strings.json +++ b/homeassistant/components/bsblan/strings.json @@ -66,6 +66,9 @@ }, "outside_temperature": { "name": "Outside temperature" + }, + "total_energy": { + "name": "Total energy" } } }, diff --git a/tests/components/bsblan/fixtures/sensor.json b/tests/components/bsblan/fixtures/sensor.json index 3448e7e98d8..f0caf29ffb9 100644 --- a/tests/components/bsblan/fixtures/sensor.json +++ b/tests/components/bsblan/fixtures/sensor.json @@ -16,5 +16,14 @@ "dataType": 0, "readonly": 1, "unit": "°C" + }, + "total_energy": { + "name": "Total energy", + "error": 0, + "value": "7968", + "desc": "", + "dataType": 0, + "readonly": 1, + "unit": "kWh" } } diff --git a/tests/components/bsblan/snapshots/test_diagnostics.ambr b/tests/components/bsblan/snapshots/test_diagnostics.ambr index baad8078b71..cf2358d9c31 100644 --- a/tests/components/bsblan/snapshots/test_diagnostics.ambr +++ b/tests/components/bsblan/snapshots/test_diagnostics.ambr @@ -102,7 +102,19 @@ 'unit': '°C', 'value': 6.1, }), - 'total_energy': None, + 'total_energy': dict({ + 'data_type': 0, + 'data_type_family': '', + 'data_type_name': '', + 'desc': '', + 'error': 0, + 'name': 'Total energy', + 'precision': None, + 'readonly': 1, + 'readwrite': 0, + 'unit': 'kWh', + 'value': 7968, + }), }), 'state': dict({ 'current_temperature': dict({ diff --git a/tests/components/bsblan/snapshots/test_sensor.ambr b/tests/components/bsblan/snapshots/test_sensor.ambr index 24f6c662308..80f8a38ac0b 100644 --- a/tests/components/bsblan/snapshots/test_sensor.ambr +++ b/tests/components/bsblan/snapshots/test_sensor.ambr @@ -113,3 +113,60 @@ 'state': '6.1', }) # --- +# name: test_sensor_entity_properties[sensor.bsb_lan_total_energy-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.bsb_lan_total_energy', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Total energy', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Total energy', + 'platform': 'bsblan', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'total_energy', + 'unique_id': '00:80:41:19:69:90-total_energy', + 'unit_of_measurement': , + }) +# --- +# name: test_sensor_entity_properties[sensor.bsb_lan_total_energy-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'BSB-LAN Total energy', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.bsb_lan_total_energy', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '7968', + }) +# --- diff --git a/tests/components/bsblan/test_sensor.py b/tests/components/bsblan/test_sensor.py index fdfe8fec06b..fbe02f71c21 100644 --- a/tests/components/bsblan/test_sensor.py +++ b/tests/components/bsblan/test_sensor.py @@ -15,6 +15,7 @@ from tests.common import MockConfigEntry, snapshot_platform ENTITY_CURRENT_TEMP = "sensor.bsb_lan_current_temperature" ENTITY_OUTSIDE_TEMP = "sensor.bsb_lan_outside_temperature" +ENTITY_TOTAL_ENERGY = "sensor.bsb_lan_total_energy" async def test_sensor_entity_properties( @@ -40,6 +41,7 @@ async def test_sensors_not_created_when_data_unavailable( # Set all sensor data to None to simulate no sensors available mock_bsblan.sensor.return_value.current_temperature = None mock_bsblan.sensor.return_value.outside_temperature = None + mock_bsblan.sensor.return_value.total_energy = None await setup_with_selected_platforms(hass, mock_config_entry, [Platform.SENSOR]) @@ -58,8 +60,9 @@ async def test_partial_sensors_created_when_some_data_available( entity_registry: er.EntityRegistry, ) -> None: """Test only available sensors are created when some sensor data is available.""" - # Only current temperature available, outside temperature not + # Only current temperature available, outside temperature and energy not mock_bsblan.sensor.return_value.outside_temperature = None + mock_bsblan.sensor.return_value.total_energy = None await setup_with_selected_platforms(hass, mock_config_entry, [Platform.SENSOR])