From dbab3fd1fec981635fe4b1ea61774b1d3a603c69 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 26 Dec 2019 13:33:25 -0500 Subject: [PATCH] Do not crash on failed speaker volume retrieval Fixes #63. --- wideq/ac.py | 8 ++++++-- wideq/core.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/wideq/ac.py b/wideq/ac.py index e6a2c7e..c2c8848 100644 --- a/wideq/ac.py +++ b/wideq/ac.py @@ -3,6 +3,7 @@ import enum from .client import Device +from .core import FailedRequestError class ACVSwingMode(enum.Enum): @@ -256,8 +257,11 @@ class ACDevice(Device): def get_volume(self): """Get the speaker volume level.""" - value = self._get_control('SpkVolume') - return int(value) + try: + value = self._get_control('SpkVolume') + return int(value) + except FailedRequestError: + return 0 # Device does not support volume control. def poll(self): """Poll the device's current state. diff --git a/wideq/core.py b/wideq/core.py index ef8927e..df31a2c 100644 --- a/wideq/core.py +++ b/wideq/core.py @@ -85,6 +85,15 @@ class TokenError(APIError): pass +class FailedRequestError(APIError): + """A failed request typically indicates an unsupported control on a + device. + """ + + def __init__(self): + pass + + class InvalidRequestError(APIError): """The server rejected a request as invalid.""" @@ -105,6 +114,7 @@ class MonitorError(APIError): API_ERRORS = { "0102": NotLoggedInError, "0106": NotConnectedError, + "0100": FailedRequestError, 9000: InvalidRequestError, # Surprisingly, an integer (not a string). }