8000 Migrate esphome alarm_control_panel platform to use _on_static_info_update by bdraco · Pull Request #94961 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate esphome alarm_control_panel platform to use _on_static_info_update #94961

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

Merged
merged 2 commits into from
Jun 26, 2023
Merged
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
49 changes: 22 additions & 27 deletions homeassistant/components/esphome/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
AlarmControlPanelInfo,
AlarmControlPanelState,
APIIntEnum,
EntityInfo,
)

from homeassistant.components.alarm_control_panel import (
Expand All @@ -27,7 +28,7 @@
STATE_ALARM_PENDING,
STATE_ALARM_TRIGGERED,
)
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .entity import (
Expand Down Expand Up @@ -85,14 +86,11 @@ class EsphomeAlarmControlPanel(
):
"""An Alarm Control Panel implementation for ESPHome."""

@property
def state(self) -> str | None:
"""Return the state of the device."""
return _ESPHOME_ACP_STATE_TO_HASS_STATE.from_esphome(self._state.state)

@property
def supported_features(self) -> AlarmControlPanelEntityFeature:
"""Return the list of supported features."""
@callback
def _on_static_info_update(self, static_info: EntityInfo) -> None:
"""Set attrs from static info."""
super()._on_static_info_update(static_info)
static_info = self._static_info
feature = 0
if self._static_info.supported_features & EspHomeACPFeatures.ARM_HOME:
feature |= AlarmControlPanelEntityFeature.ARM_HOME
Expand All @@ -106,58 +104,55 @@ def supported_features(self) -> AlarmControlPanelEntityFeature:
feature |= AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
if self._static_info.supported_features & EspHomeACPFeatures.ARM_VACATION:
feature |= AlarmControlPanelEntityFeature.ARM_VACATION
return AlarmControlPanelEntityFeature(feature)

@property
def code_format(self) -> CodeFormat | None:
"""Return code format for disarm."""
if self._static_info.requires_code:
return CodeFormat.NUMBER
return None
self._attr_supported_features = AlarmControlPanelEntityFeature(feature)
self._attr_code_format = (
CodeFormat.NUMBER if static_info.requires_code else None
)
self._attr_code_arm_required = bool(static_info.requires_code_to_arm)

@property
def code_arm_required(self) -> bool:
"""Whether the code is required for arm actions."""
return bool(self._static_info.requires_code_to_arm)
def state(self) -> str | None:
"""Return the state of the device."""
return _ESPHOME_ACP_STATE_TO_HASS_STATE.from_esphome(self._state.state)

async def async_alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
await self._client.alarm_control_panel_command(
self._static_info.key, AlarmControlPanelCommand.DISARM, code
self._key, AlarmControlPanelCommand.DISARM, code
)

async def async_alarm_arm_home(self, code: str | None = None) -> None:
"""Send arm home command."""
await self._client.alarm_control_panel_command(
self._static_info.key, AlarmControlPanelCommand.ARM_HOME, code
self._key, AlarmControlPanelCommand.ARM_HOME, code
)

async def async_alarm_arm_away(self, code: str | None = None) -> None:
"""Send arm away command."""
await self._client.alarm_control_panel_command(
self._static_info.key, AlarmControlPanelCommand.ARM_AWAY, code
self._key, AlarmControlPanelCommand.ARM_AWAY, code
)

async def async_alarm_arm_night(self, code: str | None = None) -> None:
"""Send arm away command."""
await self._client.alarm_control_panel_command(
self._static_info.key, AlarmControlPanelCommand.ARM_NIGHT, code
self._key, AlarmControlPanelCommand.ARM_NIGHT, code
)

async def async_alarm_arm_custom_bypass(self, code: str | None = None) -> None:
"""Send arm away command."""
await self._client.alarm_control_panel_command(
self._static_info.key, AlarmControlPanelCommand.ARM_CUSTOM_BYPASS, code
self._key, AlarmControlPanelCommand.ARM_CUSTOM_BYPASS, code
)

async def async_alarm_arm_vacation(self, code: str | None = None) -> None:
"""Send arm away command."""
await self._client.alarm_control_panel_command(
self._static_info.key, AlarmControlPanelCommand.ARM_VACATION, code
self._key, AlarmControlPanelCommand.ARM_VACATION, code
)

async def async_alarm_trigger(self, code: str | None = None) -> None:
"""Send alarm trigger command."""
await self._client.alarm_control_panel_command(
self._static_info.key, AlarmControlPanelCommand.TRIGGER, code
self._key, AlarmControlPanelCommand.TRIGGER, code
)
0