mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Fix nordpool Not to return Unknown if price is exactly 0 (#140647)
* now the price will return even if it is exactly 0 * now the price will return even if it is exactly 0 * now the price will return even if it is exactly 0 * clean code * clean code * update testing code coverage * change zero testing to SE4 * remove row duplicate * fix date comments * improve testing * simplify if-return-0 * remove unnecessary tests * order testing rows * restore test_sensor_no_next_price * remove_average_price_test * fix test name
This commit is contained in:
parent
91438088a0
commit
51073c948c
@ -34,7 +34,7 @@ def validate_prices(
|
||||
index: int,
|
||||
) -> float | None:
|
||||
"""Validate and return."""
|
||||
if result := func(entity)[area][index]:
|
||||
if (result := func(entity)[area][index]) is not None:
|
||||
return result / 1000
|
||||
return None
|
||||
|
||||
|
@ -162,7 +162,7 @@
|
||||
"deliveryEnd": "2024-11-05T19:00:00Z",
|
||||
"entryPerArea": {
|
||||
"SE3": 1011.77,
|
||||
"SE4": 1804.46
|
||||
"SE4": 0.0
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -519,7 +519,7 @@
|
||||
'deliveryStart': '2024-11-05T18:00:00Z',
|
||||
'entryPerArea': dict({
|
||||
'SE3': 1011.77,
|
||||
'SE4': 1804.46,
|
||||
'SE4': 0.0,
|
||||
}),
|
||||
}),
|
||||
dict({
|
||||
|
@ -1332,7 +1332,7 @@
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '1.80446',
|
||||
'state': '0.0',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[sensor.nord_pool_se4_daily_average-entry]
|
||||
@ -1580,9 +1580,9 @@
|
||||
# name: test_sensor[sensor.nord_pool_se4_lowest_price-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'end': '2024-11-05T03:00:00+00:00',
|
||||
'end': '2024-11-05T19:00:00+00:00',
|
||||
'friendly_name': 'Nord Pool SE4 Lowest price',
|
||||
'start': '2024-11-05T02:00:00+00:00',
|
||||
'start': '2024-11-05T18:00:00+00:00',
|
||||
'unit_of_measurement': 'SEK/kWh',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@ -1590,7 +1590,7 @@
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0.06519',
|
||||
'state': '0.0',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[sensor.nord_pool_se4_next_price-entry]
|
||||
|
@ -33,6 +33,19 @@ async def test_sensor(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2024-11-05T18:00:00+00:00")
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_sensor_current_price_is_0(
|
||||
hass: HomeAssistant, load_int: ConfigEntry
|
||||
) -> None:
|
||||
"""Test the Nord Pool sensor working if price is 0."""
|
||||
|
||||
current_price = hass.states.get("sensor.nord_pool_se4_current_price")
|
||||
|
||||
assert current_price is not None
|
||||
assert current_price.state == "0.0" # SE4 2024-11-05T18:00:00Z
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2024-11-05T23:00:00+00:00")
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_sensor_no_next_price(hass: HomeAssistant, load_int: ConfigEntry) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user