From 9205020fa432d1409c176f1ff929a84581a7f338 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:49:49 +0100 Subject: [PATCH] Avoid import homeassistant.const as a module (#85991) --- homeassistant/components/esphome/__init__.py | 4 ++-- homeassistant/components/ping/device_tracker.py | 9 +++++---- homeassistant/components/ring/config_flow.py | 5 +++-- homeassistant/components/zha/__init__.py | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index e4dceb304b7..8fe3cec19cb 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -26,7 +26,6 @@ from aioesphomeapi import ( from awesomeversion import AwesomeVersion import voluptuous as vol -from homeassistant import const from homeassistant.components import tag, zeroconf from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -36,6 +35,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_PORT, EVENT_HOMEASSISTANT_STOP, + __version__ as ha_version, ) from homeassistant.core import Event, HomeAssistant, ServiceCall, State, callback from homeassistant.exceptions import TemplateError @@ -122,7 +122,7 @@ async def async_setup_entry( # noqa: C901 host, port, password, - client_info=f"Home Assistant {const.__version__}", + client_info=f"Home Assistant {ha_version}", zeroconf_instance=zeroconf_instance, noise_psk=noise_psk, ) diff --git a/homeassistant/components/ping/device_tracker.py b/homeassistant/components/ping/device_tracker.py index b4266c8e9a7..c3729f04c14 100644 --- a/homeassistant/components/ping/device_tracker.py +++ b/homeassistant/components/ping/device_tracker.py @@ -9,7 +9,7 @@ import subprocess from icmplib import async_multiping import voluptuous as vol -from homeassistant import const, util +from homeassistant import util from homeassistant.components.device_tracker import ( CONF_SCAN_INTERVAL, PLATFORM_SCHEMA as BASE_PLATFORM_SCHEMA, @@ -17,6 +17,7 @@ from homeassistant.components.device_tracker import ( AsyncSeeCallback, SourceType, ) +from homeassistant.const import CONF_HOSTS from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.event import async_track_point_in_utc_time @@ -34,7 +35,7 @@ CONCURRENT_PING_LIMIT = 6 PLATFORM_SCHEMA = BASE_PLATFORM_SCHEMA.extend( { - vol.Required(const.CONF_HOSTS): {cv.slug: cv.string}, + vol.Required(CONF_HOSTS): {cv.slug: cv.string}, vol.Optional(CONF_PING_COUNT, default=1): cv.positive_int, } ) @@ -87,7 +88,7 @@ async def async_setup_scanner( """Set up the Host objects and return the update function.""" privileged = hass.data[DOMAIN][PING_PRIVS] - ip_to_dev_id = {ip: dev_id for (dev_id, ip) in config[const.CONF_HOSTS].items()} + ip_to_dev_id = {ip: dev_id for (dev_id, ip) in config[CONF_HOSTS].items()} interval = config.get( CONF_SCAN_INTERVAL, timedelta(seconds=len(ip_to_dev_id) * config[CONF_PING_COUNT]) + SCAN_INTERVAL, @@ -101,7 +102,7 @@ async def async_setup_scanner( if privileged is None: hosts = [ HostSubProcess(ip, dev_id, hass, config, privileged) - for (dev_id, ip) in config[const.CONF_HOSTS].items() + for (dev_id, ip) in config[CONF_HOSTS].items() ] async def async_update(now): diff --git a/homeassistant/components/ring/config_flow.py b/homeassistant/components/ring/config_flow.py index cca0c231d96..02b68ee6f3b 100644 --- a/homeassistant/components/ring/config_flow.py +++ b/homeassistant/components/ring/config_flow.py @@ -5,7 +5,8 @@ from oauthlib.oauth2 import AccessDeniedError, MissingTokenError from ring_doorbell import Auth import voluptuous as vol -from homeassistant import config_entries, const, core, exceptions +from homeassistant import config_entries, core, exceptions +from homeassistant.const import __version__ as ha_version from . import DOMAIN @@ -15,7 +16,7 @@ _LOGGER = logging.getLogger(__name__) async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect.""" - auth = Auth(f"HomeAssistant/{const.__version__}") + auth = Auth(f"HomeAssistant/{ha_version}") try: token = await hass.async_add_executor_job( diff --git a/homeassistant/components/zha/__init__.py b/homeassistant/components/zha/__init__.py index 18eee70b20b..48c10304ad5 100644 --- a/homeassistant/components/zha/__init__.py +++ b/homeassistant/components/zha/__init__.py @@ -7,8 +7,8 @@ import voluptuous as vol from zhaquirks import setup as setup_quirks from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH -from homeassistant import const as ha_const from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_TYPE, EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr import homeassistant.helpers.config_validation as cv @@ -39,7 +39,7 @@ from .core.const import ( ) from .core.discovery import GROUP_PROBE -DEVICE_CONFIG_SCHEMA_ENTRY = vol.Schema({vol.Optional(ha_const.CONF_TYPE): cv.string}) +DEVICE_CONFIG_SCHEMA_ENTRY = vol.Schema({vol.Optional(CONF_TYPE): cv.string}) ZHA_CONFIG_SCHEMA = { vol.Optional(CONF_BAUDRATE): cv.positive_int, vol.Optional(CONF_DATABASE): cv.string, @@ -128,7 +128,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b await zha_gateway.shutdown() zha_data[DATA_ZHA_SHUTDOWN_TASK] = hass.bus.async_listen_once( - ha_const.EVENT_HOMEASSISTANT_STOP, async_zha_shutdown + EVENT_HOMEASSISTANT_STOP, async_zha_shutdown ) await zha_gateway.async_initialize_devices_and_entities()