From 4a68164dce08fed727fa019c3e5c573d06d97f1a Mon Sep 17 00:00:00 2001 From: Anton Starikov Date: Thu, 5 Dec 2024 22:16:36 +0100 Subject: [PATCH 1/3] Update to qestdb 2.0.3 API --- custom_components/qss/const.py | 2 +- custom_components/qss/event_handling.py | 3 ++- custom_components/qss/io.py | 16 +++++++++++++--- custom_components/qss/manifest.json | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/custom_components/qss/const.py b/custom_components/qss/const.py index 060dbaf..6bc0f01 100644 --- a/custom_components/qss/const.py +++ b/custom_components/qss/const.py @@ -14,7 +14,7 @@ CONF_AUTH_Y_KEY = "y_key" RETRY_WAIT_SECONDS = 5 -RETRY_ATTEMPTS = 10 +RETRY_ATTEMPTS = 10000 STARTUP_MESSAGE = f""" ------------------------------------------------------------------- diff --git a/custom_components/qss/event_handling.py b/custom_components/qss/event_handling.py index 1203c44..0ab8e36 100644 --- a/custom_components/qss/event_handling.py +++ b/custom_components/qss/event_handling.py @@ -10,7 +10,8 @@ def put_event_to_queue(event: Event, entity_filter: Callable[[str], bool], queue """Get events with new states and put them in the process queue.""" entity_id = event.data.get(ATTR_ENTITY_ID) state = event.data.get("new_state") - if all([entity_id, state, state.state != STATE_UNKNOWN, entity_filter(entity_id)]): + if state is not None: + if all([entity_id, state, state.state != STATE_UNKNOWN, entity_filter(entity_id)]): queue.put(event) diff --git a/custom_components/qss/io.py b/custom_components/qss/io.py index b33e591..4cad701 100644 --- a/custom_components/qss/io.py +++ b/custom_components/qss/io.py @@ -4,7 +4,7 @@ from queue import Queue from homeassistant.core import Event -from questdb.ingress import IngressError, Sender +from questdb.ingress import IngressError, Sender, Protocol from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed from .const import RETRY_ATTEMPTS, RETRY_WAIT_SECONDS @@ -13,7 +13,14 @@ def _insert_row_with_auth(host: str, port: int, auth: tuple, event: Event) -> None: - with Sender(host, port, auth=auth, tls=True) as sender: + with Sender( + Protocol.Tcps, + host, + port, + username=auth[0], + token=auth[1], + token_x=auth[2], + token_y=auth[3]) as sender: entity_id = event.data["entity_id"] state = event.data.get("new_state") attrs = dict(state.attributes) @@ -33,7 +40,10 @@ def _insert_row_with_auth(host: str, port: int, auth: tuple, event: Event) -> No def _insert_row_without_auth(host: str, port: int, event: Event) -> None: - with Sender(host, port) as sender: + with Sender( + Protocol.Tcp, + host, + port) as sender: entity_id = event.data["entity_id"] state = event.data.get("new_state") attrs = dict(state.attributes) diff --git a/custom_components/qss/manifest.json b/custom_components/qss/manifest.json index c0288f7..9c872cd 100644 --- a/custom_components/qss/manifest.json +++ b/custom_components/qss/manifest.json @@ -6,6 +6,6 @@ "documentation": "https://github.com/CM000n/QSS", "iot_class": "local_push", "issue_tracker": "https://github.com/CM000n/QSS/issues", - "requirements": ["questdb>=1.2,<2.0", "tenacity>=8.0"], + "requirements": ["questdb==2.0.3", "tenacity>=8.0"], "version": "v0.0.10" } From 60dae1d381aefcf78e6fe2a76eb97e86fa835f44 Mon Sep 17 00:00:00 2001 From: Anton Starikov Date: Thu, 12 Dec 2024 18:23:50 +0100 Subject: [PATCH 2/3] Change formatting to make linter happy, update of project file --- custom_components/qss/event_handling.py | 4 ++-- custom_components/qss/io.py | 16 +++------------- pyproject.toml | 8 ++++---- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/custom_components/qss/event_handling.py b/custom_components/qss/event_handling.py index 0ab8e36..ed186bb 100644 --- a/custom_components/qss/event_handling.py +++ b/custom_components/qss/event_handling.py @@ -11,8 +11,8 @@ def put_event_to_queue(event: Event, entity_filter: Callable[[str], bool], queue entity_id = event.data.get(ATTR_ENTITY_ID) state = event.data.get("new_state") if state is not None: - if all([entity_id, state, state.state != STATE_UNKNOWN, entity_filter(entity_id)]): - queue.put(event) + if all([entity_id, state, state.state != STATE_UNKNOWN, entity_filter(entity_id)]): + queue.put(event) def get_event_from_queue(queue: Queue) -> Event: diff --git a/custom_components/qss/io.py b/custom_components/qss/io.py index 4cad701..ad697f7 100644 --- a/custom_components/qss/io.py +++ b/custom_components/qss/io.py @@ -4,7 +4,7 @@ from queue import Queue from homeassistant.core import Event -from questdb.ingress import IngressError, Sender, Protocol +from questdb.ingress import IngressError, Protocol, Sender from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed from .const import RETRY_ATTEMPTS, RETRY_WAIT_SECONDS @@ -13,14 +13,7 @@ def _insert_row_with_auth(host: str, port: int, auth: tuple, event: Event) -> None: - with Sender( - Protocol.Tcps, - host, - port, - username=auth[0], - token=auth[1], - token_x=auth[2], - token_y=auth[3]) as sender: + with Sender(Protocol.Tcps, host, port, username=auth[0], token=auth[1], token_x=auth[2], token_y=auth[3]) as sender: entity_id = event.data["entity_id"] state = event.data.get("new_state") attrs = dict(state.attributes) @@ -40,10 +33,7 @@ def _insert_row_with_auth(host: str, port: int, auth: tuple, event: Event) -> No def _insert_row_without_auth(host: str, port: int, event: Event) -> None: - with Sender( - Protocol.Tcp, - host, - port) as sender: + with Sender(Protocol.Tcp, host, port) as sender: entity_id = event.data["entity_id"] state = event.data.get("new_state") attrs = dict(state.attributes) diff --git a/pyproject.toml b/pyproject.toml index 9a208d5..63d07f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "qss" -version = "v0.0.10" +version = "v0.0.11" description = "QuestDB State Storage (QSS) for Home Assistant" authors = ["CM000n"] keywords = [ @@ -17,14 +17,14 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.11" -homeassistant = "^2023.12" -questdb = "^1.2.0" +homeassistant = "^2024.12" +questdb = "^2.0.3" tenacity = "^8.0.0" [tool.poetry.dev-dependencies] voluptuous-stubs = "^0.1" -homeassistant-stubs = "^2023.12" +homeassistant-stubs = "^2024.12" pre-commit = "^2.21.0" pre-commit-hooks = "^4.5.0" codespell = "^2.0.0" From fdc9697e0653b86a7539363ad56375ef61b86072 Mon Sep 17 00:00:00 2001 From: Anton Starikov Date: Thu, 12 Dec 2024 18:26:04 +0100 Subject: [PATCH 3/3] Update version in the manifest --- custom_components/qss/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/qss/manifest.json b/custom_components/qss/manifest.json index 9c872cd..c33e894 100644 --- a/custom_components/qss/manifest.json +++ b/custom_components/qss/manifest.json @@ -7,5 +7,5 @@ "iot_class": "local_push", "issue_tracker": "https://github.com/CM000n/QSS/issues", "requirements": ["questdb==2.0.3", "tenacity>=8.0"], - "version": "v0.0.10" + "version": "v0.0.11" }