Fix auto_bypass in alarmdecoder (#30961)
* Fix auto_bypass in alarmdecoder * Address review comments: used dict[key] and renamed variable * Use dict[key] for required or optional config keys with default values
This commit is contained in:
parent
0a90b01e77
commit
26415f6abd
2 changed files with 16 additions and 9 deletions
|
@ -118,11 +118,12 @@ def setup(hass, config):
|
|||
conf = config.get(DOMAIN)
|
||||
|
||||
restart = False
|
||||
device = conf.get(CONF_DEVICE)
|
||||
display = conf.get(CONF_PANEL_DISPLAY)
|
||||
device = conf[CONF_DEVICE]
|
||||
display = conf[CONF_PANEL_DISPLAY]
|
||||
auto_bypass = conf[CONF_AUTO_BYPASS]
|
||||
zones = conf.get(CONF_ZONES)
|
||||
|
||||
device_type = device.get(CONF_DEVICE_TYPE)
|
||||
device_type = device[CONF_DEVICE_TYPE]
|
||||
host = DEFAULT_DEVICE_HOST
|
||||
port = DEFAULT_DEVICE_PORT
|
||||
path = DEFAULT_DEVICE_PATH
|
||||
|
@ -204,7 +205,9 @@ def setup(hass, config):
|
|||
|
||||
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_AUTO_BYPASS: auto_bypass}, config
|
||||
)
|
||||
|
||||
if zones:
|
||||
load_platform(hass, "binary_sensor", DOMAIN, {CONF_ZONES: zones}, config)
|
||||
|
|
|
@ -21,7 +21,7 @@ from homeassistant.const import (
|
|||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from . import DATA_AD, DOMAIN, SIGNAL_PANEL_MESSAGE
|
||||
from . import CONF_AUTO_BYPASS, DATA_AD, DOMAIN, SIGNAL_PANEL_MESSAGE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -35,13 +35,17 @@ ALARM_KEYPRESS_SCHEMA = vol.Schema({vol.Required(ATTR_KEYPRESS): cv.string})
|
|||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up for AlarmDecoder alarm panels."""
|
||||
device = AlarmDecoderAlarmPanel(discovery_info["autobypass"])
|
||||
add_entities([device])
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
auto_bypass = discovery_info[CONF_AUTO_BYPASS]
|
||||
entity = AlarmDecoderAlarmPanel(auto_bypass)
|
||||
add_entities([entity])
|
||||
|
||||
def alarm_toggle_chime_handler(service):
|
||||
"""Register toggle chime handler."""
|
||||
code = service.data.get(ATTR_CODE)
|
||||
device.alarm_toggle_chime(code)
|
||||
entity.alarm_toggle_chime(code)
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN,
|
||||
|
@ -53,7 +57,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
def alarm_keypress_handler(service):
|
||||
"""Register keypress handler."""
|
||||
keypress = service.data[ATTR_KEYPRESS]
|
||||
device.alarm_keypress(keypress)
|
||||
entity.alarm_keypress(keypress)
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN,
|
||||
|
|
Loading…
Add table
Reference in a new issue