Skip to content

Commit

Permalink
Use attributes in nx584 alarm (home-assistant#74105)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jun 28, 2022
1 parent dac8f24 commit c1f621e
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions homeassistant/components/nx584/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the NX584 platform."""
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
name: str = config[CONF_NAME]
host: str = config[CONF_HOST]
port: int = config[CONF_PORT]

url = f"http://{host}:{port}"

Expand Down Expand Up @@ -92,33 +92,19 @@ async def async_setup_platform(
class NX584Alarm(alarm.AlarmControlPanelEntity):
"""Representation of a NX584-based alarm panel."""

_attr_code_format = alarm.CodeFormat.NUMBER
_attr_state: str | None
_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
)

def __init__(self, name, alarm_client, url):
def __init__(self, name: str, alarm_client: client.Client, url: str) -> None:
"""Init the nx584 alarm panel."""
self._name = name
self._state = None
self._attr_name = name
self._alarm = alarm_client
self._url = url

@property
def name(self):
"""Return the name of the device."""
return self._name

@property
def code_format(self):
"""Return one or more digits/characters."""
return alarm.CodeFormat.NUMBER

@property
def state(self):
"""Return the state of the device."""
return self._state

def update(self) -> None:
"""Process new events from panel."""
try:
Expand All @@ -129,11 +115,11 @@ def update(self) -> None:
"Unable to connect to %(host)s: %(reason)s",
{"host": self._url, "reason": ex},
)
self._state = None
self._attr_state = None
zones = []
except IndexError:
_LOGGER.error("NX584 reports no partitions")
self._state = None
self._attr_state = None
zones = []

bypassed = False
Expand All @@ -147,15 +133,15 @@ def update(self) -> None:
break

if not part["armed"]:
self._state = STATE_ALARM_DISARMED
self._attr_state = STATE_ALARM_DISARMED
elif bypassed:
self._state = STATE_ALARM_ARMED_HOME
self._attr_state = STATE_ALARM_ARMED_HOME
else:
self._state = STATE_ALARM_ARMED_AWAY
self._attr_state = STATE_ALARM_ARMED_AWAY

for flag in part["condition_flags"]:
if flag == "Siren on":
self._state = STATE_ALARM_TRIGGERED
self._attr_state = STATE_ALARM_TRIGGERED

def alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
Expand All @@ -169,10 +155,10 @@ def alarm_arm_away(self, code: str | None = None) -> None:
"""Send arm away command."""
self._alarm.arm("exit")

def alarm_bypass(self, zone):
def alarm_bypass(self, zone: int) -> None:
"""Send bypass command."""
self._alarm.set_bypass(zone, True)

def alarm_unbypass(self, zone):
def alarm_unbypass(self, zone: int) -> None:
"""Send bypass command."""
self._alarm.set_bypass(zone, False)

0 comments on commit c1f621e

Please sign in to comment.