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

Avoid blocking import warning #1371

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions custom_components/better_thermostat/adapters/delegate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from importlib import import_module
from homeassistant.helpers.importlib import async_import_module
import logging

_LOGGER = logging.getLogger(__name__)


def load_adapter(self, integration, entity_id, get_name=False):
async def load_adapter(self, integration, entity_id, get_name=False):
"""Load adapter."""
if get_name:
self.name = "-"
Expand All @@ -13,9 +13,9 @@ def load_adapter(self, integration, entity_id, get_name=False):
integration = "generic"

try:
self.adapter = import_module(
self.adapter = await async_import_module(
self.hass,
"custom_components.better_thermostat.adapters." + integration,
package="better_thermostat",
)
_LOGGER.debug(
"better_thermostat %s: uses adapter %s for trv %s",
Expand All @@ -24,9 +24,9 @@ def load_adapter(self, integration, entity_id, get_name=False):
entity_id,
)
except Exception:
self.adapter = import_module(
self.adapter = await async_import_module(
self.hass,
"custom_components.better_thermostat.adapters.generic",
package="better_thermostat",
)
_LOGGER.info(
"better_thermostat %s: integration: %s isn't native supported, feel free to open an issue, fallback adapter %s",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/better_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ async def async_added_to_hass(self):
_calibration = 0
if trv["advanced"]["calibration"] == "hybrid_calibration":
_calibration = 2
_adapter = load_adapter(self, trv["integration"], trv["trv"])
_model_quirks = load_model_quirks(self, trv["model"], trv["trv"])
_adapter = await load_adapter(self, trv["integration"], trv["trv"])
_model_quirks = await load_model_quirks(self, trv["model"], trv["trv"])
self.real_trvs[trv["trv"]] = {
"calibration": _calibration,
"integration": trv["integration"],
Expand Down
4 changes: 2 additions & 2 deletions custom_components/better_thermostat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async def async_step_user(self, user_input=None):
"trv": trv,
"integration": _intigration,
"model": await get_device_model(self, trv),
"adapter": load_adapter(self, _intigration, trv),
"adapter": await load_adapter(self, _intigration, trv),
}
)
self.data[CONF_MODEL] = "/".join([x["model"] for x in self.trv_bundle])
Expand Down Expand Up @@ -438,7 +438,7 @@ async def async_step_advanced(
_default_calibration = "target_temp_based"
self.name = user_input.get(CONF_NAME, "-")

_adapter = load_adapter(
_adapter = await load_adapter(
self, _trv_config.get("integration"), _trv_config.get("trv")
)
if _adapter is not None:
Expand Down
4 changes: 3 additions & 1 deletion custom_components/better_thermostat/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ async def async_get_config_entry_diagnostics(
trv = hass.states.get(trv_id["trv"])
if trv is None:
continue
_adapter_name = load_adapter(hass, trv_id["integration"], trv_id["trv"], True)
_adapter_name = await load_adapter(
hass, trv_id["integration"], trv_id["trv"], True
)
trv_id["adapter"] = _adapter_name
trvs[trv_id["trv"]] = {
"name": trv.name,
Expand Down
12 changes: 6 additions & 6 deletions custom_components/better_thermostat/model_fixes/model_quirks.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from importlib import import_module
from homeassistant.helpers.importlib import async_import_module
import logging

_LOGGER = logging.getLogger(__name__)


def load_model_quirks(self, model, entity_id):
async def load_model_quirks(self, model, entity_id):
"""Load model."""

# remove / from model
model = model.replace("/", "_")

try:
self.model_quirks = import_module(
self.model_quirks = await async_import_module(
self.hass,
"custom_components.better_thermostat.model_fixes." + model,
package="better_thermostat",
)
_LOGGER.debug(
"better_thermostat %s: uses quirks fixes for model %s for trv %s",
Expand All @@ -22,9 +22,9 @@ def load_model_quirks(self, model, entity_id):
entity_id,
)
except Exception:
self.model_quirks = import_module(
self.model_quirks = await async_import_module(
self.hass,
"custom_components.better_thermostat.model_fixes.default",
package="better_thermostat",
)
pass

Expand Down
Loading