Skip to content

Commit d28b121

Browse files
authored
Improve device initialisation for home assistant config flow (#30)
- Improve device initialisation for home assistant config flow - Fix volume for MRX-x40
1 parent becf088 commit d28b121

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# These are supported funding model platforms
22

33
github: nugget
4+
github: hyralex

README.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ Interesting Links
106106

107107
- `Project Home <https://github.com/nugget/python-anthemav>`__
108108
- `API Documentation for Anthem Network
109-
Protocol <http://www.anthemav.com/downloads/MRX-x20-AVM-60-IP-RS-232.xls>`__
110-
(Excel Spreadsheet)
109+
Protocol (Excel Spreadsheet):
110+
for MRX-x20 and AVM-60 <https://www.anthemav.com/downloads/MRX-x20-AVM-60-IP-RS-232.xls>__
111+
for MRX-x40, AVM-70 and AVM-90 <https://www.anthemav.com/downloads/MRX-x40-AVM-70-90-IP-RS-232-v5.xls>`__
111112
- `Pictures of cats <http://imgur.com/r/cats>`__
112113

113114
Credits
@@ -118,6 +119,11 @@ Credits
118119
- https://github.com/nugget
119120
- https://keybase.io/nugget
120121

122+
- This package is maintained by Alex Henry
123+
124+
- https://github.com/hyralex
125+
126+
121127
How can you help?
122128
-----------------
123129

anthemav/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
"""
66
from .connection import Connection # noqa: F401
77
from .protocol import AVR # noqa: F401
8+
from .device_error import DeviceError # noqa: F401

anthemav/device_error.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class DeviceError(Exception):
2+
"""Error triggered when the device couldn't initialised by receiving the basic information"""

anthemav/protocol.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import logging
44
from typing import Awaitable, Callable
55

6+
from anthemav.device_error import DeviceError
7+
68
__all__ = ["AVR"]
79

810
# These properties apply even when the AVR is powered off
@@ -144,6 +146,7 @@
144146
}
145147

146148
# MRX 540, 740, 1140
149+
LOOKUP["Z1PVOL"] = {"description": "Zone 1 Volume"}
147150
LOOKUP["WMAC"] = {"description": "Wi-Fi MAC address"}
148151
LOOKUP["EMAC"] = {"description": "Ethernet MAC address"}
149152
LOOKUP["IS1ARC"] = {"description": "Zone 1 ARC", "0": "Off", "1": "On"}
@@ -156,9 +159,10 @@
156159
}
157160

158161
COMMANDS_X20 = ["IDN", "ECH", "SIP", "Z1ARC", "FPB"]
159-
COMMANDS_X40 = ["WMAC", "EMAC", "IS1ARC", "GCFPB", "GCTXS"]
162+
COMMANDS_X40 = ["Z1PVOL", "WMAC", "EMAC", "IS1ARC", "GCFPB", "GCTXS"]
160163

161164
EMPTY_MAC = "00:00:00:00:00:00"
165+
UNKNOWN_MODEL = "Unknown Model"
162166

163167

164168
# pylint: disable=too-many-instance-attributes, too-many-public-methods
@@ -212,7 +216,14 @@ def __init__(
212216

213217
async def wait_for_device_initialised(self, timeout: float):
214218
"""Wait to receive the model and mac address for the device"""
215-
await asyncio.wait_for(self._deviceinfo_received.wait(), timeout)
219+
try:
220+
await asyncio.wait_for(self._deviceinfo_received.wait(), timeout)
221+
except asyncio.TimeoutError:
222+
raise DeviceError
223+
224+
if self.macaddress == EMPTY_MAC or self.model == UNKNOWN_MODEL:
225+
raise DeviceError
226+
216227
self.log.debug("device is initialised")
217228

218229
def _set_device_initialised(self):
@@ -648,12 +659,18 @@ def volume(self):
648659
>>> volvalue = volume
649660
>>> volume = 20
650661
"""
651-
return self.attenuation_to_volume(self.attenuation)
662+
if self._model_series == "x40" and self._Z1PVOL:
663+
return int(self._Z1PVOL)
664+
else:
665+
return self.attenuation_to_volume(self.attenuation)
652666

653667
@volume.setter
654668
def volume(self, value):
655669
if isinstance(value, int) and 0 <= value <= 100:
656-
self.attenuation = self.volume_to_attenuation(value)
670+
if self._model_series == "x40":
671+
self.command(f"Z1PVOL{value}")
672+
else:
673+
self.attenuation = self.volume_to_attenuation(value)
657674

658675
@property
659676
def volume_as_percentage(self):
@@ -782,7 +799,7 @@ def mute(self, value):
782799
@property
783800
def model(self):
784801
"""Device Model Name (read-only)."""
785-
return self._IDM or "Unknown Model"
802+
return self._IDM or UNKNOWN_MODEL
786803

787804
@property
788805
def swversion(self):

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.3.1",
14+
version="1.3.2",
1515
author="David McNett",
1616
author_email="[email protected]",
1717
url="https://github.com/nugget/python-anthemav",

0 commit comments

Comments
 (0)