Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
complete implementation of timestamp and protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
eavanvalkenburg committed May 10, 2021
1 parent 5845a53 commit dc7f65e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/sia/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def async_step_user(self, user_input: dict = None):

def update_data(self, user_input):
"""Parse the user_input and store in self.data."""
if not self._data:
if not self._data or user_input.get(CONF_PORT):
self._data = {
CONF_PORT: user_input[CONF_PORT],
CONF_PROTOCOL: user_input[CONF_PROTOCOL],
Expand Down
4 changes: 4 additions & 0 deletions custom_components/sia/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
EVENT_MESSAGE = "last_message"
EVENT_ID = "last_id"
EVENT_TIMESTAMP = "last_timestamp"


DEFAULT_TIMEBAND = (80, 40)
IGNORED_TIMEBAND = (3600, 1800)
17 changes: 12 additions & 5 deletions custom_components/sia/hub.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"""The sia hub."""
import logging

from homeassistant.const import CONF_PORT, EVENT_HOMEASSISTANT_STOP
from homeassistant.const import CONF_PORT, CONF_PROTOCOL, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import Event, EventOrigin, HomeAssistant
from homeassistant.helpers import device_registry as dr
from pysiaalarm.aio import SIAAccount, SIAClient, SIAEvent
from pysiaalarm.aio import SIAAccount, SIAClient, SIAEvent, CommunicationsProtocol

from .const import (
CONF_ACCOUNT,
CONF_ACCOUNTS,
CONF_ENCRYPTION_KEY,
CONF_IGNORE_TIMESTAMPS,
DOMAIN,
SIA_EVENT,
IGNORED_TIMEBAND,
DEFAULT_TIMEBAND,
)

ALLOWED_TIMEBAND = (300, 150)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -31,14 +33,19 @@ def __init__(
self.entry_id = entry_id
self._title = title
self._accounts = hub_config[CONF_ACCOUNTS]
self._protocol = hub_config[CONF_PROTOCOL]

self._remove_shutdown_listener = None
self.sia_accounts = [
SIAAccount(a[CONF_ACCOUNT], a.get(CONF_ENCRYPTION_KEY), ALLOWED_TIMEBAND)
SIAAccount(
a[CONF_ACCOUNT],
a.get(CONF_ENCRYPTION_KEY),
IGNORED_TIMEBAND if a[CONF_IGNORE_TIMESTAMPS] else DEFAULT_TIMEBAND,
)
for a in self._accounts
]
self.sia_client = SIAClient(
"", self._port, self.sia_accounts, self.async_create_and_fire_event
"", self._port, self.sia_accounts, self.async_create_and_fire_event, CommunicationsProtocol(self._protocol)
)

async def async_setup_hub(self):
Expand Down

0 comments on commit dc7f65e

Please sign in to comment.