mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Broadlink Sensor - switch to connection-less mode (#13761)
* Broadlink Sensor - switch to connection-less mode Solved the issue with broadlink sensor that occurs when short connection loss with RM2/3 is present on poor WiFi networks. * Update broadlink.py * Update broadlink.py * Update broadlink.py * Update broadlink.py * Update broadlink.py * Update broadlink.py * Update broadlink.py
This commit is contained in:
parent
86709427b6
commit
ad212d8dd4
@ -56,9 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
timeout = config.get(CONF_TIMEOUT)
|
timeout = config.get(CONF_TIMEOUT)
|
||||||
update_interval = config.get(CONF_UPDATE_INTERVAL)
|
update_interval = config.get(CONF_UPDATE_INTERVAL)
|
||||||
|
|
||||||
broadlink_data = BroadlinkData(update_interval, host, mac_addr, timeout)
|
broadlink_data = BroadlinkData(update_interval, host, mac_addr, timeout)
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for variable in config[CONF_MONITORED_CONDITIONS]:
|
for variable in config[CONF_MONITORED_CONDITIONS]:
|
||||||
dev.append(BroadlinkSensor(name, broadlink_data, variable))
|
dev.append(BroadlinkSensor(name, broadlink_data, variable))
|
||||||
@ -104,10 +102,11 @@ class BroadlinkData(object):
|
|||||||
|
|
||||||
def __init__(self, interval, ip_addr, mac_addr, timeout):
|
def __init__(self, interval, ip_addr, mac_addr, timeout):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
import broadlink
|
|
||||||
self.data = None
|
self.data = None
|
||||||
self._device = broadlink.a1((ip_addr, 80), mac_addr, None)
|
self.ip_addr = ip_addr
|
||||||
self._device.timeout = timeout
|
self.mac_addr = mac_addr
|
||||||
|
self.timeout = timeout
|
||||||
|
self._connect()
|
||||||
self._schema = vol.Schema({
|
self._schema = vol.Schema({
|
||||||
vol.Optional('temperature'): vol.Range(min=-50, max=150),
|
vol.Optional('temperature'): vol.Range(min=-50, max=150),
|
||||||
vol.Optional('humidity'): vol.Range(min=0, max=100),
|
vol.Optional('humidity'): vol.Range(min=0, max=100),
|
||||||
@ -119,6 +118,11 @@ class BroadlinkData(object):
|
|||||||
if not self._auth():
|
if not self._auth():
|
||||||
_LOGGER.warning("Failed to connect to device")
|
_LOGGER.warning("Failed to connect to device")
|
||||||
|
|
||||||
|
def _connect(self):
|
||||||
|
import broadlink
|
||||||
|
self._device = broadlink.a1((self.ip_addr, 80), self.mac_addr, None)
|
||||||
|
self._device.timeout = self.timeout
|
||||||
|
|
||||||
def _update(self, retry=3):
|
def _update(self, retry=3):
|
||||||
try:
|
try:
|
||||||
data = self._device.check_sensors_raw()
|
data = self._device.check_sensors_raw()
|
||||||
@ -140,5 +144,6 @@ class BroadlinkData(object):
|
|||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
auth = False
|
auth = False
|
||||||
if not auth and retry > 0:
|
if not auth and retry > 0:
|
||||||
|
self._connect()
|
||||||
return self._auth(retry-1)
|
return self._auth(retry-1)
|
||||||
return auth
|
return auth
|
||||||
|
Loading…
x
Reference in New Issue
Block a user