Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom_components/crestron/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"iTunes": "ITUNES",
}

POLL_INTERVAL_SECONDS = 15
POLL_INTERVAL_SECONDS = 30
REBOOT_COOLDOWN_SECONDS = 180
COMMAND_TIMEOUT_SECONDS = 5.0
COMMAND_TIMEOUT_SECONDS = 2.0
CONNECT_TIMEOUT_SECONDS = 5.0
15 changes: 8 additions & 7 deletions custom_components/crestron/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ async def _async_poll(self) -> dict[str, dict[str, Any]]:
power = await self.request(f"{zone} POWER")
if power is not None:
zone_state["power"] = power
volume_line = await self.request(f"{zone} VOLUME CHECK")
if volume_line:
with contextlib.suppress(ValueError):
zone_state["volume"] = int(volume_line.split()[-1])
source_line = await self.request(f"{zone} SOURCE")
if source_line:
zone_state["source"] = source_line.split()[-1]
if power and power.upper().endswith("ON"):
volume_line = await self.request(f"{zone} VOLUME CHECK")
if volume_line:
with contextlib.suppress(ValueError):
zone_state["volume"] = int(volume_line.split()[-1])
source_line = await self.request(f"{zone} SOURCE")
if source_line:
zone_state["source"] = source_line.split()[-1]
except ConnectionError as exc:
had_error = True
_LOGGER.debug("Poll failed for zone %s: %s", zone, exc)
Expand Down
16 changes: 9 additions & 7 deletions tests/test_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ async def test_poll_collects_state_for_all_zones(
) -> None:
entry = _make_entry(["KITCHEN", "DECK"])
entry.add_to_hass(hass)
# DECK is off, so only POWER is queried for it — no VOLUME/SOURCE lines.
open_stub.enqueue(
2000,
[
"KITCHEN POWER ON\r\n",
"KITCHEN VOLUME CURRENT 40\r\n",
"KITCHEN SOURCE CHROMECAST\r\n",
"DECK POWER OFF\r\n",
"DECK VOLUME CURRENT 0\r\n",
"DECK SOURCE ITUNES\r\n",
],
)

Expand All @@ -240,8 +239,11 @@ async def test_poll_collects_state_for_all_zones(
"volume": 40,
"source": "CHROMECAST",
}
assert data["DECK"] == {
"power": "DECK POWER OFF",
"volume": 0,
"source": "ITUNES",
}
assert data["DECK"] == {"power": "DECK POWER OFF"}
# Only 4 lines consumed (3 KITCHEN + 1 DECK POWER); VOLUME/SOURCE skipped for OFF zone.
assert open_stub.writers[0].writes == [
"KITCHEN POWER\r\n",
"KITCHEN VOLUME CHECK\r\n",
"KITCHEN SOURCE\r\n",
"DECK POWER\r\n",
]
Loading