Home Assistant Unofficial Reference 2024.12.1
common.py
Go to the documentation of this file.
1 """Common utilities for VeSync Component."""
2 
3 import logging
4 
5 from .const import VS_FANS, VS_LIGHTS, VS_SENSORS, VS_SWITCHES
6 
7 _LOGGER = logging.getLogger(__name__)
8 
9 
10 async def async_process_devices(hass, manager):
11  """Assign devices to proper component."""
12  devices = {}
13  devices[VS_SWITCHES] = []
14  devices[VS_FANS] = []
15  devices[VS_LIGHTS] = []
16  devices[VS_SENSORS] = []
17 
18  await hass.async_add_executor_job(manager.update)
19 
20  if manager.fans:
21  devices[VS_FANS].extend(manager.fans)
22  # Expose fan sensors separately
23  devices[VS_SENSORS].extend(manager.fans)
24  _LOGGER.debug("%d VeSync fans found", len(manager.fans))
25 
26  if manager.bulbs:
27  devices[VS_LIGHTS].extend(manager.bulbs)
28  _LOGGER.debug("%d VeSync lights found", len(manager.bulbs))
29 
30  if manager.outlets:
31  devices[VS_SWITCHES].extend(manager.outlets)
32  # Expose outlets' voltage, power & energy usage as separate sensors
33  devices[VS_SENSORS].extend(manager.outlets)
34  _LOGGER.debug("%d VeSync outlets found", len(manager.outlets))
35 
36  if manager.switches:
37  for switch in manager.switches:
38  if not switch.is_dimmable():
39  devices[VS_SWITCHES].append(switch)
40  else:
41  devices[VS_LIGHTS].append(switch)
42  _LOGGER.debug("%d VeSync switches found", len(manager.switches))
43 
44  return devices
def async_process_devices(hass, manager)
Definition: common.py:10