Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add config option to disable Arm at Home for the alarm panel #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion custom_components/hikvision_axpro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import DATA_COORDINATOR, DOMAIN, USE_CODE_ARMING, INTERNAL_API, ENABLE_DEBUG_OUTPUT, ALLOW_SUBSYSTEMS
from .const import DATA_COORDINATOR, DOMAIN, USE_CODE_ARMING, INTERNAL_API, ENABLE_DEBUG_OUTPUT, ALLOW_SUBSYSTEMS, DISABLE_ARM_HOME
from .model import ZonesResponse, Zone, SubSystemResponse, SubSys, Arming, ZonesConf, ZoneConfig, RelaySwitchConf, OutputStatusFull, RelayStatusSearchResponse, OutputConfList, JSONResponseStatus, ExDevStatusResponse

PLATFORMS: list[Platform] = [Platform.ALARM_CONTROL_PANEL, Platform.SENSOR, Platform.SWITCH]
Expand Down Expand Up @@ -73,6 +73,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
code_format = entry.data[ATTR_CODE_FORMAT]
code = entry.data[CONF_CODE]
use_code_arming = entry.data[USE_CODE_ARMING]
disable_arm_home = entry.data[DISABLE_ARM_HOME]
use_sub_systems = entry.data.get(ALLOW_SUBSYSTEMS, False)
axpro = hikaxpro.HikAxPro(host, username, password)
if entry.data.get(INTERNAL_API):
Expand Down Expand Up @@ -100,6 +101,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
use_code_arming,
code,
update_interval,
disable_arm_home,
use_sub_systems
)
try:
Expand Down Expand Up @@ -154,6 +156,7 @@ def __init__(
use_code_arming,
code,
update_interval: float,
disable_arm_home,
use_sub_systems = False
):
self.axpro = axpro
Expand All @@ -165,6 +168,7 @@ def __init__(
self.code_format = code_format
self.use_code_arming = use_code_arming
self.code = code
self.disable_arm_home = disable_arm_home
self.use_sub_systems = use_sub_systems
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=timedelta(seconds=update_interval))

Expand Down
21 changes: 13 additions & 8 deletions custom_components/hikvision_axpro/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ async def async_setup_entry(

class HikAxProPanel(CoordinatorEntity, AlarmControlPanelEntity):
"""Representation of Hikvision Ax Pro alarm panel."""
def __init__(self, coordinator: HikAxProDataUpdateCoordinator):
if not coordinator.disable_arm_home:
"""if ARM_HOME shouldn't be disabled, add it to the supported features"""
self._attr_supported_features |= AlarmControlPanelEntityFeature.ARM_HOME

super().__init__(coordinator=coordinator)
_attr_code_arm_required = False
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self.async_write_ha_state()

_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
)
_attr_supported_features = (AlarmControlPanelEntityFeature.ARM_AWAY)



@property
def device_info(self) -> DeviceInfo:
Expand Down Expand Up @@ -137,6 +142,9 @@ class HikAxProSubPanel(CoordinatorEntity, AlarmControlPanelEntity):

def __init__(self, coordinator: HikAxProDataUpdateCoordinator, sys: SubSys):
self.sys = sys
if not coordinator.disable_arm_home:
"""if ARM_HOME shouldn't be disabled, add it to the supported features"""
self._attr_supported_features |= AlarmControlPanelEntityFeature.ARM_HOME
super().__init__(coordinator=coordinator)


Expand All @@ -150,10 +158,7 @@ def _handle_coordinator_update(self) -> None:
logging.warning("Area %s was not found", self.sys.id)
self.async_write_ha_state()

_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
)
_attr_supported_features = (AlarmControlPanelEntityFeature.ARM_AWAY)



Expand Down
6 changes: 4 additions & 2 deletions custom_components/hikvision_axpro/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
CONF_HOST,
CONF_USERNAME,
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_SCAN_INTERVAL
)
from homeassistant.components.alarm_control_panel import SCAN_INTERVAL

from .const import DOMAIN, USE_CODE_ARMING, ALLOW_SUBSYSTEMS, INTERNAL_API, ENABLE_DEBUG_OUTPUT
from .const import DOMAIN, USE_CODE_ARMING, ALLOW_SUBSYSTEMS, INTERNAL_API, ENABLE_DEBUG_OUTPUT, DISABLE_ARM_HOME

_LOGGER = logging.getLogger(__name__)

Expand All @@ -36,6 +36,7 @@
vol.Optional(ATTR_CODE_FORMAT, default="NUMBER"): vol.In(["TEXT", "NUMBER"]),
vol.Optional(CONF_CODE, default=""): str,
vol.Optional(USE_CODE_ARMING, default=False): bool,
vol.Optional(DISABLE_ARM_HOME, default=False): bool,
vol.Required(CONF_SCAN_INTERVAL, default=SCAN_INTERVAL.total_seconds()): int,
vol.Optional(ALLOW_SUBSYSTEMS, default=False): bool,
vol.Optional(INTERNAL_API, default=False): bool,
Expand All @@ -53,6 +54,7 @@
vol.Optional(ATTR_CODE_FORMAT, default="NUMBER"): vol.In(["TEXT", "NUMBER"]),
vol.Optional(CONF_CODE, default=""): str,
vol.Optional(USE_CODE_ARMING, default=False): bool,
vol.Optional(DISABLE_ARM_HOME, default=False): bool,
vol.Required(CONF_SCAN_INTERVAL, default=SCAN_INTERVAL.total_seconds()): int,
vol.Optional(ALLOW_SUBSYSTEMS, default=False): bool,
vol.Optional(INTERNAL_API, default=False): bool,
Expand Down
2 changes: 2 additions & 0 deletions custom_components/hikvision_axpro/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

ENABLE_DEBUG_OUTPUT: Final[str] = "debug"

DISABLE_ARM_HOME: Final[str] = "disable_arm_home"


# Sensor entity description constants
ENTITY_DESC_KEY_BATTERY: Final[str] = "battery"
Expand Down
2 changes: 2 additions & 0 deletions custom_components/hikvision_axpro/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"use_code_arming": "[%key:common::config_flow::data::use_code_arming%]",
"code": "[%key:common::config_flow::data::code%]",
"scan_interval": "[%key:common::config_flow::data::scan_interval%]",
"disable_arm_home": "[%key:common::config_flow::data::disable_arm_home%]",
"internal_api": "[%key:common::config_flow::data::internal_api%]"
}
}
Expand Down Expand Up @@ -38,6 +39,7 @@
"use_code_arming": "[%key:common::config_flow::data::use_code_arming%]",
"code": "[%key:common::config_flow::data::code%]",
"scan_interval": "[%key:common::config_flow::data::scan_interval%]",
"disable_arm_home": "[%key:common::config_flow::data::disable_arm_home%]",
"internal_api": "[%key:common::config_flow::data::internal_api%]"
}
}
Expand Down
2 changes: 2 additions & 0 deletions custom_components/hikvision_axpro/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"allow_subsystems": "Include areas as separate zones for arm/disarm",
"code": "Code",
"scan_interval": "Pull interval from system",
"disable_arm_home": "Remove option to arm in Home mode",
"internal_api": "Use internal API lib (AXHub)",
"debug": "Enable debug output"
}
Expand All @@ -42,6 +43,7 @@
"allow_subsystems": "Include areas as separate zones for arm/disarm",
"code": "Code",
"scan_interval": "Pull interval from system",
"disable_arm_home": "Remove option to arm in Home mode",
"internal_api": "DEPRECATED - Use internal API lib (AXHub)",
"debug": "Enable debug output"
}
Expand Down
2 changes: 2 additions & 0 deletions custom_components/hikvision_axpro/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"allow_subsystems": "Includi aree come zone separate per armare/disarmare",
"code": "Codice",
"scan_interval": "Intervallo di scansione del sistema",
"disable_arm_home": "Rimuovi l'opzione per armare in modalità a Casa",
"internal_api": "Usa la libreria API interna (AXHub)",
"debug": "Abilita l'output di debug"
}
Expand All @@ -42,6 +43,7 @@
"allow_subsystems": "Includi aree come zone separate per armare/disarmare",
"code": "Codice",
"scan_interval": "Intervallo di scansione del sistema",
"disable_arm_home": "Rimuovi l'opzione per armare in modalità a Casa",
"internal_api": "OBSOLETA - Usa la libreria API interna (AXHub)",
"debug": "Abilita l'output di debug"
}
Expand Down