fix: logging, prediction update, multiple bugs (#584)
Some checks failed
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled

* Fix logging configuration issues that made logging stop operation. Switch to Loguru
  logging (from Python logging). Enable console and file logging with different log levels.
  Add logging documentation.

* Fix logging configuration and EOS configuration out of sync. Added tracking support
  for nested value updates of Pydantic models. This used to update the logging configuration
  when the EOS configurationm for logging is changed. Should keep logging config and EOS
  config in sync as long as all changes to the EOS logging configuration are done by
  set_nested_value(), which is the case for the REST API.

* Fix energy management task looping endlessly after the second update when trying to update
  the last_update datetime.

* Fix get_nested_value() to correctly take values from the dicts in a Pydantic model instance.

* Fix usage of model classes instead of model instances in nested value access when evaluation
  the value type that is associated to each key.

* Fix illegal json format in prediction documentation for PVForecastAkkudoktor provider.

* Fix documentation qirks and add EOS Connect to integrations.

* Support deprecated fields in configuration in documentation generation and EOSdash.

* Enhance EOSdash demo to show BrightSky humidity data (that is often missing)

* Update documentation reference to German EOS installation videos.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte
2025-06-10 22:00:28 +02:00
committed by GitHub
parent 9d46f3c08e
commit bd38b3c5ef
70 changed files with 5927 additions and 5035 deletions

View File

@@ -66,6 +66,11 @@ class TestPydanticModelNestedValueMixin:
with pytest.raises(TypeError):
PydanticModelNestedValueMixin._get_key_types(User, "unknown_field")
def test_get_key_types_for_instance_raises(self, user_instance):
"""Test _get_key_types raises an error for an instance."""
with pytest.raises(TypeError):
PydanticModelNestedValueMixin._get_key_types(user_instance, "unknown_field")
def test_set_nested_value_in_model(self, user_instance):
"""Test setting nested value in a model field (Address -> city)."""
assert user_instance.addresses is None
@@ -123,7 +128,7 @@ class TestPydanticModelNestedValueMixin:
"""Test attempting to set value for a non-existent field."""
user = User(name="John")
with pytest.raises(ValueError):
with pytest.raises(TypeError):
user.set_nested_value("non_existent_field", "Some Value")
def test_set_nested_value_with_invalid_type(self, user_instance):
@@ -144,6 +149,91 @@ class TestPydanticModelNestedValueMixin:
"The first address should be an instance of Address"
)
def test_track_nested_value_simple_callback(self, user_instance):
user_instance.set_nested_value("addresses/0/city", "NY")
assert user_instance.addresses is not None
assert user_instance.addresses[0].city == "NY"
callback_calls = []
def cb(model, path, old, new):
callback_calls.append((path, old, new))
user_instance.track_nested_value("addresses/0/city", cb)
user_instance.set_nested_value("addresses/0/city", "LA")
assert user_instance.addresses is not None
assert user_instance.addresses[0].city == "LA"
assert callback_calls == [("addresses/0/city", "NY", "LA")]
def test_track_nested_value_prefix_triggers(self, user_instance):
user_instance.set_nested_value("addresses/0", Address(city="Berlin", postal_code="10000"))
assert user_instance.addresses is not None
assert user_instance.addresses[0].city == "Berlin"
cb_prefix = []
cb_exact = []
def cb1(model, path, old, new):
cb_prefix.append((path, old, new))
def cb2(model, path, old, new):
cb_exact.append((path, old, new))
user_instance.track_nested_value("addresses/0", cb1)
user_instance.track_nested_value("addresses/0/city", cb2)
user_instance.set_nested_value("addresses/0/city", "Munich")
assert user_instance.addresses is not None
assert user_instance.addresses[0].city == "Munich"
# Both callbacks should be triggered
assert cb_prefix == [("addresses/0/city", "Berlin", "Munich")]
assert cb_exact == [("addresses/0/city", "Berlin", "Munich")]
def test_track_nested_value_multiple_callbacks_same_path(self, user_instance):
user_instance.set_nested_value("addresses/0/city", "Berlin")
calls1 = []
calls2 = []
user_instance.track_nested_value("addresses/0/city", lambda lib, path, o, n: calls1.append((path, o, n)))
user_instance.track_nested_value("addresses/0/city", lambda lib, path, o, n: calls2.append((path, o, n)))
user_instance.set_nested_value("addresses/0/city", "Stuttgart")
assert calls1 == [("addresses/0/city", "Berlin", "Stuttgart")]
assert calls2 == [("addresses/0/city", "Berlin", "Stuttgart")]
def test_track_nested_value_invalid_path_raises(self, user_instance):
with pytest.raises(ValueError) as excinfo:
user_instance.track_nested_value("unknown_field", lambda model, path, o, n: None)
assert "is invalid" in str(excinfo.value)
with pytest.raises(ValueError) as excinfo:
user_instance.track_nested_value("unknown_field/0/city", lambda model, path, o, n: None)
assert "is invalid" in str(excinfo.value)
def test_track_nested_value_list_and_dict_path(self):
class Book(PydanticBaseModel):
title: str
class Library(PydanticBaseModel):
books: list[Book]
meta: dict[str, str] = {}
lib = Library(books=[Book(title="A")], meta={"location": "center"})
assert lib.meta["location"] == "center"
calls = []
# For list, only root attribute structure is checked, not indices
lib.track_nested_value("books/0/title", lambda lib, path, o, n: calls.append((path, o, n)))
lib.set_nested_value("books/0/title", "B")
assert lib.books[0].title == "B"
assert calls == [("books/0/title", "A", "B")]
# For dict, only root attribute structure is checked
meta_calls = []
lib.track_nested_value("meta/location", lambda lib, path, o, n: meta_calls.append((path, o, n)))
assert lib.meta["location"] == "center"
lib.set_nested_value("meta/location", "north")
assert lib.meta["location"] == "north"
assert meta_calls == [("meta/location", "center", "north")]
class TestPydanticBaseModel:
def test_valid_pendulum_datetime(self):