1
1
"""Support for Vivint buttons."""
2
+
2
3
from __future__ import annotations
3
4
4
5
from vivintpy .devices .alarm_panel import AlarmPanel
6
+ from vivintpy .devices .camera import Camera as VivintCamera
5
7
from vivintpy .entity import UPDATE
8
+ from vivintpy .enums import (
9
+ CapabilityCategoryType as Category ,
10
+ CapabilityType as Capability ,
11
+ )
6
12
7
13
from homeassistant .components .button import (
8
14
ButtonDeviceClass ,
14
20
from homeassistant .helpers .entity_platform import AddEntitiesCallback
15
21
16
22
from .const import DOMAIN
17
- from .hub import VivintBaseEntity , VivintHub
23
+ from .hub import VivintBaseEntity , VivintHub , has_capability
18
24
19
- HUB_REBOOT_ENTITY = ButtonEntityDescription (
25
+ REBOOT_ENTITY = ButtonEntityDescription (
20
26
key = "reboot" , device_class = ButtonDeviceClass .RESTART
21
27
)
22
28
@@ -30,24 +36,36 @@ async def async_setup_entry(
30
36
hub : VivintHub = hass .data [DOMAIN ][entry .entry_id ]
31
37
entities = [
32
38
VivintButtonEntity (
33
- device = alarm_panel , hub = hub , entity_description = HUB_REBOOT_ENTITY
39
+ device = alarm_panel , hub = hub , entity_description = REBOOT_ENTITY
34
40
)
35
41
for system in hub .account .systems
36
42
if system .is_admin
37
43
for alarm_panel in system .alarm_panels
38
44
]
45
+ entities .extend (
46
+ VivintButtonEntity (device = device , hub = hub , entity_description = REBOOT_ENTITY )
47
+ for system in hub .account .systems
48
+ for alarm_panel in system .alarm_panels
49
+ for device in alarm_panel .devices
50
+ if isinstance (device , VivintCamera )
51
+ and has_capability (device , Category .CAMERA , Capability .REBOOT_CAMERA )
52
+ )
39
53
async_add_entities (entities )
40
54
41
55
42
56
class VivintButtonEntity (VivintBaseEntity , ButtonEntity ):
43
57
"""A class that describes device button entities."""
44
58
45
- device : AlarmPanel
59
+ device : AlarmPanel | VivintCamera
46
60
47
61
@property
48
62
def available (self ) -> bool :
49
63
"""Return if entity is available."""
50
- return super ().available and self .device ._AlarmPanel__panel .data ["can_reboot" ]
64
+ if isinstance (self .device , AlarmPanel ):
65
+ return (
66
+ super ().available and self .device ._AlarmPanel__panel .data ["can_reboot" ]
67
+ )
68
+ return super ().available
51
69
52
70
async def async_press (self ) -> None :
53
71
"""Handle the button press."""
@@ -56,8 +74,9 @@ async def async_press(self) -> None:
56
74
async def async_added_to_hass (self ) -> None :
57
75
"""Set up a listener for the entity."""
58
76
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 ()
77
+ if isinstance (self .device , AlarmPanel ):
78
+ self .async_on_remove (
79
+ self .device ._AlarmPanel__panel .on (
80
+ UPDATE , lambda _ : self .async_write_ha_state ()
81
+ )
62
82
)
63
- )
0 commit comments