Skip to content

Commit

Permalink
Improve device initialisation for home assistant config flow (#30)
Browse files Browse the repository at this point in the history
- Improve device initialisation for home assistant config flow
- Fix volume for MRX-x40
  • Loading branch information
Hyralex authored Jun 1, 2022
1 parent becf088 commit d28b121
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# These are supported funding model platforms

github: nugget
github: hyralex
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ Interesting Links

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

Credits
Expand All @@ -118,6 +119,11 @@ Credits
- https://github.com/nugget
- https://keybase.io/nugget

- This package is maintained by Alex Henry

- https://github.com/hyralex


How can you help?
-----------------

Expand Down
1 change: 1 addition & 0 deletions anthemav/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
"""
from .connection import Connection # noqa: F401
from .protocol import AVR # noqa: F401
from .device_error import DeviceError # noqa: F401
2 changes: 2 additions & 0 deletions anthemav/device_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class DeviceError(Exception):
"""Error triggered when the device couldn't initialised by receiving the basic information"""
27 changes: 22 additions & 5 deletions anthemav/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging
from typing import Awaitable, Callable

from anthemav.device_error import DeviceError

__all__ = ["AVR"]

# These properties apply even when the AVR is powered off
Expand Down Expand Up @@ -144,6 +146,7 @@
}

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

COMMANDS_X20 = ["IDN", "ECH", "SIP", "Z1ARC", "FPB"]
COMMANDS_X40 = ["WMAC", "EMAC", "IS1ARC", "GCFPB", "GCTXS"]
COMMANDS_X40 = ["Z1PVOL", "WMAC", "EMAC", "IS1ARC", "GCFPB", "GCTXS"]

EMPTY_MAC = "00:00:00:00:00:00"
UNKNOWN_MODEL = "Unknown Model"


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

async def wait_for_device_initialised(self, timeout: float):
"""Wait to receive the model and mac address for the device"""
await asyncio.wait_for(self._deviceinfo_received.wait(), timeout)
try:
await asyncio.wait_for(self._deviceinfo_received.wait(), timeout)
except asyncio.TimeoutError:
raise DeviceError

if self.macaddress == EMPTY_MAC or self.model == UNKNOWN_MODEL:
raise DeviceError

self.log.debug("device is initialised")

def _set_device_initialised(self):
Expand Down Expand Up @@ -648,12 +659,18 @@ def volume(self):
>>> volvalue = volume
>>> volume = 20
"""
return self.attenuation_to_volume(self.attenuation)
if self._model_series == "x40" and self._Z1PVOL:
return int(self._Z1PVOL)
else:
return self.attenuation_to_volume(self.attenuation)

@volume.setter
def volume(self, value):
if isinstance(value, int) and 0 <= value <= 100:
self.attenuation = self.volume_to_attenuation(value)
if self._model_series == "x40":
self.command(f"Z1PVOL{value}")
else:
self.attenuation = self.volume_to_attenuation(value)

@property
def volume_as_percentage(self):
Expand Down Expand Up @@ -782,7 +799,7 @@ def mute(self, value):
@property
def model(self):
"""Device Model Name (read-only)."""
return self._IDM or "Unknown Model"
return self._IDM or UNKNOWN_MODEL

@property
def swversion(self):
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.3.1",
version="1.3.2",
author="David McNett",
author_email="[email protected]",
url="https://github.com/nugget/python-anthemav",
Expand Down

0 comments on commit d28b121

Please sign in to comment.