Skip to content

Commit

Permalink
Enable AlarmDecoder arming without security code (#32390)
Browse files Browse the repository at this point in the history
* set alarmdecoder code_arm_required to False

* rm unnecessary f strings

* add code_arm_required config option

* add self as codeowner :-)

* add self as codeowner the right way
  • Loading branch information
ajschmidt8 authored Mar 16, 2020
1 parent f4b3760 commit 40356b4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ homeassistant/components/abode/* @shred86
homeassistant/components/adguard/* @frenck
homeassistant/components/airly/* @bieniu
homeassistant/components/airvisual/* @bachya
homeassistant/components/alarmdecoder/* @ajschmidt8
homeassistant/components/alexa/* @home-assistant/cloud @ochlocracy
homeassistant/components/almond/* @gcampax @balloob
homeassistant/components/alpha_vantage/* @fabaff
Expand Down
12 changes: 11 additions & 1 deletion homeassistant/components/alarmdecoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CONF_ZONES = "zones"
CONF_RELAY_ADDR = "relayaddr"
CONF_RELAY_CHAN = "relaychan"
CONF_CODE_ARM_REQUIRED = "code_arm_required"

DEFAULT_DEVICE_TYPE = "socket"
DEFAULT_DEVICE_HOST = "localhost"
Expand All @@ -42,6 +43,7 @@

DEFAULT_AUTO_BYPASS = False
DEFAULT_PANEL_DISPLAY = False
DEFAULT_CODE_ARM_REQUIRED = True

DEFAULT_ZONE_TYPE = "opening"

Expand Down Expand Up @@ -105,6 +107,9 @@
CONF_PANEL_DISPLAY, default=DEFAULT_PANEL_DISPLAY
): cv.boolean,
vol.Optional(CONF_AUTO_BYPASS, default=DEFAULT_AUTO_BYPASS): cv.boolean,
vol.Optional(
CONF_CODE_ARM_REQUIRED, default=DEFAULT_CODE_ARM_REQUIRED
): cv.boolean,
vol.Optional(CONF_ZONES): {vol.Coerce(int): ZONE_SCHEMA},
}
)
Expand All @@ -121,6 +126,7 @@ def setup(hass, config):
device = conf[CONF_DEVICE]
display = conf[CONF_PANEL_DISPLAY]
auto_bypass = conf[CONF_AUTO_BYPASS]
code_arm_required = conf[CONF_CODE_ARM_REQUIRED]
zones = conf.get(CONF_ZONES)

device_type = device[CONF_DEVICE_TYPE]
Expand Down Expand Up @@ -206,7 +212,11 @@ def handle_rel_message(sender, message):
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_alarmdecoder)

load_platform(
hass, "alarm_control_panel", DOMAIN, {CONF_AUTO_BYPASS: auto_bypass}, config
hass,
"alarm_control_panel",
DOMAIN,
{CONF_AUTO_BYPASS: auto_bypass, CONF_CODE_ARM_REQUIRED: code_arm_required},
config,
)

if zones:
Expand Down
26 changes: 23 additions & 3 deletions homeassistant/components/alarmdecoder/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
)
import homeassistant.helpers.config_validation as cv

from . import CONF_AUTO_BYPASS, DATA_AD, DOMAIN, SIGNAL_PANEL_MESSAGE
from . import (
CONF_AUTO_BYPASS,
CONF_CODE_ARM_REQUIRED,
DATA_AD,
DOMAIN,
SIGNAL_PANEL_MESSAGE,
)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -39,7 +45,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
return

auto_bypass = discovery_info[CONF_AUTO_BYPASS]
entity = AlarmDecoderAlarmPanel(auto_bypass)
code_arm_required = discovery_info[CONF_CODE_ARM_REQUIRED]
entity = AlarmDecoderAlarmPanel(auto_bypass, code_arm_required)
add_entities([entity])

def alarm_toggle_chime_handler(service):
Expand Down Expand Up @@ -70,7 +77,7 @@ def alarm_keypress_handler(service):
class AlarmDecoderAlarmPanel(AlarmControlPanel):
"""Representation of an AlarmDecoder-based alarm panel."""

def __init__(self, auto_bypass):
def __init__(self, auto_bypass, code_arm_required):
"""Initialize the alarm panel."""
self._display = ""
self._name = "Alarm Panel"
Expand All @@ -85,6 +92,7 @@ def __init__(self, auto_bypass):
self._ready = None
self._zone_bypassed = None
self._auto_bypass = auto_bypass
self._code_arm_required = code_arm_required

async def async_added_to_hass(self):
"""Register callbacks."""
Expand Down Expand Up @@ -140,6 +148,11 @@ def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT

@property
def code_arm_required(self):
"""Whether the code is required for arm actions."""
return self._code_arm_required

@property
def device_state_attributes(self):
"""Return the state attributes."""
Expand All @@ -153,6 +166,7 @@ def device_state_attributes(self):
"programming_mode": self._programming_mode,
"ready": self._ready,
"zone_bypassed": self._zone_bypassed,
"code_arm_required": self._code_arm_required,
}

def alarm_disarm(self, code=None):
Expand All @@ -166,18 +180,24 @@ def alarm_arm_away(self, code=None):
if self._auto_bypass:
self.hass.data[DATA_AD].send(f"{code!s}6#")
self.hass.data[DATA_AD].send(f"{code!s}2")
elif not self._code_arm_required:
self.hass.data[DATA_AD].send("#2")

def alarm_arm_home(self, code=None):
"""Send arm home command."""
if code:
if self._auto_bypass:
self.hass.data[DATA_AD].send(f"{code!s}6#")
self.hass.data[DATA_AD].send(f"{code!s}3")
elif not self._code_arm_required:
self.hass.data[DATA_AD].send("#3")

def alarm_arm_night(self, code=None):
"""Send arm night command."""
if code:
self.hass.data[DATA_AD].send(f"{code!s}7")
elif not self._code_arm_required:
self.hass.data[DATA_AD].send("#7")

def alarm_toggle_chime(self, code=None):
"""Send toggle chime command."""
Expand Down
14 changes: 6 additions & 8 deletions homeassistant/components/alarmdecoder/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"domain": "alarmdecoder",
"name": "AlarmDecoder",
"documentation": "https://www.home-assistant.io/integrations/alarmdecoder",
"requirements": [
"alarmdecoder==1.13.2"
],
"dependencies": [],
"codeowners": []
"domain": "alarmdecoder",
"name": "AlarmDecoder",
"documentation": "https://www.home-assistant.io/integrations/alarmdecoder",
"requirements": ["alarmdecoder==1.13.2"],
"dependencies": [],
"codeowners": ["@ajschmidt8"]
}

0 comments on commit 40356b4

Please sign in to comment.