From 68433b09383071c53fa5d3ba9321c8f34f4252fb Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Tue, 13 Oct 2020 22:09:31 +0100 Subject: [PATCH 1/2] Fix circular import of config_validation and template --- homeassistant/helpers/location.py | 4 +++- homeassistant/helpers/template.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/location.py b/homeassistant/helpers/location.py index 856c5c4d8e3afe..5c55bf9536cbdb 100644 --- a/homeassistant/helpers/location.py +++ b/homeassistant/helpers/location.py @@ -7,7 +7,6 @@ from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE from homeassistant.core import State -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util import location as loc_util @@ -91,6 +90,9 @@ def find_coordinates( # Check if state is valid coordinate set try: + # Import here, not at top-level to avoid circular import + import homeassistant.helpers.config_validation as cv + cv.gps(entity_state.state.split(",")) except vol.Invalid: _LOGGER.error( diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index b92f926f809953..f5ca6c7fce5b84 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -32,7 +32,7 @@ ) from homeassistant.core import State, callback, split_entity_id, valid_entity_id from homeassistant.exceptions import TemplateError -from homeassistant.helpers import config_validation as cv, location as loc_helper +from homeassistant.helpers import location as loc_helper from homeassistant.helpers.frame import report from homeassistant.helpers.typing import HomeAssistantType, TemplateVarsType from homeassistant.loader import bind_hass @@ -762,6 +762,9 @@ def result_as_boolean(template_result: Optional[str]) -> bool: """ try: + # Import here, not at top-level to avoid circular import + from homeassistant.helpers import config_validation as cv + return cv.boolean(template_result) except vol.Invalid: return False From 093e5889c5a127f4c01d5d00fb3b082bd7cd2a4a Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Tue, 13 Oct 2020 23:26:43 +0100 Subject: [PATCH 2/2] Disable linting of the imports outside of toplevel --- homeassistant/helpers/location.py | 2 +- homeassistant/helpers/template.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/location.py b/homeassistant/helpers/location.py index 5c55bf9536cbdb..bca2996dfa2da1 100644 --- a/homeassistant/helpers/location.py +++ b/homeassistant/helpers/location.py @@ -91,7 +91,7 @@ def find_coordinates( # Check if state is valid coordinate set try: # Import here, not at top-level to avoid circular import - import homeassistant.helpers.config_validation as cv + import homeassistant.helpers.config_validation as cv # pylint: disable=import-outside-toplevel cv.gps(entity_state.state.split(",")) except vol.Invalid: diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index f5ca6c7fce5b84..9f0d63e4dd158d 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -763,7 +763,9 @@ def result_as_boolean(template_result: Optional[str]) -> bool: """ try: # Import here, not at top-level to avoid circular import - from homeassistant.helpers import config_validation as cv + from homeassistant.helpers import ( # pylint: disable=import-outside-toplevel + config_validation as cv, + ) return cv.boolean(template_result) except vol.Invalid: