Skip to content

Commit

Permalink
- Remove space in model name for MDX series
Browse files Browse the repository at this point in the history
- Populate input name for MDX
- Add additional command to ignore for MDX
  • Loading branch information
Hyralex committed Jun 7, 2022
1 parent 6142925 commit 35a1b4c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
9 changes: 5 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"python.linting.enabled": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.flake8Enabled": true
}
30 changes: 25 additions & 5 deletions anthemav/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@

COMMANDS_X20 = ["IDN", "ECH", "SIP", "Z1ARC", "FPB"]
COMMANDS_X40 = ["PVOL", "WMAC", "EMAC", "IS1ARC", "GCFPB", "GCTXS"]
COMMANDS_MDX_IGNORE = ["IDR"]
COMMANDS_MDX_IGNORE = [
"IDR",
"Z1IRH",
"Z1IRV",
"Z1AIC",
"Z1BRT",
"Z1AIN",
"Z1DYN",
"Z1DIA",
"Z1ALM",
]
COMMANDS_MDX = ["MAC"]

EMPTY_MAC = "00:00:00:00:00:00"
Expand Down Expand Up @@ -222,6 +232,7 @@ def __init__(
self._last_command = ""
self._deviceinfo_received = asyncio.Event()
self._alm_number = {"None": 0}
self._available_input_numbers = []
self.zones: Dict[int, Zone] = {1: Zone(self, 1)}

for key in LOOKUP:
Expand Down Expand Up @@ -276,7 +287,7 @@ async def poweron_refresh(self):
return
else:
await self.refresh_all()
await asyncio.sleep(2)
await asyncio.sleep(5)
await self.poweron_refresh()

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

async def refresh_power(self):
"""Refresh power of all zones."""
Expand Down Expand Up @@ -398,7 +412,11 @@ def _populate_inputs(self, total):
if self._model_series == "x40":
self.query(f"IS{input_number}IN")
else:
self.query(f"ISN{input_number:02d}")
if (
len(self._available_input_numbers) == 0
or input_number in self._available_input_numbers
):
self.query(f"ISN{input_number:02d}")

async def _parse_message(self, data: str):
"""Interpret each message datagram from device and do the needful.
Expand Down Expand Up @@ -638,10 +656,12 @@ def set_model_command(self, model: str):
def set_zones(self, model: str):
"""Set zones for the appropriate objects."""
number_of_zones: int = 0
if model == "MDX 16" or model == "MDA 16":
if model == "MDX16" or model == "MDA16":
number_of_zones = 8
elif model == "MDX 8" or model == "MDA 8":
elif model == "MDX8" or model == "MDA8":
number_of_zones = 4
# MDX 16 input number range is 1 to 12, but MDX 8 only have 1 to 4 and 9
self._available_input_numbers = [1, 2, 3, 4, 9]
else:
number_of_zones = 2

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def readme():

setup(
name="anthemav",
version="1.4.0",
version="1.4.0b2",
author="David McNett",
author_email="[email protected]",
url="https://github.com/nugget/python-anthemav",
Expand Down
31 changes: 28 additions & 3 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,48 @@ async def test_zone_created_x40(self):
async def test_zone_created_MDX8(self):
avr = AVR()
with patch.object(avr, "query"):
await avr._parse_message("IDMMDX 8")
await avr._parse_message("IDMMDX8")
assert len(avr.zones) == 4

async def test_zone_created_MDX16(self):
avr = AVR()
with patch.object(avr, "query"):
await avr._parse_message("IDMMDX 16")
await avr._parse_message("IDMMDX16")
assert len(avr.zones) == 8

async def test_zone_created_MDA16(self):
avr = AVR()
with patch.object(avr, "query"):
await avr._parse_message("IDMMDA16")
assert len(avr.zones) == 8

async def test_power_refreshed_MDX16(self):
avr = AVR()
with patch.object(avr, "query") as mock:
await avr._parse_message("IDMMDX 16")
await avr._parse_message("IDMMDX16")
for zone in range(1, 9):
mock.assert_any_call(f"Z{zone}POW")
assert call("Z9POW") not in mock.mock_calls

async def test_input_name_queried_for_MDX16(self):
avr = AVR()
with patch.object(avr, "query") as mock, patch.object(avr, "transport"):
await avr._parse_message("IDMMDX16")
await avr.refresh_all()
for input_number in range(1, 13):
mock.assert_any_call(f"ISN{input_number:02d}")

async def test_input_name_queried_for_MDX8(self):
avr = AVR()
with patch.object(avr, "query") as mock, patch.object(avr, "transport"):
await avr._parse_message("IDMMDX8")
await avr.refresh_all()
for input_number in range(1, 13):
if input_number in [1, 2, 3, 4, 9]:
mock.assert_any_call(f"ISN{input_number:02d}")
else:
assert call(f"ISN{input_number:02d}") not in mock.mock_calls

async def test_pvol_x40(self):
avr = AVR()
with patch.object(avr, "query"):
Expand Down

0 comments on commit 35a1b4c

Please sign in to comment.