Broadlink fix (#5065)
* Broadlink fix * style fix * style fix * typo * restructure * Update broadlink.py * Update broadlink.py * Add support for more devices * fix library version * fix library version * fix library version * fix library version * fix library version * Update broadlink.py * lib version * remove lower * remove lower * refactor * refactor * refactor * authorization * authorization * refactor * lib version * lib version
This commit is contained in:
1 parent
e17ce4f374
commit
ebfb2c9b26
3 files changed
+69
-49
No files matched your search
@@ -19,7 +19,7 @@ from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['broadlink==0.2']
|
||||
REQUIREMENTS = ['broadlink==0.3']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -111,9 +111,7 @@ class BroadlinkData(object):
|
||||
self._device = broadlink.a1((ip_addr, 80), mac_addr)
|
||||
self._device.timeout = timeout
|
||||
self.update = Throttle(interval)(self._update)
|
||||
try:
|
||||
self._device.auth()
|
||||
except socket.timeout:
|
||||
if not self._auth():
|
||||
_LOGGER.error("Failed to connect to device.")
|
||||
|
||||
def _update(self, retry=2):
|
||||
@@ -123,8 +121,15 @@ class BroadlinkData(object):
|
||||
if retry < 1:
|
||||
_LOGGER.error(error)
|
||||
return
|
||||
try:
|
||||
self._device.auth()
|
||||
except socket.timeout:
|
||||
pass
|
||||
if not self._auth():
|
||||
return
|
||||
return self._update(max(0, retry-1))
|
||||
|
||||
def _auth(self, retry=2):
|
||||
try:
|
||||
auth = self._device.auth()
|
||||
except socket.timeout:
|
||||
auth = False
|
||||
if not auth and retry > 0:
|
||||
return self._auth(max(0, retry-1))
|
||||
return auth
|
||||
Reference in new issue
Block a user