Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circular import of config_validation and template #41802

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/helpers/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 # pylint: disable=import-outside-toplevel

cv.gps(entity_state.state.split(","))
except vol.Invalid:
_LOGGER.error(
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/helpers/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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.typing import HomeAssistantType, TemplateVarsType
from homeassistant.loader import bind_hass
from homeassistant.util import convert, dt as dt_util, location as loc_util
Expand Down Expand Up @@ -791,6 +791,11 @@ def result_as_boolean(template_result: Optional[str]) -> bool:

"""
try:
# Import here, not at top-level to avoid circular import
from homeassistant.helpers import ( # pylint: disable=import-outside-toplevel
config_validation as cv,
)

return cv.boolean(template_result)
except vol.Invalid:
return False
Expand Down