diff --git a/homeassistant/components/forecast_solar/const.py b/homeassistant/components/forecast_solar/const.py index e23072f0bec..0e47fa9701b 100644 --- a/homeassistant/components/forecast_solar/const.py +++ b/homeassistant/components/forecast_solar/const.py @@ -28,6 +28,15 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, suggested_display_precision=1, ), + ForecastSolarSensorEntityDescription( + key="energy_production_today_remaining", + name="Estimated energy production - remaining today", + state=lambda estimate: estimate.energy_production_today_remaining, + device_class=SensorDeviceClass.ENERGY, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + suggested_display_precision=1, + ), ForecastSolarSensorEntityDescription( key="energy_production_tomorrow", name="Estimated energy production - tomorrow", diff --git a/homeassistant/components/forecast_solar/diagnostics.py b/homeassistant/components/forecast_solar/diagnostics.py index d14136103a4..970747253df 100644 --- a/homeassistant/components/forecast_solar/diagnostics.py +++ b/homeassistant/components/forecast_solar/diagnostics.py @@ -34,6 +34,7 @@ async def async_get_config_entry_diagnostics( }, "data": { "energy_production_today": coordinator.data.energy_production_today, + "energy_production_today_remaining": coordinator.data.energy_production_today_remaining, "energy_production_tomorrow": coordinator.data.energy_production_tomorrow, "energy_current_hour": coordinator.data.energy_current_hour, "power_production_now": coordinator.data.power_production_now, diff --git a/tests/components/forecast_solar/conftest.py b/tests/components/forecast_solar/conftest.py index 26c1ae7ba36..60e9c9dc5d0 100644 --- a/tests/components/forecast_solar/conftest.py +++ b/tests/components/forecast_solar/conftest.py @@ -72,6 +72,7 @@ def mock_forecast_solar(hass) -> Generator[None, MagicMock, None]: estimate.api_rate_limit = 60 estimate.account_type.value = "public" estimate.energy_production_today = 100000 + estimate.energy_production_today_remaining = 50000 estimate.energy_production_tomorrow = 200000 estimate.power_production_now = 300000 estimate.power_highest_peak_time_today = datetime( diff --git a/tests/components/forecast_solar/test_diagnostics.py b/tests/components/forecast_solar/test_diagnostics.py index 4ef25379497..4900c3bdb32 100644 --- a/tests/components/forecast_solar/test_diagnostics.py +++ b/tests/components/forecast_solar/test_diagnostics.py @@ -34,6 +34,7 @@ async def test_diagnostics( }, "data": { "energy_production_today": 100000, + "energy_production_today_remaining": 50000, "energy_production_tomorrow": 200000, "energy_current_hour": 800000, "power_production_now": 300000, diff --git a/tests/components/forecast_solar/test_sensor.py b/tests/components/forecast_solar/test_sensor.py index 39d9103c486..4539619febc 100644 --- a/tests/components/forecast_solar/test_sensor.py +++ b/tests/components/forecast_solar/test_sensor.py @@ -48,6 +48,21 @@ async def test_sensors( assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY assert ATTR_ICON not in state.attributes + state = hass.states.get("sensor.energy_production_today_remaining") + entry = entity_registry.async_get("sensor.energy_production_today_remaining") + assert entry + assert state + assert entry.unique_id == f"{entry_id}_energy_production_today_remaining" + assert state.state == "50.0" + assert ( + state.attributes.get(ATTR_FRIENDLY_NAME) + == "Solar production forecast Estimated energy production - remaining today" + ) + assert state.attributes.get(ATTR_STATE_CLASS) is None + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR + assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY + assert ATTR_ICON not in state.attributes + state = hass.states.get("sensor.energy_production_tomorrow") entry = entity_registry.async_get("sensor.energy_production_tomorrow") assert entry