mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Move imports to top for tellduslive (#29550)
This commit is contained in:
parent
b759d50900
commit
957a2e99fd
@ -1,15 +1,17 @@
|
|||||||
"""Support for Telldus Live."""
|
"""Support for Telldus Live."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from tellduslive import DIM, TURNON, UP, Session
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_SCAN_INTERVAL
|
from homeassistant.const import CONF_SCAN_INTERVAL
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
from . import config_flow # noqa: F401
|
from . import config_flow # noqa: F401
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -51,7 +53,6 @@ INTERVAL_TRACKER = f"{DOMAIN}_INTERVAL"
|
|||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Create a tellduslive session."""
|
"""Create a tellduslive session."""
|
||||||
from tellduslive import Session
|
|
||||||
|
|
||||||
conf = entry.data[KEY_SESSION]
|
conf = entry.data[KEY_SESSION]
|
||||||
|
|
||||||
@ -159,7 +160,6 @@ class TelldusLiveClient:
|
|||||||
"""Find out what type of HA component to create."""
|
"""Find out what type of HA component to create."""
|
||||||
if device.is_sensor:
|
if device.is_sensor:
|
||||||
return "sensor"
|
return "sensor"
|
||||||
from tellduslive import DIM, UP, TURNON
|
|
||||||
|
|
||||||
if device.methods & DIM:
|
if device.methods & DIM:
|
||||||
return "light"
|
return "light"
|
||||||
|
@ -4,6 +4,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
from tellduslive import Session, supports_local_api
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -43,7 +44,6 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||||||
self._scan_interval = SCAN_INTERVAL
|
self._scan_interval = SCAN_INTERVAL
|
||||||
|
|
||||||
def _get_auth_url(self):
|
def _get_auth_url(self):
|
||||||
from tellduslive import Session
|
|
||||||
|
|
||||||
self._session = Session(
|
self._session = Session(
|
||||||
public_key=PUBLIC_KEY,
|
public_key=PUBLIC_KEY,
|
||||||
@ -116,7 +116,6 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||||||
|
|
||||||
async def async_step_discovery(self, user_input):
|
async def async_step_discovery(self, user_input):
|
||||||
"""Run when a Tellstick is discovered."""
|
"""Run when a Tellstick is discovered."""
|
||||||
from tellduslive import supports_local_api
|
|
||||||
|
|
||||||
_LOGGER.info("Discovered tellstick device: %s", user_input)
|
_LOGGER.info("Discovered tellstick device: %s", user_input)
|
||||||
if supports_local_api(user_input[1]):
|
if supports_local_api(user_input[1]):
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from tellduslive import BATTERY_LOW, BATTERY_OK, BATTERY_UNKNOWN
|
||||||
|
|
||||||
from homeassistant.const import ATTR_BATTERY_LEVEL, DEVICE_DEFAULT_NAME
|
from homeassistant.const import ATTR_BATTERY_LEVEL, DEVICE_DEFAULT_NAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
@ -91,7 +93,6 @@ class TelldusLiveEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def _battery_level(self):
|
def _battery_level(self):
|
||||||
"""Return the battery level of a device."""
|
"""Return the battery level of a device."""
|
||||||
from tellduslive import BATTERY_LOW, BATTERY_UNKNOWN, BATTERY_OK
|
|
||||||
|
|
||||||
if self.device.battery == BATTERY_LOW:
|
if self.device.battery == BATTERY_LOW:
|
||||||
return 1
|
return 1
|
||||||
|
@ -15,7 +15,7 @@ from homeassistant.components.tellduslive import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, MockDependency, mock_coro
|
from tests.common import MockConfigEntry, mock_coro
|
||||||
|
|
||||||
|
|
||||||
def init_config_flow(hass, side_effect=None):
|
def init_config_flow(hass, side_effect=None):
|
||||||
@ -42,13 +42,17 @@ def authorize():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_tellduslive(supports_local_api, authorize):
|
def mock_tellduslive(supports_local_api, authorize):
|
||||||
"""Mock tellduslive."""
|
"""Mock tellduslive."""
|
||||||
with MockDependency("tellduslive") as mock_tellduslive_:
|
with patch(
|
||||||
mock_tellduslive_.supports_local_api.return_value = supports_local_api
|
"homeassistant.components.tellduslive.config_flow.Session"
|
||||||
mock_tellduslive_.Session().authorize.return_value = authorize
|
) as Session, patch(
|
||||||
mock_tellduslive_.Session().access_token = "token"
|
"homeassistant.components.tellduslive.config_flow.supports_local_api"
|
||||||
mock_tellduslive_.Session().access_token_secret = "token_secret"
|
) as tellduslive_supports_local_api:
|
||||||
mock_tellduslive_.Session().authorize_url = "https://example.com"
|
tellduslive_supports_local_api.return_value = supports_local_api
|
||||||
yield mock_tellduslive_
|
Session().authorize.return_value = authorize
|
||||||
|
Session().access_token = "token"
|
||||||
|
Session().access_token_secret = "token_secret"
|
||||||
|
Session().authorize_url = "https://example.com"
|
||||||
|
yield Session, tellduslive_supports_local_api
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_already_setup(hass):
|
async def test_abort_if_already_setup(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user