Skip to content

Commit fb04038

Browse files
authored
Merge pull request #25 from NitorCreations/fixes
Decrease polling interval, fix race condition
2 parents f22dedb + b1621b6 commit fb04038

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Not every single feature can be controlled, only the basics:
2929

3030
The communication is done using Python's `asyncio` and requires no external libraries.
3131

32+
## Caveats
33+
34+
* SSP 200 surround sound processors seem to stop responding properly (both to commands and to physical interactions
35+
like button presses) after some time, requiring a reboot
36+
3237
## Development
3338

3439
Developing the integration and testing it locally in Home Assistant are two separate tasks.

custom_components/extron/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from homeassistant.helpers.device_registry import DeviceInfo, format_mac
1212
from pyextron import AuthenticationError, ExtronDevice
1313

14-
from custom_components.extron.const import OPTION_INPUT_NAMES
14+
from custom_components.extron.const import EXTRON_DEVICE_TIMEOUT_SECONDS, OPTION_INPUT_NAMES
1515

1616
PLATFORMS: list[Platform] = [Platform.MEDIA_PLAYER, Platform.SENSOR, Platform.BUTTON]
1717
_LOGGER = logging.getLogger(__name__)
@@ -56,7 +56,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
5656
"""Set up Extron from a config entry."""
5757
# Verify we can connect to the device
5858
try:
59-
device = ExtronDevice(entry.data["host"], entry.data["port"], entry.data["password"])
59+
device = ExtronDevice(
60+
entry.data["host"], entry.data["port"], entry.data["password"], timeout=EXTRON_DEVICE_TIMEOUT_SECONDS
61+
)
6062
await device.connect()
6163
await device.disconnect()
6264
except AuthenticationError as e:

custom_components/extron/config_flow.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
from homeassistant.helpers.selector import selector
1212
from pyextron import AuthenticationError, DeviceType, ExtronDevice
1313

14-
from .const import CONF_DEVICE_TYPE, CONF_HOST, CONF_PASSWORD, CONF_PORT, DOMAIN, OPTION_INPUT_NAMES
14+
from .const import (
15+
CONF_DEVICE_TYPE,
16+
CONF_HOST,
17+
CONF_PASSWORD,
18+
CONF_PORT,
19+
DOMAIN,
20+
EXTRON_DEVICE_TIMEOUT_SECONDS,
21+
OPTION_INPUT_NAMES,
22+
)
1523

1624
_LOGGER = logging.getLogger(__name__)
1725

@@ -45,7 +53,12 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None):
4553
if user_input is not None:
4654
try:
4755
# Try to connect to the device
48-
extron_device = ExtronDevice(user_input["host"], user_input["port"], user_input["password"])
56+
extron_device = ExtronDevice(
57+
user_input["host"],
58+
user_input["port"],
59+
user_input["password"],
60+
timeout=EXTRON_DEVICE_TIMEOUT_SECONDS,
61+
)
4962
await extron_device.connect()
5063

5164
# Make a title for the entry

custom_components/extron/const.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Constants for the Extron integration."""
22

3+
from datetime import timedelta
4+
35
DOMAIN = "extron"
46

57
CONF_HOST = "host"
@@ -8,3 +10,8 @@
810
CONF_DEVICE_TYPE = "device_type"
911

1012
OPTION_INPUT_NAMES = "input_names"
13+
14+
EXTRON_DEVICE_TIMEOUT_SECONDS = 10
15+
16+
# Poll entities every 30 seconds
17+
SCAN_INTERVAL = timedelta(minutes=30)

custom_components/extron/media_player.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,5 @@ def create_source_bidict(self) -> bidict:
203203
return make_source_bidict(num_sources, self._input_names)
204204

205205
async def async_select_source(self, source: str):
206-
await self._hdmi_switcher.select_input(self._source_bidict.inverse.get(source))
206+
async with self._hdmi_switcher._device.connection():
207+
await self._hdmi_switcher.select_input(self._source_bidict.inverse.get(source))

0 commit comments

Comments
 (0)