Add today's remaining production estimate (#91965)

This commit is contained in:
Ondřej Kolenatý 2023-04-26 15:58:28 +02:00 committed by GitHub
parent 32ffedd365
commit 64e4414a5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 0 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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(

View File

@ -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,

View File

@ -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