mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Cleanup variable names in versasense (#63914)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
dc58bc375a
commit
4460aef040
@ -4,7 +4,7 @@ import logging
|
|||||||
import pyversasense as pyv
|
import pyversasense as pyv
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -50,8 +50,8 @@ async def _configure_entities(hass, config, consumer):
|
|||||||
devices = await consumer.fetchDevices()
|
devices = await consumer.fetchDevices()
|
||||||
_LOGGER.debug(devices)
|
_LOGGER.debug(devices)
|
||||||
|
|
||||||
sensor_info_list = {}
|
sensor_info = {}
|
||||||
switch_info_list = {}
|
switch_info = {}
|
||||||
|
|
||||||
for mac, device in devices.items():
|
for mac, device in devices.items():
|
||||||
_LOGGER.info("Device connected: %s %s", device.name, mac)
|
_LOGGER.info("Device connected: %s %s", device.name, mac)
|
||||||
@ -61,22 +61,18 @@ async def _configure_entities(hass, config, consumer):
|
|||||||
hass.data[DOMAIN][mac][peripheral_id] = peripheral
|
hass.data[DOMAIN][mac][peripheral_id] = peripheral
|
||||||
|
|
||||||
if peripheral.classification == PERIPHERAL_CLASS_SENSOR:
|
if peripheral.classification == PERIPHERAL_CLASS_SENSOR:
|
||||||
sensor_info_list = _add_entity_info_to_list(
|
sensor_info = _add_entity_info(peripheral, device, sensor_info)
|
||||||
peripheral, device, sensor_info_list
|
|
||||||
)
|
|
||||||
elif peripheral.classification == PERIPHERAL_CLASS_SENSOR_ACTUATOR:
|
elif peripheral.classification == PERIPHERAL_CLASS_SENSOR_ACTUATOR:
|
||||||
switch_info_list = _add_entity_info_to_list(
|
switch_info = _add_entity_info(peripheral, device, switch_info)
|
||||||
peripheral, device, switch_info_list
|
|
||||||
)
|
|
||||||
|
|
||||||
if sensor_info_list:
|
if sensor_info:
|
||||||
_load_platform(hass, config, "sensor", sensor_info_list)
|
_load_platform(hass, config, Platform.SENSOR, sensor_info)
|
||||||
|
|
||||||
if switch_info_list:
|
if switch_info:
|
||||||
_load_platform(hass, config, "switch", switch_info_list)
|
_load_platform(hass, config, Platform.SWITCH, switch_info)
|
||||||
|
|
||||||
|
|
||||||
def _add_entity_info_to_list(peripheral, device, entity_info_list):
|
def _add_entity_info(peripheral, device, entity_dict) -> None:
|
||||||
"""Add info from a peripheral to specified list."""
|
"""Add info from a peripheral to specified list."""
|
||||||
for measurement in peripheral.measurements:
|
for measurement in peripheral.measurements:
|
||||||
entity_info = {
|
entity_info = {
|
||||||
@ -88,13 +84,13 @@ def _add_entity_info_to_list(peripheral, device, entity_info_list):
|
|||||||
}
|
}
|
||||||
|
|
||||||
key = f"{entity_info[KEY_PARENT_MAC]}/{entity_info[KEY_IDENTIFIER]}/{entity_info[KEY_MEASUREMENT]}"
|
key = f"{entity_info[KEY_PARENT_MAC]}/{entity_info[KEY_IDENTIFIER]}/{entity_info[KEY_MEASUREMENT]}"
|
||||||
entity_info_list[key] = entity_info
|
entity_dict[key] = entity_info
|
||||||
|
|
||||||
return entity_info_list
|
return entity_dict
|
||||||
|
|
||||||
|
|
||||||
def _load_platform(hass, config, entity_type, entity_info_list):
|
def _load_platform(hass, config, entity_type, entity_info):
|
||||||
"""Load platform with list of entity info."""
|
"""Load platform with list of entity info."""
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
async_load_platform(hass, entity_type, DOMAIN, entity_info_list, config)
|
async_load_platform(hass, entity_type, DOMAIN, entity_info, config)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user