mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Only auth on enter_learning in response to errors for broadlink (#27341)
* Only auth on enter_learning in response to errors. * Remove extra newline. * Add missing break on successful attempt. * Avoid logging success message when auth is unsuccessful.
This commit is contained in:
parent
e3894d212c
commit
9f58e5d6ea
@ -75,18 +75,20 @@ def async_setup_service(hass, host, device):
|
||||
|
||||
async def _learn_command(call):
|
||||
"""Learn a packet from remote."""
|
||||
|
||||
device = hass.data[DOMAIN][call.data[CONF_HOST]]
|
||||
|
||||
try:
|
||||
auth = await hass.async_add_executor_job(device.auth)
|
||||
except socket.timeout:
|
||||
_LOGGER.error("Failed to connect to device, timeout")
|
||||
return
|
||||
if not auth:
|
||||
_LOGGER.error("Failed to connect to device")
|
||||
return
|
||||
|
||||
await hass.async_add_executor_job(device.enter_learning)
|
||||
for retry in range(DEFAULT_RETRY):
|
||||
try:
|
||||
await hass.async_add_executor_job(device.enter_learning)
|
||||
break
|
||||
except (socket.timeout, ValueError):
|
||||
try:
|
||||
await hass.async_add_executor_job(device.auth)
|
||||
except socket.timeout:
|
||||
if retry == DEFAULT_RETRY - 1:
|
||||
_LOGGER.error("Failed to enter learning mode")
|
||||
return
|
||||
|
||||
_LOGGER.info("Press the key you want Home Assistant to learn")
|
||||
start_time = utcnow()
|
||||
|
Loading…
x
Reference in New Issue
Block a user