Skip to content

Commit

Permalink
Add drop down for alarm config flow
Browse files Browse the repository at this point in the history
  • Loading branch information
lawtancool committed Jan 16, 2022
1 parent 28937b4 commit 1400422
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add this repository as a custom repository in HACS to install the integration. O

If you are using an alarm control panel, you must go to Home Assistant -> Configuration -> Devices and Services -> Integrations and click "Configure" on the Control4 entry.

In the dialog that appears, type the English names of the arming modes that your alarm system is capable of into the corresponding fields. For example, a DSC alarm system uses "Stay" as the "Alarm arm home mode name", and "Away" as the "Alarm arm away mode name". If your alarm system does not use one of the mode names, just leave the field blank. Once you click submit on the dialog, Home Assistant will be able to arm your alarm control panel and detect its state.
In the dialog that appears, choose the Control4 alarm arming modes that you want to correspond to each Home Assistant arming mode. For example, a DSC alarm system uses "Stay" as the "Alarm arm home mode name", and "Away" as the "Alarm arm away mode name". If your alarm system does not use one of the mode names, select `(not set)`. Once you click submit on the dialog, Home Assistant will be able to arm your alarm control panel and detect its state.

## Disclaimer

Expand Down
9 changes: 9 additions & 0 deletions custom_components/control4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from .const import (
CONF_ACCOUNT,
CONF_ALARM_ARM_STATES,
CONF_ALARM_AWAY_MODE,
CONF_ALARM_CUSTOM_BYPASS_MODE,
CONF_ALARM_HOME_MODE,
Expand Down Expand Up @@ -105,6 +106,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
CONF_ALARM_VACATION_MODE, DEFAULT_ALARM_VACATION_MODE
)

entry_data[CONF_ALARM_ARM_STATES] = {
DEFAULT_ALARM_AWAY_MODE,
DEFAULT_ALARM_HOME_MODE,
DEFAULT_ALARM_NIGHT_MODE,
DEFAULT_ALARM_CUSTOM_BYPASS_MODE,
DEFAULT_ALARM_VACATION_MODE,
}

entry_data[CONF_CONFIG_LISTENER] = entry.add_update_listener(update_listener)

hass.config_entries.async_setup_platforms(entry, PLATFORMS)
Expand Down
28 changes: 21 additions & 7 deletions custom_components/control4/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@

from . import Control4Entity, get_items_of_category
from .const import (
CONF_ALARM_ARM_STATES,
CONF_ALARM_AWAY_MODE,
CONF_ALARM_CUSTOM_BYPASS_MODE,
CONF_ALARM_HOME_MODE,
CONF_ALARM_NIGHT_MODE,
CONF_ALARM_VACATION_MODE,
CONF_DIRECTOR,
CONTROL4_ENTITY_TYPE,
DEFAULT_ALARM_AWAY_MODE,
DEFAULT_ALARM_CUSTOM_BYPASS_MODE,
DEFAULT_ALARM_HOME_MODE,
DEFAULT_ALARM_NIGHT_MODE,
DEFAULT_ALARM_VACATION_MODE,
DOMAIN,
)
from .director_utils import director_get_entry_variables
Expand Down Expand Up @@ -203,6 +209,10 @@ async def async_setup_entry(
for item in items_of_category:
try:
if item["type"] == CONTROL4_ENTITY_TYPE and item["id"]:
if "capabilities" in item and "arm_states" in item["capabilities"]:
entry_data[CONF_ALARM_ARM_STATES].update(
item["capabilities"]["arm_states"].split(",")
)
item_name = str(item["name"])
item_id = item["id"]
item_area = item["roomName"]
Expand All @@ -223,9 +233,10 @@ async def async_setup_entry(
item_model = parent_item["model"]
else:
continue
except KeyError:
except KeyError as exception:
_LOGGER.warning(
"Unknown device properties received from Control4: %s",
"Unknown device properties received from Control4: %s %s",
exception,
item,
)
continue
Expand Down Expand Up @@ -340,15 +351,18 @@ def code_format(self):
def supported_features(self) -> int:
"""Flag supported features."""
flags = 0
if not self.entry_data[CONF_ALARM_AWAY_MODE] == "":
if not self.entry_data[CONF_ALARM_AWAY_MODE] == DEFAULT_ALARM_AWAY_MODE:
flags |= SUPPORT_ALARM_ARM_AWAY
if not self.entry_data[CONF_ALARM_HOME_MODE] == "":
if not self.entry_data[CONF_ALARM_HOME_MODE] == DEFAULT_ALARM_HOME_MODE:
flags |= SUPPORT_ALARM_ARM_HOME
if not self.entry_data[CONF_ALARM_NIGHT_MODE] == "":
if not self.entry_data[CONF_ALARM_NIGHT_MODE] == DEFAULT_ALARM_NIGHT_MODE:
flags |= SUPPORT_ALARM_ARM_NIGHT
if not self.entry_data[CONF_ALARM_CUSTOM_BYPASS_MODE] == "":
if (
not self.entry_data[CONF_ALARM_CUSTOM_BYPASS_MODE]
== DEFAULT_ALARM_CUSTOM_BYPASS_MODE
):
flags |= SUPPORT_ALARM_ARM_CUSTOM_BYPASS
if not self.entry_data[CONF_ALARM_VACATION_MODE] == "":
if not self.entry_data[CONF_ALARM_VACATION_MODE] == DEFAULT_ALARM_VACATION_MODE:
flags |= SUPPORT_ALARM_ARM_VACATION
return flags

Expand Down
17 changes: 11 additions & 6 deletions custom_components/control4/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from homeassistant.helpers.device_registry import format_mac

from .const import (
CONF_ALARM_ARM_STATES,
CONF_ALARM_AWAY_MODE,
CONF_ALARM_CUSTOM_BYPASS_MODE,
CONF_ALARM_HOME_MODE,
Expand Down Expand Up @@ -186,43 +187,47 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
async def async_step_init(self, user_input=None):
"""Handle options flow."""
if user_input is not None:
_LOGGER.debug(user_input)
return self.async_create_entry(title="", data=user_input)

# TODO: figure out how to accept empty strings to disable modes
# TODO: figure out how to only show alarm options if a alarm_control_panel entity exists
self.entry_data = self.hass.data[DOMAIN][self.config_entry.entry_id]
_LOGGER.debug(self.entry_data[CONF_ALARM_ARM_STATES])
data_schema = vol.Schema(
{
vol.Optional(
CONF_ALARM_AWAY_MODE,
default=self.config_entry.options.get(
CONF_ALARM_AWAY_MODE, DEFAULT_ALARM_AWAY_MODE
),
): str,
): vol.In(self.entry_data[CONF_ALARM_ARM_STATES]),
vol.Optional(
CONF_ALARM_HOME_MODE,
default=self.config_entry.options.get(
CONF_ALARM_HOME_MODE, DEFAULT_ALARM_HOME_MODE
),
): str,
): vol.In(self.entry_data[CONF_ALARM_ARM_STATES]),
vol.Optional(
CONF_ALARM_NIGHT_MODE,
default=self.config_entry.options.get(
CONF_ALARM_NIGHT_MODE, DEFAULT_ALARM_NIGHT_MODE
),
): str,
): vol.In(self.entry_data[CONF_ALARM_ARM_STATES]),
vol.Optional(
CONF_ALARM_CUSTOM_BYPASS_MODE,
default=self.config_entry.options.get(
CONF_ALARM_CUSTOM_BYPASS_MODE, DEFAULT_ALARM_CUSTOM_BYPASS_MODE
),
): str,
): vol.In(self.entry_data[CONF_ALARM_ARM_STATES]),
vol.Optional(
CONF_ALARM_VACATION_MODE,
default=self.config_entry.options.get(
CONF_ALARM_VACATION_MODE, DEFAULT_ALARM_VACATION_MODE
),
): str,
}, required=False
): vol.In(self.entry_data[CONF_ALARM_ARM_STATES]),
},
required=False,
)
return self.async_show_form(step_id="init", data_schema=data_schema)

Expand Down
11 changes: 6 additions & 5 deletions custom_components/control4/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
DOMAIN = "control4"

CONF_ALARM_HOME_MODE = "alarm_home_mode"
DEFAULT_ALARM_HOME_MODE = ""
DEFAULT_ALARM_HOME_MODE = "(not set)"
CONF_ALARM_AWAY_MODE = "alarm_away_mode"
DEFAULT_ALARM_AWAY_MODE = ""
DEFAULT_ALARM_AWAY_MODE = "(not set)"
CONF_ALARM_NIGHT_MODE = "alarm_night_mode"
DEFAULT_ALARM_NIGHT_MODE = ""
DEFAULT_ALARM_NIGHT_MODE = "(not set)"
CONF_ALARM_CUSTOM_BYPASS_MODE = "alarm_custom_bypass_mode"
DEFAULT_ALARM_CUSTOM_BYPASS_MODE = ""
DEFAULT_ALARM_CUSTOM_BYPASS_MODE = "(not set)"
CONF_ALARM_VACATION_MODE = "alarm_vacation_mode"
DEFAULT_ALARM_VACATION_MODE = ""
DEFAULT_ALARM_VACATION_MODE = "(not set)"

CONF_ACCOUNT = "account"
CONF_DIRECTOR = "director"
Expand All @@ -21,6 +21,7 @@
CONF_DIRECTOR_MODEL = "director_model"
CONF_DIRECTOR_ALL_ITEMS = "director_all_items"
CONF_CONTROLLER_UNIQUE_ID = "controller_unique_id"
CONF_ALARM_ARM_STATES = "alarm_arm_states"

CONF_CONFIG_LISTENER = "config_listener"

Expand Down
2 changes: 1 addition & 1 deletion custom_components/control4/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
],
"codeowners": ["@lawtancool"],
"iot_class": "local_push",
"version": "1.1.6",
"version": "1.1.7",
"issue_tracker": "https://github.com/lawtancool/hass-control4/issues"
}

0 comments on commit 1400422

Please sign in to comment.