mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-17 07:40:09 -07:00
Merge branch 'feature/refrigerator' of https://github.com/NorDroN/wideq into feature/refrigerator
# Conflicts: # wideq/ac.py
This commit is contained in:
commit
cfd27c0100
@ -4,6 +4,7 @@ import enum
|
||||
|
||||
from .client import Device
|
||||
from .util import lookup_enum
|
||||
from .core import FailedRequestError
|
||||
|
||||
|
||||
class ACVSwingMode(enum.Enum):
|
||||
@ -257,8 +258,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.
|
||||
|
@ -67,16 +67,10 @@ class APIError(Exception):
|
||||
class NotLoggedInError(APIError):
|
||||
"""The session is not valid or expired."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class NotConnectedError(APIError):
|
||||
"""The service can't contact the specified device."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class TokenError(APIError):
|
||||
"""An authentication token was rejected."""
|
||||
@ -85,6 +79,16 @@ class TokenError(APIError):
|
||||
pass
|
||||
|
||||
|
||||
class FailedRequestError(APIError):
|
||||
"""A failed request typically indicates an unsupported control on a
|
||||
device.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidRequestError(APIError):
|
||||
"""The server rejected a request as invalid."""
|
||||
|
||||
|
||||
class MonitorError(APIError):
|
||||
"""Monitoring a device failed, possibly because the monitoring
|
||||
session failed and needs to be restarted.
|
||||
@ -95,6 +99,14 @@ class MonitorError(APIError):
|
||||
self.code = code
|
||||
|
||||
|
||||
API_ERRORS = {
|
||||
"0102": NotLoggedInError,
|
||||
"0106": NotConnectedError,
|
||||
"0100": FailedRequestError,
|
||||
9000: InvalidRequestError, # Surprisingly, an integer (not a string).
|
||||
}
|
||||
|
||||
|
||||
def lgedm_post(url, data=None, access_token=None, session_id=None):
|
||||
"""Make an HTTP request in the format used by the API servers.
|
||||
|
||||
@ -125,10 +137,8 @@ def lgedm_post(url, data=None, access_token=None, session_id=None):
|
||||
code = out['returnCd']
|
||||
if code != '0000':
|
||||
message = out['returnMsg']
|
||||
if code == "0102":
|
||||
raise NotLoggedInError()
|
||||
elif code == "0106":
|
||||
raise NotConnectedError()
|
||||
if code in API_ERRORS:
|
||||
raise API_ERRORS[code](code, message)
|
||||
else:
|
||||
raise APIError(code, message)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user