Skip to content

Commit 8481853

Browse files
committed
Add reboot button to NSPanel Pro #1723
1 parent 6c7280a commit 8481853

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

custom_components/sonoff/button.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from homeassistant.components.button import ButtonEntity
1+
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
22
from homeassistant.components.script import ATTR_LAST_TRIGGERED
3+
from homeassistant.const import EntityCategory
34
from homeassistant.helpers.entity import DeviceInfo
45

56
from .core.const import DOMAIN
@@ -47,5 +48,12 @@ async def async_press(self):
4748
class XButton(XEntity, ButtonEntity):
4849
value = None
4950

51+
def __init__(self, ewelink: XRegistry, device: dict):
52+
XEntity.__init__(self, ewelink, device)
53+
54+
if self.params == "reboot":
55+
self._attr_device_class = ButtonDeviceClass.RESTART
56+
self._attr_entity_category = EntityCategory.CONFIG
57+
5058
async def async_press(self):
5159
await self.ewelink.send(self.device, {self.param: self.value})

custom_components/sonoff/core/devices.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
143143
SPEC_2CH = [Switch1, Switch2, LED, RSSI]
144144
SPEC_3CH = [Switch1, Switch2, Switch3, LED, RSSI]
145145
SPEC_4CH = [Switch1, Switch2, Switch3, Switch4, LED, RSSI]
146-
SPEC_NSP = [XTemperatureTH, XPanelAlarm, XPanelBuzzer, XPanelScreen, XCPUTemperature]
146+
147+
SPEC_NSP = [
148+
XTemperatureTH,
149+
XPanelAlarm,
150+
XPanelBuzzer,
151+
XPanelScreen,
152+
XCPUTemperature,
153+
spec(XButton, param="reboot", value=True),
154+
]
147155

148156
Current1 = spec(XSensor100, param="current_00", uid="current_1")
149157
Current2 = spec(XSensor100, param="current_01", uid="current_2")

tests/test_entity.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,3 +2189,9 @@ def test_nspanel():
21892189

21902190
cpu_temp: XSensor = next(e for e in entities if e.uid == "cpu_temperature")
21912191
assert cpu_temp.state == 42.727
2192+
2193+
reboot = next(e for e in entities if e.uid == "reboot")
2194+
2195+
registry: DummyRegistry = reboot.ewelink
2196+
result = registry.call(reboot.async_press())
2197+
assert result[1] == {"reboot": True}

0 commit comments

Comments
 (0)