From 4460aef040c7cf8b8feba65663500c9ebc14e17d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 11 Jan 2022 18:18:39 +0100 Subject: [PATCH] Cleanup variable names in versasense (#63914) Co-authored-by: epenet --- .../components/versasense/__init__.py | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/versasense/__init__.py b/homeassistant/components/versasense/__init__.py index 9b1e90b698d..d1ca23d82af 100644 --- a/homeassistant/components/versasense/__init__.py +++ b/homeassistant/components/versasense/__init__.py @@ -4,7 +4,7 @@ import logging import pyversasense as pyv import voluptuous as vol -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_HOST, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import aiohttp_client import homeassistant.helpers.config_validation as cv @@ -50,8 +50,8 @@ async def _configure_entities(hass, config, consumer): devices = await consumer.fetchDevices() _LOGGER.debug(devices) - sensor_info_list = {} - switch_info_list = {} + sensor_info = {} + switch_info = {} for mac, device in devices.items(): _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 if peripheral.classification == PERIPHERAL_CLASS_SENSOR: - sensor_info_list = _add_entity_info_to_list( - peripheral, device, sensor_info_list - ) + sensor_info = _add_entity_info(peripheral, device, sensor_info) elif peripheral.classification == PERIPHERAL_CLASS_SENSOR_ACTUATOR: - switch_info_list = _add_entity_info_to_list( - peripheral, device, switch_info_list - ) + switch_info = _add_entity_info(peripheral, device, switch_info) - if sensor_info_list: - _load_platform(hass, config, "sensor", sensor_info_list) + if sensor_info: + _load_platform(hass, config, Platform.SENSOR, sensor_info) - if switch_info_list: - _load_platform(hass, config, "switch", switch_info_list) + if switch_info: + _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.""" for measurement in peripheral.measurements: 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]}" - 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.""" 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) )