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,17 +1,15 @@
"""Support for esphome sensors."""
import logging
import math
from typing import TYPE_CHECKING, Optional
from typing import Optional
from aioesphomeapi import (
SensorInfo, SensorState, TextSensorInfo, TextSensorState)
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
from . import EsphomeEntity, platform_async_setup_entry, esphome_state_property
if TYPE_CHECKING:
# pylint: disable=unused-import
from aioesphomeapi import ( # noqa
SensorInfo, SensorState, TextSensorInfo, TextSensorState)
from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry
_LOGGER = logging.getLogger(__name__)
@ -19,10 +17,6 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass: HomeAssistantType,
entry: ConfigEntry, async_add_entities) -> None:
"""Set up esphome sensors based on a config entry."""
# pylint: disable=redefined-outer-name
from aioesphomeapi import ( # noqa
SensorInfo, SensorState, TextSensorInfo, TextSensorState)
await platform_async_setup_entry(
hass, entry, async_add_entities,
component_key='sensor',
@ -41,11 +35,11 @@ class EsphomeSensor(EsphomeEntity):
"""A sensor implementation for esphome."""
@property
def _static_info(self) -> 'SensorInfo':
def _static_info(self) -> SensorInfo:
return super()._static_info
@property
def _state(self) -> Optional['SensorState']:
def _state(self) -> Optional[SensorState]:
return super()._state
@property