mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
Move imports to top for toon (#29553)
This commit is contained in:
parent
d5419b77f9
commit
ec3ffe309a
@ -1,17 +1,18 @@
|
||||
"""Support for Toon van Eneco devices."""
|
||||
from functools import partial
|
||||
import logging
|
||||
from typing import Any, Dict
|
||||
from functools import partial
|
||||
|
||||
from toonapilib import Toon
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, CONF_SCAN_INTERVAL
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send, async_dispatcher_connect
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
|
||||
from . import config_flow # noqa: F401
|
||||
from .const import (
|
||||
@ -19,10 +20,10 @@ from .const import (
|
||||
CONF_CLIENT_SECRET,
|
||||
CONF_DISPLAY,
|
||||
CONF_TENANT,
|
||||
DATA_TOON,
|
||||
DATA_TOON_CLIENT,
|
||||
DATA_TOON_CONFIG,
|
||||
DATA_TOON_UPDATED,
|
||||
DATA_TOON,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DOMAIN,
|
||||
)
|
||||
@ -63,7 +64,6 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigType) -> bool:
|
||||
"""Set up Toon from a config entry."""
|
||||
from toonapilib import Toon
|
||||
|
||||
conf = hass.data.get(DATA_TOON_CONFIG)
|
||||
|
||||
|
@ -8,11 +8,11 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from . import (
|
||||
ToonData,
|
||||
ToonEntity,
|
||||
ToonDisplayDeviceEntity,
|
||||
ToonBoilerDeviceEntity,
|
||||
ToonBoilerModuleDeviceEntity,
|
||||
ToonData,
|
||||
ToonDisplayDeviceEntity,
|
||||
ToonEntity,
|
||||
)
|
||||
from .const import DATA_TOON, DOMAIN
|
||||
|
||||
|
@ -5,6 +5,8 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
HVAC_MODE_HEAT,
|
||||
PRESET_AWAY,
|
||||
PRESET_COMFORT,
|
||||
@ -12,8 +14,6 @@ from homeassistant.components.climate.const import (
|
||||
PRESET_SLEEP,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
@ -21,8 +21,8 @@ from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from . import ToonData, ToonDisplayDeviceEntity
|
||||
from .const import (
|
||||
DATA_TOON_CLIENT,
|
||||
DATA_TOON,
|
||||
DATA_TOON_CLIENT,
|
||||
DEFAULT_MAX_TEMP,
|
||||
DEFAULT_MIN_TEMP,
|
||||
DOMAIN,
|
||||
|
@ -1,8 +1,15 @@
|
||||
"""Config flow to configure the Toon component."""
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
from functools import partial
|
||||
import logging
|
||||
|
||||
from toonapilib import Toon
|
||||
from toonapilib.toonapilibexceptions import (
|
||||
AgreementsRetrievalError,
|
||||
InvalidConsumerKey,
|
||||
InvalidConsumerSecret,
|
||||
InvalidCredentials,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
@ -67,13 +74,6 @@ class ToonFlowHandler(config_entries.ConfigFlow):
|
||||
|
||||
async def async_step_authenticate(self, user_input=None):
|
||||
"""Attempt to authenticate with the Toon account."""
|
||||
from toonapilib import Toon
|
||||
from toonapilib.toonapilibexceptions import (
|
||||
InvalidConsumerSecret,
|
||||
InvalidConsumerKey,
|
||||
InvalidCredentials,
|
||||
AgreementsRetrievalError,
|
||||
)
|
||||
|
||||
if user_input is None:
|
||||
return await self._show_authenticaticate_form()
|
||||
@ -129,7 +129,6 @@ class ToonFlowHandler(config_entries.ConfigFlow):
|
||||
|
||||
async def async_step_display(self, user_input=None):
|
||||
"""Select Toon display to add."""
|
||||
from toonapilib import Toon
|
||||
|
||||
if not self.displays:
|
||||
return self.async_abort(reason="no_displays")
|
||||
|
@ -2,18 +2,18 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from . import (
|
||||
ToonBoilerDeviceEntity,
|
||||
ToonData,
|
||||
ToonEntity,
|
||||
ToonElectricityMeterDeviceEntity,
|
||||
ToonEntity,
|
||||
ToonGasMeterDeviceEntity,
|
||||
ToonSolarDeviceEntity,
|
||||
ToonBoilerDeviceEntity,
|
||||
)
|
||||
from .const import CURRENCY_EUR, DATA_TOON, DOMAIN, VOLUME_CM3, VOLUME_M3, RATIO_PERCENT
|
||||
from .const import CURRENCY_EUR, DATA_TOON, DOMAIN, RATIO_PERCENT, VOLUME_CM3, VOLUME_M3
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from homeassistant.components.toon.const import (
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, MockDependency
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
FIXTURE_APP = {
|
||||
DOMAIN: {CONF_CLIENT_ID: "1234567890abcdef", CONF_CLIENT_SECRET: "1234567890abcdef"}
|
||||
@ -40,9 +40,9 @@ FIXTURE_DISPLAY = {CONF_DISPLAY: "display1"}
|
||||
@pytest.fixture
|
||||
def mock_toonapilib():
|
||||
"""Mock toonapilib."""
|
||||
with MockDependency("toonapilib") as mock_toonapilib_:
|
||||
mock_toonapilib_.Toon().display_names = [FIXTURE_DISPLAY[CONF_DISPLAY]]
|
||||
yield mock_toonapilib_
|
||||
with patch("homeassistant.components.toon.config_flow.Toon") as Toon:
|
||||
Toon().display_names = [FIXTURE_DISPLAY[CONF_DISPLAY]]
|
||||
yield Toon
|
||||
|
||||
|
||||
async def setup_component(hass):
|
||||
@ -90,7 +90,7 @@ async def test_toon_abort(hass, mock_toonapilib, side_effect, reason):
|
||||
flow = config_flow.ToonFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
mock_toonapilib.Toon.side_effect = side_effect
|
||||
mock_toonapilib.side_effect = side_effect
|
||||
|
||||
result = await flow.async_step_authenticate(user_input=FIXTURE_CREDENTIALS)
|
||||
|
||||
@ -100,7 +100,7 @@ async def test_toon_abort(hass, mock_toonapilib, side_effect, reason):
|
||||
|
||||
async def test_invalid_credentials(hass, mock_toonapilib):
|
||||
"""Test we show authentication form on Toon auth error."""
|
||||
mock_toonapilib.Toon.side_effect = InvalidCredentials
|
||||
mock_toonapilib.side_effect = InvalidCredentials
|
||||
|
||||
await setup_component(hass)
|
||||
|
||||
@ -140,7 +140,7 @@ async def test_no_displays(hass, mock_toonapilib):
|
||||
"""Test abort when there are no displays."""
|
||||
await setup_component(hass)
|
||||
|
||||
mock_toonapilib.Toon().display_names = []
|
||||
mock_toonapilib().display_names = []
|
||||
|
||||
flow = config_flow.ToonFlowHandler()
|
||||
flow.hass = hass
|
||||
@ -177,7 +177,7 @@ async def test_abort_last_minute_fail(hass, mock_toonapilib):
|
||||
flow.hass = hass
|
||||
await flow.async_step_user(user_input=FIXTURE_CREDENTIALS)
|
||||
|
||||
mock_toonapilib.Toon.side_effect = Exception
|
||||
mock_toonapilib.side_effect = Exception
|
||||
|
||||
result = await flow.async_step_display(user_input=FIXTURE_DISPLAY)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
|
Loading…
Reference in New Issue
Block a user