Skip to content

Commit 35a1b4c

Browse files
committed
- Remove space in model name for MDX series
- Populate input name for MDX - Add additional command to ignore for MDX
1 parent 6142925 commit 35a1b4c

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

.vscode/settings.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"python.linting.flake8Enabled": true,
2+
"python.formatting.provider": "black",
3+
"editor.formatOnSave": true,
34
"python.linting.enabled": true,
45
"python.testing.pytestArgs": [
56
"tests"
67
],
7-
"python.testing.unittestEnabled": false,
8-
"python.testing.nosetestsEnabled": false,
9-
"python.testing.pytestEnabled": true
8+
"python.testing.unittestEnabled": false,
9+
"python.testing.pytestEnabled": true,
10+
"python.linting.flake8Enabled": true
1011
}

anthemav/protocol.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@
170170

171171
COMMANDS_X20 = ["IDN", "ECH", "SIP", "Z1ARC", "FPB"]
172172
COMMANDS_X40 = ["PVOL", "WMAC", "EMAC", "IS1ARC", "GCFPB", "GCTXS"]
173-
COMMANDS_MDX_IGNORE = ["IDR"]
173+
COMMANDS_MDX_IGNORE = [
174+
"IDR",
175+
"Z1IRH",
176+
"Z1IRV",
177+
"Z1AIC",
178+
"Z1BRT",
179+
"Z1AIN",
180+
"Z1DYN",
181+
"Z1DIA",
182+
"Z1ALM",
183+
]
174184
COMMANDS_MDX = ["MAC"]
175185

176186
EMPTY_MAC = "00:00:00:00:00:00"
@@ -222,6 +232,7 @@ def __init__(
222232
self._last_command = ""
223233
self._deviceinfo_received = asyncio.Event()
224234
self._alm_number = {"None": 0}
235+
self._available_input_numbers = []
225236
self.zones: Dict[int, Zone] = {1: Zone(self, 1)}
226237

227238
for key in LOOKUP:
@@ -276,7 +287,7 @@ async def poweron_refresh(self):
276287
return
277288
else:
278289
await self.refresh_all()
279-
await asyncio.sleep(2)
290+
await asyncio.sleep(5)
280291
await self.poweron_refresh()
281292

282293
async def refresh_all(self):
@@ -291,6 +302,9 @@ async def refresh_all(self):
291302
self.log.debug("refresh_all")
292303
# refresh main attribues
293304
await self.query_commands(LOOKUP)
305+
if self._model_series == "mdx":
306+
# MDX receivers don't returns the list of available input numbers and have a fixed list
307+
self._populate_inputs(12)
294308

295309
async def refresh_power(self):
296310
"""Refresh power of all zones."""
@@ -398,7 +412,11 @@ def _populate_inputs(self, total):
398412
if self._model_series == "x40":
399413
self.query(f"IS{input_number}IN")
400414
else:
401-
self.query(f"ISN{input_number:02d}")
415+
if (
416+
len(self._available_input_numbers) == 0
417+
or input_number in self._available_input_numbers
418+
):
419+
self.query(f"ISN{input_number:02d}")
402420

403421
async def _parse_message(self, data: str):
404422
"""Interpret each message datagram from device and do the needful.
@@ -638,10 +656,12 @@ def set_model_command(self, model: str):
638656
def set_zones(self, model: str):
639657
"""Set zones for the appropriate objects."""
640658
number_of_zones: int = 0
641-
if model == "MDX 16" or model == "MDA 16":
659+
if model == "MDX16" or model == "MDA16":
642660
number_of_zones = 8
643-
elif model == "MDX 8" or model == "MDA 8":
661+
elif model == "MDX8" or model == "MDA8":
644662
number_of_zones = 4
663+
# MDX 16 input number range is 1 to 12, but MDX 8 only have 1 to 4 and 9
664+
self._available_input_numbers = [1, 2, 3, 4, 9]
645665
else:
646666
number_of_zones = 2
647667

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def readme():
1111

1212
setup(
1313
name="anthemav",
14-
version="1.4.0",
14+
version="1.4.0b2",
1515
author="David McNett",
1616
author_email="[email protected]",
1717
url="https://github.com/nugget/python-anthemav",

tests/test_protocol.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,48 @@ async def test_zone_created_x40(self):
8585
async def test_zone_created_MDX8(self):
8686
avr = AVR()
8787
with patch.object(avr, "query"):
88-
await avr._parse_message("IDMMDX 8")
88+
await avr._parse_message("IDMMDX8")
8989
assert len(avr.zones) == 4
9090

9191
async def test_zone_created_MDX16(self):
9292
avr = AVR()
9393
with patch.object(avr, "query"):
94-
await avr._parse_message("IDMMDX 16")
94+
await avr._parse_message("IDMMDX16")
95+
assert len(avr.zones) == 8
96+
97+
async def test_zone_created_MDA16(self):
98+
avr = AVR()
99+
with patch.object(avr, "query"):
100+
await avr._parse_message("IDMMDA16")
95101
assert len(avr.zones) == 8
96102

97103
async def test_power_refreshed_MDX16(self):
98104
avr = AVR()
99105
with patch.object(avr, "query") as mock:
100-
await avr._parse_message("IDMMDX 16")
106+
await avr._parse_message("IDMMDX16")
101107
for zone in range(1, 9):
102108
mock.assert_any_call(f"Z{zone}POW")
103109
assert call("Z9POW") not in mock.mock_calls
104110

111+
async def test_input_name_queried_for_MDX16(self):
112+
avr = AVR()
113+
with patch.object(avr, "query") as mock, patch.object(avr, "transport"):
114+
await avr._parse_message("IDMMDX16")
115+
await avr.refresh_all()
116+
for input_number in range(1, 13):
117+
mock.assert_any_call(f"ISN{input_number:02d}")
118+
119+
async def test_input_name_queried_for_MDX8(self):
120+
avr = AVR()
121+
with patch.object(avr, "query") as mock, patch.object(avr, "transport"):
122+
await avr._parse_message("IDMMDX8")
123+
await avr.refresh_all()
124+
for input_number in range(1, 13):
125+
if input_number in [1, 2, 3, 4, 9]:
126+
mock.assert_any_call(f"ISN{input_number:02d}")
127+
else:
128+
assert call(f"ISN{input_number:02d}") not in mock.mock_calls
129+
105130
async def test_pvol_x40(self):
106131
avr = AVR()
107132
with patch.object(avr, "query"):

0 commit comments

Comments
 (0)