Skip to content

Commit

Permalink
Merge branch 'palazzem/issue-23' into palazzem/v1.1.0.dev1
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem committed Sep 12, 2023
2 parents 48fbafb + 61d3267 commit eabe099
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions custom_components/elmo_iess_alarm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

from .const import (
CONF_DOMAIN,
CONF_SCAN_INTERVAL,
CONF_SYSTEM_URL,
DOMAIN,
KEY_COORDINATOR,
KEY_DEVICE,
KEY_UNSUBSCRIBER,
POLLING_TIMEOUT,
SCAN_INTERVAL,
SCAN_INTERVAL_DEFAULT,
)
from .devices import AlarmDevice

Expand Down Expand Up @@ -89,11 +90,12 @@ async def async_update_data():
await hass.async_add_executor_job(device.connect, entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD])
_LOGGER.info("Token was invalid or expired, re-authentication executed.")

scan_interval = entry.options.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL_DEFAULT)
coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name="elmo_iess_alarm",
update_interval=timedelta(seconds=SCAN_INTERVAL),
update_interval=timedelta(seconds=scan_interval),
update_method=async_update_data,
)

Expand Down
8 changes: 8 additions & 0 deletions custom_components/elmo_iess_alarm/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
CONF_AREAS_ARM_NIGHT,
CONF_AREAS_ARM_VACATION,
CONF_DOMAIN,
CONF_SCAN_INTERVAL,
CONF_SYSTEM_URL,
DOMAIN,
SCAN_INTERVAL_DEFAULT,
SUPPORTED_SYSTEMS,
)
from .exceptions import InvalidAreas
Expand Down Expand Up @@ -126,6 +128,7 @@ async def async_step_init(self, user_input=None):
suggest_arm_vacation = user_input.get(CONF_AREAS_ARM_VACATION) or self.config_entry.options.get(
CONF_AREAS_ARM_VACATION
)
suggest_scan_interval = user_input.get(CONF_SCAN_INTERVAL) or self.config_entry.options.get(CONF_SCAN_INTERVAL)
return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
Expand All @@ -142,6 +145,11 @@ async def async_step_init(self, user_input=None):
CONF_AREAS_ARM_VACATION,
description={"suggested_value": suggest_arm_vacation},
): str,
vol.Required(
CONF_SCAN_INTERVAL,
default=SCAN_INTERVAL_DEFAULT,
description={"suggested_value": suggest_scan_interval},
): int,
}
),
errors=errors,
Expand Down
4 changes: 3 additions & 1 deletion custom_components/elmo_iess_alarm/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
CONF_AREAS_ARM_HOME = "areas_arm_home"
CONF_AREAS_ARM_NIGHT = "areas_arm_night"
CONF_AREAS_ARM_VACATION = "areas_arm_vacation"
CONF_SCAN_INTERVAL = "scan_interval"
DOMAIN = "elmo_iess_alarm"
KEY_DEVICE = "device"
KEY_COORDINATOR = "coordinator"
KEY_UNSUBSCRIBER = "options_unsubscriber"
# Fast scanning is fine because long-polling is used
# and lasts 15 seconds
SCAN_INTERVAL = 5
# TODO: update this comment explaining the default value
SCAN_INTERVAL_DEFAULT = 5
POLLING_TIMEOUT = 20

0 comments on commit eabe099

Please sign in to comment.