forked from marthoc/homeseer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.py
57 lines (42 loc) · 1.69 KB
/
switch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Support for HomeSeer switch-type devices.
"""
from .pyhs3.device import GenericDevice, GenericSwitch, GenericSwitchMultilevel
from .hoomseer import HomeseerEntity
from homeassistant.components.switch import SwitchEntity
from .const import DATA_CLIENT, _LOGGER, DOMAIN
DEPENDENCIES = ["homeseer"]
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up HomeSeer switch-type devices."""
switch_devices = []
homeseer = hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id]
for device in homeseer.devices:
if (
issubclass(type(device), GenericSwitch)
and issubclass(type(device), GenericSwitchMultilevel) == False
):
dev = HSSwitch(device, homeseer)
switch_devices.append(dev)
_LOGGER.info(f"Added HomeSeer switch-type device: {dev.name}")
if (
issubclass(type(device), GenericDevice)
and device.device_type_string == "Virtual Switch"
):
dev = HSSwitch(device, homeseer)
switch_devices.append(dev)
_LOGGER.info(
f"Added HomeSeer virtual switch as switch-type device: {dev.name}"
)
async_add_entities(switch_devices)
class HSSwitch(HomeseerEntity, SwitchEntity):
"""Representation of a HomeSeer switch-type device."""
def __init__(self, device, connection):
HomeseerEntity.__init__(self, device, connection)
@property
def is_on(self):
"""Return true if device is on."""
return self._device.is_on
async def async_turn_on(self, **kwargs):
await self._device.on()
async def async_turn_off(self, **kwargs):
await self._device.off()