-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
89 lines (69 loc) · 2.56 KB
/
common.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Common utilities for VeSync Component."""
import logging
from homeassistant.helpers.entity import ToggleEntity
from .const import VS_FANS, VS_HUMIDIFIERS, VS_LIGHTS, VS_SWITCHES
_LOGGER = logging.getLogger(__name__)
async def async_process_devices(hass, manager):
"""Assign devices to proper component."""
devices = {}
devices[VS_SWITCHES] = []
devices[VS_FANS] = []
devices[VS_LIGHTS] = []
devices[VS_HUMIDIFIERS] = []
await hass.async_add_executor_job(manager.update)
if manager.fans:
# VeSync classifies humidifiers as fans.
# Separate humidifers from the VeSync fans.
fans = []
humidifiers = []
for fan in manager.fans:
if fan.device_type in ("Classic300S",):
humidifiers.append(fan)
else:
fans.append(fan)
if fans:
devices[VS_FANS].extend(fans)
_LOGGER.info("%d VeSync fans found", len(fans))
if humidifiers:
devices[VS_HUMIDIFIERS].extend(humidifiers)
_LOGGER.info("%d VeSync humidifier found", len(humidifiers))
if manager.outlets:
devices[VS_SWITCHES].extend(manager.outlets)
_LOGGER.info("%d VeSync outlets found", len(manager.outlets))
if manager.switches:
for switch in manager.switches:
if not switch.is_dimmable():
devices[VS_SWITCHES].append(switch)
else:
devices[VS_LIGHTS].append(switch)
_LOGGER.info("%d VeSync switches found", len(manager.switches))
return devices
class VeSyncDevice(ToggleEntity):
"""Base class for VeSync Device Representations."""
def __init__(self, device):
"""Initialize the VeSync device."""
self.device = device
@property
def unique_id(self):
"""Return the ID of this device."""
if isinstance(self.device.sub_device_no, int):
return f"{self.device.cid}{str(self.device.sub_device_no)}"
return self.device.cid
@property
def name(self):
"""Return the name of the device."""
return self.device.device_name
@property
def is_on(self):
"""Return True if device is on."""
return self.device.device_status == "on"
@property
def available(self) -> bool:
"""Return True if device is available."""
return self.device.connection_status == "online"
def turn_off(self, **kwargs):
"""Turn the device off."""
self.device.turn_off()
def update(self):
"""Update vesync device."""
self.device.update()