Skip to content

Commit e4270da

Browse files
committed
🐛 Fix one-line conditional
matching for 'not None' instead of positive value 🙈
1 parent f188bda commit e4270da

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [v4.2.1](https://github.com/azogue/aiopvpc/tree/v4.2.1) - Fix injection price sensor attributes (2) (2023-05-29)
4+
5+
[Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.2.0...v4.2.1)
6+
7+
- 🐛 Fix one-line conditional matching for 'not None' instead of positive value 🙈
8+
- ✅ tests: Add unit test for price sensor attributes
9+
310
## [v4.2.0](https://github.com/azogue/aiopvpc/tree/v4.2.0) - Fix injection price sensor attributes (2023-05-29)
411

512
[Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.1.0...v4.2.0)

aiopvpc/prices.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ def _make_price_stats_attributes(
8080
except ZeroDivisionError: # pragma: no cover
8181
pass
8282
attributes["max_price"] = max_price
83-
best_price_at = next(iter(prices_sorted)).astimezone(timezone).hour
84-
worst_price_at = next(iter(reversed(prices_sorted))).astimezone(timezone).hour
85-
attributes["max_price_at"] = worst_price_at if sign_is_best else best_price_at
83+
first_price_at = next(iter(prices_sorted)).astimezone(timezone).hour
84+
last_price_at = next(iter(reversed(prices_sorted))).astimezone(timezone).hour
85+
attributes["max_price_at"] = last_price_at if sign_is_best == 1 else first_price_at
8686
attributes["min_price"] = min_price
87-
attributes["min_price_at"] = best_price_at if sign_is_best else worst_price_at
87+
attributes["min_price_at"] = first_price_at if sign_is_best == 1 else last_price_at
8888
attributes["next_best_at"] = [
8989
ts.astimezone(timezone).hour for ts in prices_sorted.keys() if ts >= utc_time
9090
]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ markers = [
4040

4141
[tool.poetry]
4242
name = "aiopvpc"
43-
version = "4.2.0"
43+
version = "4.2.1"
4444
description = "Retrieval of Spanish Electricity hourly prices (PVPC)"
4545
authors = ["Eugenio Panadero <[email protected]>"]
4646
license = "MIT"

0 commit comments

Comments
 (0)