Skip to content

Commit 7dc36ec

Browse files
committed
Add AlarmControlPanel to NSPanel Pro #1648
1 parent a3a4c95 commit 7dc36ec

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

custom_components/sonoff/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
_LOGGER = logging.getLogger(__name__)
4444

4545
PLATFORMS = [
46+
"alarm_control_panel",
4647
"binary_sensor",
4748
"button",
4849
"climate",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from homeassistant.components.alarm_control_panel import (
2+
AlarmControlPanelEntity,
3+
AlarmControlPanelEntityFeature,
4+
AlarmControlPanelState,
5+
)
6+
7+
from .core.const import DOMAIN
8+
from .core.entity import XEntity
9+
from .core.ewelink import SIGNAL_ADD_ENTITIES, XRegistry
10+
11+
PARALLEL_UPDATES = 0 # fix entity_platform parallel_updates Semaphore
12+
13+
14+
async def async_setup_entry(hass, config_entry, add_entities):
15+
ewelink: XRegistry = hass.data[DOMAIN][config_entry.entry_id]
16+
ewelink.dispatcher_connect(
17+
SIGNAL_ADD_ENTITIES,
18+
lambda x: add_entities(
19+
[e for e in x if isinstance(e, AlarmControlPanelEntity)]
20+
),
21+
)
22+
23+
24+
STATES = {
25+
0: AlarmControlPanelState.DISARMED,
26+
1: AlarmControlPanelState.ARMED_HOME,
27+
2: AlarmControlPanelState.ARMED_AWAY,
28+
3: AlarmControlPanelState.ARMED_NIGHT,
29+
}
30+
31+
32+
class XAlarmPanel(XEntity, AlarmControlPanelEntity):
33+
param = "securityType"
34+
uid = "alarm"
35+
36+
_attr_code_arm_required = False
37+
_attr_supported_features = (
38+
AlarmControlPanelEntityFeature.ARM_HOME
39+
| AlarmControlPanelEntityFeature.ARM_AWAY
40+
| AlarmControlPanelEntityFeature.ARM_NIGHT
41+
)
42+
43+
def set_state(self, params: dict):
44+
if self.param in params:
45+
self._attr_alarm_state = STATES.get(params[self.param])
46+
47+
async def async_alarm_disarm(self, code=None):
48+
await self.ewelink.send(self.device, {self.param: 0})
49+
50+
async def async_alarm_arm_home(self, code=None):
51+
await self.ewelink.send(self.device, {self.param: 1, "currentType": 1})
52+
53+
async def async_alarm_arm_away(self, code=None):
54+
await self.ewelink.send(self.device, {self.param: 2, "currentType": 2})
55+
56+
async def async_alarm_arm_night(self, code=None):
57+
await self.ewelink.send(self.device, {self.param: 3, "currentType": 3})

custom_components/sonoff/core/devices.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from homeassistant.components.switch import SwitchEntity
1919

2020
from .ewelink import XDevice
21+
from ..alarm_control_panel import XAlarmPanel
2122
from ..binary_sensor import (
2223
XBinarySensor,
2324
XHumanSensor,
@@ -439,7 +440,7 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
439440
),
440441
],
441442
# NSPanel Pro, https://github.com/AlexxIT/SonoffLAN/issues/984
442-
195: [XTemperatureTH],
443+
195: [XTemperatureTH, XAlarmPanel],
443444
# Sonoff TX ULTIMATE T5-1C-86, https://github.com/AlexxIT/SonoffLAN/issues/1183
444445
209: [Switch1, Startup1, XT5Light, XT5Action, XT5Alarm, XT5Bell],
445446
# Sonoff TX ULTIMATE T5-2C-86

0 commit comments

Comments
 (0)