Skip to content

Commit 6594d59

Browse files
committed
combining the logic for inserting rows with and without authentication
1 parent 0f13805 commit 6594d59

File tree

1 file changed

+4
-30
lines changed
  • custom_components/qss

1 file changed

+4
-30
lines changed

custom_components/qss/io.py

+4-30
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,9 @@
1212
_LOGGER = logging.getLogger(__name__)
1313

1414

15-
def _insert_row_with_auth(host: str, port: int, auth: tuple, event: Event) -> None:
16-
with Sender(host, port, auth=auth, tls=True) as sender:
17-
entity_id = event.data["entity_id"]
18-
state = event.data.get("new_state")
19-
attrs = dict(state.attributes)
20-
sender.row(
21-
"qss",
22-
symbols={
23-
"entity_id": entity_id,
24-
},
25-
columns={
26-
"state": state.state,
27-
"attributes": dumps(attrs, sort_keys=True, default=str),
28-
},
29-
at=event.time_fired,
30-
)
31-
32-
sender.flush()
33-
34-
35-
def _insert_row_without_auth(host: str, port: int, event: Event) -> None:
36-
with Sender(host, port) as sender:
15+
def _insert_row(host: str, port: int, auth: tuple, event: Event) -> None:
16+
tls = bool(auth)
17+
with Sender(host, port, auth=auth, tls=tls) as sender:
3718
entity_id = event.data["entity_id"]
3819
state = event.data.get("new_state")
3920
attrs = dict(state.attributes)
@@ -52,20 +33,13 @@ def _insert_row_without_auth(host: str, port: int, event: Event) -> None:
5233
sender.flush()
5334

5435

55-
def _insert_row(host: str, port: int, auth: tuple, event: Event) -> None:
56-
if all(auth):
57-
_insert_row_with_auth(host, port, auth, event)
58-
else:
59-
_insert_row_without_auth(host, port, event)
60-
61-
6236
@retry(
6337
stop=stop_after_attempt(RETRY_ATTEMPTS),
6438
wait=wait_fixed(RETRY_WAIT_SECONDS),
6539
retry=retry_if_exception_type(IngressError),
6640
)
6741
def _retry_data_insertion(host: str, port: int, auth: tuple, event: Event) -> None:
68-
"""Usign a retry for inserting event data into QuestDB."""
42+
"""Use a retry for inserting event data into QuestDB."""
6943
_insert_row(host, port, auth, event)
7044

7145

0 commit comments

Comments
 (0)