mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Reconnect to alarmdecoder on disconnect (#11383)
* Reconnect to alarmdecoder on disconnect * Use track_point_in_time instead of call_later * use alarmdecoder 1.13.2 which has a more robust reconnection fix
This commit is contained in:
parent
3436676de2
commit
6cb02128b4
@ -6,13 +6,15 @@ https://home-assistant.io/components/alarmdecoder/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.helpers.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
REQUIREMENTS = ['alarmdecoder==0.12.3']
|
REQUIREMENTS = ['alarmdecoder==1.13.2']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -88,6 +90,7 @@ def setup(hass, config):
|
|||||||
|
|
||||||
conf = config.get(DOMAIN)
|
conf = config.get(DOMAIN)
|
||||||
|
|
||||||
|
restart = False
|
||||||
device = conf.get(CONF_DEVICE)
|
device = conf.get(CONF_DEVICE)
|
||||||
display = conf.get(CONF_PANEL_DISPLAY)
|
display = conf.get(CONF_PANEL_DISPLAY)
|
||||||
zones = conf.get(CONF_ZONES)
|
zones = conf.get(CONF_ZONES)
|
||||||
@ -101,8 +104,33 @@ def setup(hass, config):
|
|||||||
def stop_alarmdecoder(event):
|
def stop_alarmdecoder(event):
|
||||||
"""Handle the shutdown of AlarmDecoder."""
|
"""Handle the shutdown of AlarmDecoder."""
|
||||||
_LOGGER.debug("Shutting down alarmdecoder")
|
_LOGGER.debug("Shutting down alarmdecoder")
|
||||||
|
nonlocal restart
|
||||||
|
restart = False
|
||||||
controller.close()
|
controller.close()
|
||||||
|
|
||||||
|
def open_connection(now=None):
|
||||||
|
"""Open a connection to AlarmDecoder."""
|
||||||
|
from alarmdecoder.util import NoDeviceError
|
||||||
|
nonlocal restart
|
||||||
|
try:
|
||||||
|
controller.open(baud)
|
||||||
|
except NoDeviceError:
|
||||||
|
_LOGGER.debug("Failed to connect. Retrying in 5 seconds")
|
||||||
|
hass.helpers.event.track_point_in_time(
|
||||||
|
open_connection, dt_util.utcnow() + timedelta(seconds=5))
|
||||||
|
return
|
||||||
|
_LOGGER.debug("Established a connection with the alarmdecoder")
|
||||||
|
restart = True
|
||||||
|
|
||||||
|
def handle_closed_connection(event):
|
||||||
|
"""Restart after unexpected loss of connection."""
|
||||||
|
nonlocal restart
|
||||||
|
if not restart:
|
||||||
|
return
|
||||||
|
restart = False
|
||||||
|
_LOGGER.warning("AlarmDecoder unexpectedly lost connection.")
|
||||||
|
hass.add_job(open_connection)
|
||||||
|
|
||||||
def handle_message(sender, message):
|
def handle_message(sender, message):
|
||||||
"""Handle message from AlarmDecoder."""
|
"""Handle message from AlarmDecoder."""
|
||||||
hass.helpers.dispatcher.dispatcher_send(
|
hass.helpers.dispatcher.dispatcher_send(
|
||||||
@ -140,12 +168,12 @@ def setup(hass, config):
|
|||||||
controller.on_rfx_message += handle_rfx_message
|
controller.on_rfx_message += handle_rfx_message
|
||||||
controller.on_zone_fault += zone_fault_callback
|
controller.on_zone_fault += zone_fault_callback
|
||||||
controller.on_zone_restore += zone_restore_callback
|
controller.on_zone_restore += zone_restore_callback
|
||||||
|
controller.on_close += handle_closed_connection
|
||||||
|
|
||||||
hass.data[DATA_AD] = controller
|
hass.data[DATA_AD] = controller
|
||||||
|
|
||||||
controller.open(baud)
|
open_connection()
|
||||||
|
|
||||||
_LOGGER.debug("Established a connection with the alarmdecoder")
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_alarmdecoder)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_alarmdecoder)
|
||||||
|
|
||||||
load_platform(hass, 'alarm_control_panel', DOMAIN, conf, config)
|
load_platform(hass, 'alarm_control_panel', DOMAIN, conf, config)
|
||||||
|
@ -81,7 +81,7 @@ aiolifx_effects==0.1.2
|
|||||||
aiopvapi==1.5.4
|
aiopvapi==1.5.4
|
||||||
|
|
||||||
# homeassistant.components.alarmdecoder
|
# homeassistant.components.alarmdecoder
|
||||||
alarmdecoder==0.12.3
|
alarmdecoder==1.13.2
|
||||||
|
|
||||||
# homeassistant.components.sensor.alpha_vantage
|
# homeassistant.components.sensor.alpha_vantage
|
||||||
alpha_vantage==1.6.0
|
alpha_vantage==1.6.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user