Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nordpool Not to return Unknown if price is exactly 0 #140647

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions homeassistant/components/nordpool/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ def validate_prices(
index: int,
) -> float | None:
"""Validate and return."""
if result := func(entity)[area][index]:
return result / 1000
return None
result = func(entity)[area][index]
if result is None:
return None
if result == 0:
return float(0)
return result / 1000


def get_prices(
Expand Down
66 changes: 33 additions & 33 deletions tests/components/nordpool/fixtures/delivery_period_today.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,191 +10,191 @@
"deliveryEnd": "2024-11-05T00:00:00Z",
"entryPerArea": {
"SE3": 250.73,
"SE4": 283.79
"SE4": 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change one and not all of them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original idea was to test whether average values work even when they are all exactly 0.

For example NordpoolDailyAveragePriceSensor
return data.area_average[self.area] / 1000

}
},
{
"deliveryStart": "2024-11-05T00:00:00Z",
"deliveryEnd": "2024-11-05T01:00:00Z",
"entryPerArea": {
"SE3": 76.36,
"SE4": 81.36
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T01:00:00Z",
"deliveryEnd": "2024-11-05T02:00:00Z",
"entryPerArea": {
"SE3": 73.92,
"SE4": 79.15
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T02:00:00Z",
"deliveryEnd": "2024-11-05T03:00:00Z",
"entryPerArea": {
"SE3": 61.69,
"SE4": 65.19
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T03:00:00Z",
"deliveryEnd": "2024-11-05T04:00:00Z",
"entryPerArea": {
"SE3": 64.6,
"SE4": 68.44
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T04:00:00Z",
"deliveryEnd": "2024-11-05T05:00:00Z",
"entryPerArea": {
"SE3": 453.27,
"SE4": 516.71
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T05:00:00Z",
"deliveryEnd": "2024-11-05T06:00:00Z",
"entryPerArea": {
"SE3": 996.28,
"SE4": 1240.85
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T06:00:00Z",
"deliveryEnd": "2024-11-05T07:00:00Z",
"entryPerArea": {
"SE3": 1406.14,
"SE4": 1648.25
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T07:00:00Z",
"deliveryEnd": "2024-11-05T08:00:00Z",
"entryPerArea": {
"SE3": 1346.54,
"SE4": 1570.5
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T08:00:00Z",
"deliveryEnd": "2024-11-05T09:00:00Z",
"entryPerArea": {
"SE3": 1150.28,
"SE4": 1345.37
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T09:00:00Z",
"deliveryEnd": "2024-11-05T10:00:00Z",
"entryPerArea": {
"SE3": 1031.32,
"SE4": 1206.51
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T10:00:00Z",
"deliveryEnd": "2024-11-05T11:00:00Z",
"entryPerArea": {
"SE3": 927.37,
"SE4": 1085.8
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T11:00:00Z",
"deliveryEnd": "2024-11-05T12:00:00Z",
"entryPerArea": {
"SE3": 925.05,
"SE4": 1081.72
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T12:00:00Z",
"deliveryEnd": "2024-11-05T13:00:00Z",
"entryPerArea": {
"SE3": 949.49,
"SE4": 1130.38
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T13:00:00Z",
"deliveryEnd": "2024-11-05T14:00:00Z",
"entryPerArea": {
"SE3": 1042.03,
"SE4": 1256.91
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T14:00:00Z",
"deliveryEnd": "2024-11-05T15:00:00Z",
"entryPerArea": {
"SE3": 1258.89,
"SE4": 1765.82
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T15:00:00Z",
"deliveryEnd": "2024-11-05T16:00:00Z",
"entryPerArea": {
"SE3": 1816.45,
"SE4": 2522.55
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T16:00:00Z",
"deliveryEnd": "2024-11-05T17:00:00Z",
"entryPerArea": {
"SE3": 2512.65,
"SE4": 3533.03
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T17:00:00Z",
"deliveryEnd": "2024-11-05T18:00:00Z",
"entryPerArea": {
"SE3": 1819.83,
"SE4": 2524.06
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T18:00:00Z",
"deliveryEnd": "2024-11-05T19:00:00Z",
"entryPerArea": {
"SE3": 1011.77,
"SE4": 1804.46
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T19:00:00Z",
"deliveryEnd": "2024-11-05T20:00:00Z",
"entryPerArea": {
"SE3": 835.53,
"SE4": 1112.57
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T20:00:00Z",
"deliveryEnd": "2024-11-05T21:00:00Z",
"entryPerArea": {
"SE3": 796.19,
"SE4": 1051.69
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T21:00:00Z",
"deliveryEnd": "2024-11-05T22:00:00Z",
"entryPerArea": {
"SE3": 522.3,
"SE4": 662.44
"SE4": 0.0
}
},
{
"deliveryStart": "2024-11-05T22:00:00Z",
"deliveryEnd": "2024-11-05T23:00:00Z",
"entryPerArea": {
"SE3": 289.14,
"SE4": 349.21
"SE4": 0.0
}
}
],
Expand All @@ -210,9 +210,9 @@
"max": 1406.14
},
"SE4": {
"average": 497.97,
"min": 65.19,
"max": 1648.25
"average": 0.0,
"min": 0.0,
"max": 0.0
}
}
},
Expand All @@ -227,9 +227,9 @@
"max": 2512.65
},
"SE4": {
"average": 1735.59,
"min": 1081.72,
"max": 3533.03
"average": 0.0,
"min": 0.0,
"max": 0.0
}
}
},
Expand All @@ -245,8 +245,8 @@
},
"SE4": {
"average": 793.98,
"min": 349.21,
"max": 1112.57
"min": 0.0,
"max": 0.0
}
}
}
Expand All @@ -266,7 +266,7 @@
},
{
"areaCode": "SE4",
"price": 1166.12
"price": 0.0
}
]
}
Loading