1 """Support for VersaSense MicroPnP devices."""
5 import pyversasense
as pyv
6 import voluptuous
as vol
22 PERIPHERAL_CLASS_SENSOR,
23 PERIPHERAL_CLASS_SENSOR_ACTUATOR,
26 _LOGGER = logging.getLogger(__name__)
31 CONFIG_SCHEMA = vol.Schema(
32 {DOMAIN: vol.Schema({vol.Required(CONF_HOST): cv.string})}, extra=vol.ALLOW_EXTRA
36 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
37 """Set up the versasense component."""
38 session = aiohttp_client.async_get_clientsession(hass)
39 consumer = pyv.Consumer(config[DOMAIN][
"host"], session)
41 hass.data[DOMAIN] = {KEY_CONSUMER: consumer}
50 """Fetch all devices with their peripherals for representation."""
51 devices = await consumer.fetchDevices()
52 _LOGGER.debug(devices)
57 for mac, device
in devices.items():
58 _LOGGER.debug(
"Device connected: %s %s", device.name, mac)
59 hass.data[DOMAIN][mac] = {}
61 for peripheral_id, peripheral
in device.peripherals.items():
62 hass.data[DOMAIN][mac][peripheral_id] = peripheral
64 if peripheral.classification == PERIPHERAL_CLASS_SENSOR:
66 elif peripheral.classification == PERIPHERAL_CLASS_SENSOR_ACTUATOR:
77 """Add info from a peripheral to specified list."""
78 for measurement
in peripheral.measurements:
80 KEY_IDENTIFIER: peripheral.identifier,
81 KEY_UNIT: measurement.unit,
82 KEY_MEASUREMENT: measurement.name,
83 KEY_PARENT_NAME: device.name,
84 KEY_PARENT_MAC: device.mac,
87 key = f
"{entity_info[KEY_PARENT_MAC]}/{entity_info[KEY_IDENTIFIER]}/{entity_info[KEY_MEASUREMENT]}"
88 entity_dict[key] = entity_info
94 """Load platform with list of entity info."""
95 hass.async_create_task(
None _add_entity_info(peripheral, device, entity_dict)
def _configure_entities(hass, config, consumer)
def _load_platform(hass, config, entity_type, entity_info)
bool async_setup(HomeAssistant hass, ConfigType config)
None async_load_platform(core.HomeAssistant hass, Platform|str component, str platform, DiscoveryInfoType|None discovered, ConfigType hass_config)