Skip to content

Commit

Permalink
Fix tls handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
CM000n committed Dec 14, 2023
1 parent 8347f76 commit ae0338d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
30 changes: 26 additions & 4 deletions custom_components/qss/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,28 @@
_LOGGER = logging.getLogger(__name__)


def _insert_row(host: str, port: int, auth: tuple, event: Event) -> None:
tls = bool(auth)
with Sender(host, port, auth=auth, tls=tls) as sender:
def _insert_row_with_auth(host: str, port: int, auth: tuple, event: Event) -> None:
with Sender(host, port, auth=auth, tls=True) as sender:
entity_id = event.data["entity_id"]
state = event.data.get("new_state")
attrs = dict(state.attributes)
sender.row(
"qss",
symbols={
"entity_id": entity_id,
},
columns={
"state": state.state,
"attributes": dumps(attrs, sort_keys=True, default=str),
},
at=event.time_fired,
)

sender.flush()


def _insert_row_without_auth(host: str, port: int, event: Event) -> None:
with Sender(host, port) as sender:
entity_id = event.data["entity_id"]
state = event.data.get("new_state")
attrs = dict(state.attributes)
Expand All @@ -40,7 +59,10 @@ def _insert_row(host: str, port: int, auth: tuple, event: Event) -> None:
)
def _retry_data_insertion(host: str, port: int, auth: tuple, event: Event) -> None:
"""Use a retry for inserting event data into QuestDB."""
_insert_row(host, port, auth, event)
if all(auth):
_insert_row_with_auth(host, port, auth, event)
else:
_insert_row_without_auth(host, port, event)


def insert_event_data_into_questdb(host: str, port: int, auth: tuple, event: Event, queue: Queue) -> None:
Expand Down
42 changes: 21 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "qss"
version = "v0.0.7"
version = "v0.0.8"
description = "QuestDB State Storage (QSS) for Home Assistant"
license = "MIT"
readme = "README.md"
Expand Down

0 comments on commit ae0338d

Please sign in to comment.