Skip to content

Commit 84ce823

Browse files
authored
Merge pull request #126 from natekspencer/dev
Add restart button
2 parents 4677783 + ac2d8f3 commit 84ce823

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

custom_components/vivint/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
PLATFORMS = [
3030
Platform.ALARM_CONTROL_PANEL,
3131
Platform.BINARY_SENSOR,
32+
Platform.BUTTON,
3233
Platform.CAMERA,
3334
Platform.CLIMATE,
3435
Platform.COVER,
@@ -110,7 +111,7 @@ def async_on_device_event(event_type: str, viv_device: VivintDevice) -> None:
110111
),
111112
)
112113
)
113-
if CapabilityCategoryType.DOORBELL in device.capabilities.keys():
114+
if CapabilityCategoryType.DOORBELL in device.capabilities:
114115
entry.async_on_unload(
115116
device.on(
116117
DOORBELL_DING,

custom_components/vivint/button.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""Support for Vivint buttons."""
2+
from __future__ import annotations
3+
4+
from vivintpy.devices.alarm_panel import AlarmPanel
5+
from vivintpy.entity import UPDATE
6+
7+
from homeassistant.components.button import (
8+
ButtonDeviceClass,
9+
ButtonEntity,
10+
ButtonEntityDescription,
11+
)
12+
from homeassistant.config_entries import ConfigEntry
13+
from homeassistant.core import HomeAssistant
14+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
15+
16+
from .const import DOMAIN
17+
from .hub import VivintBaseEntity, VivintHub
18+
19+
HUB_REBOOT_ENTITY = ButtonEntityDescription(
20+
key="reboot", device_class=ButtonDeviceClass.RESTART
21+
)
22+
23+
24+
async def async_setup_entry(
25+
hass: HomeAssistant,
26+
entry: ConfigEntry,
27+
async_add_entities: AddEntitiesCallback,
28+
) -> None:
29+
"""Set up Vivint button platform."""
30+
hub: VivintHub = hass.data[DOMAIN][entry.entry_id]
31+
entities = [
32+
VivintButtonEntity(
33+
device=alarm_panel, hub=hub, entity_description=HUB_REBOOT_ENTITY
34+
)
35+
for system in hub.account.systems
36+
if system.is_admin
37+
for alarm_panel in system.alarm_panels
38+
]
39+
async_add_entities(entities)
40+
41+
42+
class VivintButtonEntity(VivintBaseEntity, ButtonEntity):
43+
"""A class that describes device button entities."""
44+
45+
device: AlarmPanel
46+
47+
@property
48+
def available(self) -> bool:
49+
"""Return if entity is available."""
50+
return super().available and self.device._AlarmPanel__panel.data["can_reboot"]
51+
52+
async def async_press(self) -> None:
53+
"""Handle the button press."""
54+
await self.device.reboot()
55+
56+
async def async_added_to_hass(self) -> None:
57+
"""Set up a listener for the entity."""
58+
await super().async_added_to_hass()
59+
self.async_on_remove(
60+
self.device._AlarmPanel__panel.on(
61+
UPDATE, lambda _: self.async_write_ha_state()
62+
)
63+
)

custom_components/vivint/update.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ class VivintUpdateEntity(VivintBaseEntity, UpdateEntity):
5656
@property
5757
def in_progress(self) -> bool:
5858
"""Update installation progress."""
59-
return self.device._AlarmPanel__panel.data["sus"] != "Idle"
59+
return self.device._AlarmPanel__panel.data["sus"] not in (
60+
"Idle",
61+
"Reboot Pending",
62+
)
6063

6164
@property
6265
def installed_version(self) -> str:

0 commit comments

Comments
 (0)