Use global imports for ESPHome (#24158)

* Use global import for ESPHome

* Add aioesphomeapi to test requirements

aioesphomeapi is also shipped as a pure-python wheel, so this should not impact test install time
This commit is contained in:
Otto Winter 2019-05-29 13:33:49 +02:00 committed by Pascal Vizeli
parent d9c78b77cb
commit 015c8811a5
11 changed files with 69 additions and 118 deletions

View file

@ -1,6 +1,8 @@
"""Support for ESPHome lights."""
import logging
from typing import TYPE_CHECKING, List, Optional, Tuple
from typing import List, Optional, Tuple
from aioesphomeapi import LightInfo, LightState
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_FLASH, ATTR_HS_COLOR,
@ -11,11 +13,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
import homeassistant.util.color as color_util
from . import EsphomeEntity, platform_async_setup_entry, esphome_state_property
if TYPE_CHECKING:
# pylint: disable=unused-import
from aioesphomeapi import LightInfo, LightState # noqa
from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry
_LOGGER = logging.getLogger(__name__)
@ -29,9 +27,6 @@ FLASH_LENGTHS = {
async def async_setup_entry(hass: HomeAssistantType,
entry: ConfigEntry, async_add_entities) -> None:
"""Set up ESPHome lights based on a config entry."""
# pylint: disable=redefined-outer-name
from aioesphomeapi import LightInfo, LightState # noqa
await platform_async_setup_entry(
hass, entry, async_add_entities,
component_key='light',
@ -44,11 +39,11 @@ class EsphomeLight(EsphomeEntity, Light):
"""A switch implementation for ESPHome."""
@property
def _static_info(self) -> 'LightInfo':
def _static_info(self) -> LightInfo:
return super()._static_info
@property
def _state(self) -> Optional['LightState']:
def _state(self) -> Optional[LightState]:
return super()._state
@esphome_state_property