mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Move esphome imports at top-level (#29064)
This commit is contained in:
parent
87de5db535
commit
8a413b152d
@ -1,5 +1,4 @@
|
|||||||
"""Support for ESPHome binary sensors."""
|
"""Support for ESPHome binary sensors."""
|
||||||
import logging
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from aioesphomeapi import BinarySensorInfo, BinarySensorState
|
from aioesphomeapi import BinarySensorInfo, BinarySensorState
|
||||||
@ -8,8 +7,6 @@ from homeassistant.components.binary_sensor import BinarySensorDevice
|
|||||||
|
|
||||||
from . import EsphomeEntity, platform_async_setup_entry
|
from . import EsphomeEntity, platform_async_setup_entry
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry, async_add_entities):
|
async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
"""Set up ESPHome binary sensors based on a config entry."""
|
"""Set up ESPHome binary sensors based on a config entry."""
|
||||||
|
@ -20,8 +20,8 @@ from homeassistant.components.climate.const import (
|
|||||||
CURRENT_HVAC_DRY,
|
CURRENT_HVAC_DRY,
|
||||||
CURRENT_HVAC_FAN,
|
CURRENT_HVAC_FAN,
|
||||||
CURRENT_HVAC_HEAT,
|
CURRENT_HVAC_HEAT,
|
||||||
CURRENT_HVAC_OFF,
|
|
||||||
CURRENT_HVAC_IDLE,
|
CURRENT_HVAC_IDLE,
|
||||||
|
CURRENT_HVAC_OFF,
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
FAN_DIFFUSE,
|
FAN_DIFFUSE,
|
||||||
FAN_FOCUS,
|
FAN_FOCUS,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from aioesphomeapi import APIClient, APIConnectionError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -147,8 +148,6 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
|
|||||||
|
|
||||||
async def fetch_device_info(self):
|
async def fetch_device_info(self):
|
||||||
"""Fetch device info from API and return any errors."""
|
"""Fetch device info from API and return any errors."""
|
||||||
from aioesphomeapi import APIClient, APIConnectionError
|
|
||||||
|
|
||||||
cli = APIClient(self.hass.loop, self._host, self._port, "")
|
cli = APIClient(self.hass.loop, self._host, self._port, "")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -165,8 +164,6 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
|
|||||||
|
|
||||||
async def try_login(self):
|
async def try_login(self):
|
||||||
"""Try logging in to device and return any errors."""
|
"""Try logging in to device and return any errors."""
|
||||||
from aioesphomeapi import APIClient, APIConnectionError
|
|
||||||
|
|
||||||
cli = APIClient(self.hass.loop, self._host, self._port, self._password)
|
cli = APIClient(self.hass.loop, self._host, self._port, self._password)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from aioesphomeapi import CoverInfo, CoverState
|
from aioesphomeapi import CoverInfo, CoverOperation, CoverState
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
@ -82,15 +82,11 @@ class EsphomeCover(EsphomeEntity, CoverDevice):
|
|||||||
@esphome_state_property
|
@esphome_state_property
|
||||||
def is_opening(self) -> bool:
|
def is_opening(self) -> bool:
|
||||||
"""Return if the cover is opening or not."""
|
"""Return if the cover is opening or not."""
|
||||||
from aioesphomeapi import CoverOperation
|
|
||||||
|
|
||||||
return self._state.current_operation == CoverOperation.IS_OPENING
|
return self._state.current_operation == CoverOperation.IS_OPENING
|
||||||
|
|
||||||
@esphome_state_property
|
@esphome_state_property
|
||||||
def is_closing(self) -> bool:
|
def is_closing(self) -> bool:
|
||||||
"""Return if the cover is closing or not."""
|
"""Return if the cover is closing or not."""
|
||||||
from aioesphomeapi import CoverOperation
|
|
||||||
|
|
||||||
return self._state.current_operation == CoverOperation.IS_CLOSING
|
return self._state.current_operation == CoverOperation.IS_CLOSING
|
||||||
|
|
||||||
@esphome_state_property
|
@esphome_state_property
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
"""Runtime entry data for ESPHome stored in hass.data."""
|
"""Runtime entry data for ESPHome stored in hass.data."""
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import Any, Callable, Dict, List, Optional, Tuple, Set
|
from typing import Any, Callable, Dict, List, Optional, Set, Tuple
|
||||||
|
|
||||||
from aioesphomeapi import (
|
from aioesphomeapi import (
|
||||||
COMPONENT_TYPE_TO_INFO,
|
COMPONENT_TYPE_TO_INFO,
|
||||||
DeviceInfo,
|
|
||||||
EntityInfo,
|
|
||||||
EntityState,
|
|
||||||
UserService,
|
|
||||||
BinarySensorInfo,
|
BinarySensorInfo,
|
||||||
CameraInfo,
|
CameraInfo,
|
||||||
ClimateInfo,
|
ClimateInfo,
|
||||||
CoverInfo,
|
CoverInfo,
|
||||||
|
DeviceInfo,
|
||||||
|
EntityInfo,
|
||||||
|
EntityState,
|
||||||
FanInfo,
|
FanInfo,
|
||||||
LightInfo,
|
LightInfo,
|
||||||
SensorInfo,
|
SensorInfo,
|
||||||
SwitchInfo,
|
SwitchInfo,
|
||||||
TextSensorInfo,
|
TextSensorInfo,
|
||||||
|
UserService,
|
||||||
)
|
)
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
|
@ -4,23 +4,17 @@ from unittest.mock import MagicMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.esphome import config_flow, DATA_KEY
|
from homeassistant.components.esphome import DATA_KEY, config_flow
|
||||||
from tests.common import mock_coro, MockConfigEntry
|
|
||||||
|
from tests.common import MockConfigEntry, mock_coro
|
||||||
|
|
||||||
MockDeviceInfo = namedtuple("DeviceInfo", ["uses_password", "name"])
|
MockDeviceInfo = namedtuple("DeviceInfo", ["uses_password", "name"])
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def aioesphomeapi_mock():
|
|
||||||
"""Mock aioesphomeapi."""
|
|
||||||
with patch.dict("sys.modules", {"aioesphomeapi": MagicMock()}):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_client():
|
def mock_client():
|
||||||
"""Mock APIClient."""
|
"""Mock APIClient."""
|
||||||
with patch("aioesphomeapi.APIClient") as mock_client:
|
with patch("homeassistant.components.esphome.config_flow.APIClient") as mock_client:
|
||||||
|
|
||||||
def mock_constructor(loop, host, port, password):
|
def mock_constructor(loop, host, port, password):
|
||||||
"""Fake the client constructor."""
|
"""Fake the client constructor."""
|
||||||
@ -40,7 +34,8 @@ def mock_client():
|
|||||||
def mock_api_connection_error():
|
def mock_api_connection_error():
|
||||||
"""Mock out the try login method."""
|
"""Mock out the try login method."""
|
||||||
with patch(
|
with patch(
|
||||||
"aioesphomeapi.APIConnectionError", new_callable=lambda: OSError
|
"homeassistant.components.esphome.config_flow.APIConnectionError",
|
||||||
|
new_callable=lambda: OSError,
|
||||||
) as mock_error:
|
) as mock_error:
|
||||||
yield mock_error
|
yield mock_error
|
||||||
|
|
||||||
@ -86,7 +81,8 @@ async def test_user_resolve_error(hass, mock_api_connection_error, mock_client):
|
|||||||
super().__init__("Error resolving IP address")
|
super().__init__("Error resolving IP address")
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"aioesphomeapi.APIConnectionError", new_callable=lambda: MockResolveError
|
"homeassistant.components.esphome.config_flow.APIConnectionError",
|
||||||
|
new_callable=lambda: MockResolveError,
|
||||||
) as exc:
|
) as exc:
|
||||||
mock_client.device_info.side_effect = exc
|
mock_client.device_info.side_effect = exc
|
||||||
result = await flow.async_step_user(
|
result = await flow.async_step_user(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user