Skip to content

Commit

Permalink
Configurable maximum concurrency in Risco local
Browse files Browse the repository at this point in the history
  • Loading branch information
OnFreund committed Apr 8, 2024
1 parent f23e48f commit 418239f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion homeassistant/components/risco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import (
CONF_CONCURRENCY,
DATA_COORDINATOR,
DEFAULT_CONCURRENCY,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
EVENTS_COORDINATOR,
Expand Down Expand Up @@ -85,7 +87,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def _async_setup_local_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
data = entry.data
risco = RiscoLocal(data[CONF_HOST], data[CONF_PORT], data[CONF_PIN])
concurrency = entry.options.get(CONF_CONCURRENCY, DEFAULT_CONCURRENCY)
risco = RiscoLocal(
data[CONF_HOST], data[CONF_PORT], data[CONF_PIN], concurrency=concurrency
)

try:
await risco.connect()
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/risco/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
CONF_CODE_ARM_REQUIRED,
CONF_CODE_DISARM_REQUIRED,
CONF_COMMUNICATION_DELAY,
CONF_CONCURRENCY,
CONF_HA_STATES_TO_RISCO,
CONF_RISCO_STATES_TO_HA,
DEFAULT_OPTIONS,
Expand Down Expand Up @@ -230,6 +231,9 @@ def _options_schema(self) -> vol.Schema:
vol.Required(
CONF_SCAN_INTERVAL, default=self._data[CONF_SCAN_INTERVAL]
): int,
vol.Required(
CONF_CONCURRENCY, default=self._data[CONF_CONCURRENCY]
): int,
vol.Required(
CONF_CODE_ARM_REQUIRED, default=self._data[CONF_CODE_ARM_REQUIRED]
): bool,
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/risco/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
EVENTS_COORDINATOR = "risco_events"

DEFAULT_SCAN_INTERVAL = 30
DEFAULT_CONCURRENCY = 4

TYPE_LOCAL = "local"

Expand All @@ -25,6 +26,7 @@
CONF_RISCO_STATES_TO_HA = "risco_states_to_ha"
CONF_HA_STATES_TO_RISCO = "ha_states_to_risco"
CONF_COMMUNICATION_DELAY = "communication_delay"
CONF_CONCURRENCY = "concurrency"

RISCO_GROUPS = ["A", "B", "C", "D"]
RISCO_ARM = "arm"
Expand All @@ -45,6 +47,7 @@

DEFAULT_OPTIONS = {
CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL,
CONF_CONCURRENCY: DEFAULT_CONCURRENCY,
CONF_CODE_ARM_REQUIRED: False,
CONF_CODE_DISARM_REQUIRED: False,
CONF_RISCO_STATES_TO_HA: DEFAULT_RISCO_STATES_TO_HA,
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/risco/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"title": "Configure options",
"data": {
"scan_interval": "How often to poll Risco (in seconds)",
"concurrency": "Maximum concurrent requests (advanced - only change this if you know what you're doing)",
"code_arm_required": "Require PIN to arm",
"code_disarm_required": "Require PIN to disarm"
}
Expand Down
1 change: 1 addition & 0 deletions tests/components/risco/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

TEST_OPTIONS = {
"scan_interval": 10,
"concurrency": 4,
"code_arm_required": True,
"code_disarm_required": True,
}
Expand Down

0 comments on commit 418239f

Please sign in to comment.