From 3562c4ac1fbbae3c2cc633459faa7ea7fccd2ba4 Mon Sep 17 00:00:00 2001 From: Johannes Ott Date: Mon, 24 Jun 2024 20:28:24 +0200 Subject: [PATCH] Bump versions and reconnect fix Signed-off-by: Johannes Ott --- .github/workflows/build_project.yml | 2 +- requirements.txt | 6 +++--- solaredge2mqtt/core/events/__init__.py | 4 ++-- solaredge2mqtt/core/mqtt/__init__.py | 4 +--- solaredge2mqtt/core/mqtt/settings.py | 15 +++++++++++++-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_project.yml b/.github/workflows/build_project.yml index 54ee91e..c9d22e7 100644 --- a/.github/workflows/build_project.yml +++ b/.github/workflows/build_project.yml @@ -147,7 +147,7 @@ jobs: ${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }} - name: Build and push Docker image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: builder: ${{ steps.buildx.outputs.name }} context: . diff --git a/requirements.txt b/requirements.txt index 812b1ed..89f855d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,11 +6,11 @@ ephem==4.1.5 influxdb-client==1.43.0 jsonref==1.1.0 loguru==0.7.2 -numpy==1.26.4 +numpy==2.0.0 pandas==2.2.2 -pydantic==2.7.1 +pydantic==2.7.4 pyjwt==2.8.0 -requests==2.32.2 +requests==2.32.3 scikit-learn==1.4.2 scipy==1.13.1 solaredge_modbus==0.8.0 diff --git a/solaredge2mqtt/core/events/__init__.py b/solaredge2mqtt/core/events/__init__.py index 7c30a91..e6e2cb6 100644 --- a/solaredge2mqtt/core/events/__init__.py +++ b/solaredge2mqtt/core/events/__init__.py @@ -3,7 +3,7 @@ import asyncio from typing import Callable -from aiomqtt import MqttError +from aiomqtt import MqttCodeError from solaredge2mqtt.core.exceptions import InvalidDataException from solaredge2mqtt.core.logging import logger @@ -71,7 +71,7 @@ async def _notify_listeners( await asyncio.gather( *[self._notify_listener(listener, event) for listener in listeners] ) - except MqttError as error: + except MqttCodeError as error: raise error except asyncio.CancelledError: pass diff --git a/solaredge2mqtt/core/mqtt/__init__.py b/solaredge2mqtt/core/mqtt/__init__.py index b08954f..9571463 100644 --- a/solaredge2mqtt/core/mqtt/__init__.py +++ b/solaredge2mqtt/core/mqtt/__init__.py @@ -36,10 +36,8 @@ def __init__(self, settings: MQTTSettings, event_bus: EventBus): super().__init__( self.broker, self.port, - username=settings.username, - password=settings.password.get_secret_value(), - identifier=settings.client_id, will=will, + **settings.kargs, ) def _subscribe_events(self) -> None: diff --git a/solaredge2mqtt/core/mqtt/settings.py b/solaredge2mqtt/core/mqtt/settings.py index 6139e20..9510f66 100644 --- a/solaredge2mqtt/core/mqtt/settings.py +++ b/solaredge2mqtt/core/mqtt/settings.py @@ -5,6 +5,17 @@ class MQTTSettings(BaseModel): client_id: str = Field("solaredge2mqtt") broker: str port: int = Field(1883) - username: str - password: SecretStr + username: str | None = Field(None) + password: SecretStr | None = Field(None) topic_prefix: str = Field("solaredge") + + @property + def kargs(self) -> dict[str, str]: + args = {"identifier": self.client_id} + + if self.username is not None: + args["username"] = self.username + if self.password is not None: + args["password"] = self.password.get_secret_value() + + return args