Move imports in rflink component (#27367)
* Move imports in rflink component * import order * import order * Update __init__.py * Update __init__.py I don't understand why tests are failing... * Fix RFLink imports * Fix monkeypatch for 'create_rflink_connection' * isort for rflink classes
This commit is contained in:
parent
2acd3f9e98
commit
dd8fc41747
8 changed files with 28 additions and 28 deletions
|
@ -2,8 +2,10 @@
|
|||
import asyncio
|
||||
from collections import defaultdict
|
||||
import logging
|
||||
import async_timeout
|
||||
|
||||
import async_timeout
|
||||
from rflink.protocol import create_rflink_connection
|
||||
from serial import SerialException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -11,18 +13,18 @@ from homeassistant.const import (
|
|||
CONF_COMMAND,
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
STATE_ON,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import CoreState, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.deprecation import get_deprecated
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_send,
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -118,9 +120,6 @@ def identify_event_type(event):
|
|||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the Rflink component."""
|
||||
from rflink.protocol import create_rflink_connection
|
||||
import serial
|
||||
|
||||
# Allow entities to register themselves by device_id to be looked up when
|
||||
# new rflink events arrive to be handled
|
||||
hass.data[DATA_ENTITY_LOOKUP] = {
|
||||
|
@ -239,7 +238,7 @@ async def async_setup(hass, config):
|
|||
transport, protocol = await connection
|
||||
|
||||
except (
|
||||
serial.serialutil.SerialException,
|
||||
SerialException,
|
||||
ConnectionRefusedError,
|
||||
TimeoutError,
|
||||
OSError,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Support for Rflink sensors."""
|
||||
import logging
|
||||
|
||||
from rflink.parser import PACKET_FIELDS, UNITS
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
|
@ -66,8 +67,6 @@ def lookup_unit_for_sensor_type(sensor_type):
|
|||
|
||||
Async friendly.
|
||||
"""
|
||||
from rflink.parser import UNITS, PACKET_FIELDS
|
||||
|
||||
field_abbrev = {v: k for k, v in PACKET_FIELDS.items()}
|
||||
|
||||
return UNITS.get(field_abbrev.get(sensor_type))
|
||||
|
|
|
@ -8,14 +8,13 @@ from datetime import timedelta
|
|||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.rflink import CONF_RECONNECT_INTERVAL
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.const import (
|
||||
EVENT_STATE_CHANGED,
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
import homeassistant.core as ha
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
|
|
@ -9,13 +9,13 @@ import logging
|
|||
|
||||
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
|
||||
from homeassistant.const import (
|
||||
SERVICE_OPEN_COVER,
|
||||
SERVICE_CLOSE_COVER,
|
||||
STATE_OPEN,
|
||||
STATE_CLOSED,
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_OPEN_COVER,
|
||||
STATE_CLOSED,
|
||||
STATE_OPEN,
|
||||
)
|
||||
from homeassistant.core import callback, State, CoreState
|
||||
from homeassistant.core import CoreState, State, callback
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.components.rflink.test_init import mock_rflink
|
||||
|
|
|
@ -5,14 +5,14 @@ from unittest.mock import Mock
|
|||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.rflink import (
|
||||
CONF_RECONNECT_INTERVAL,
|
||||
SERVICE_SEND_COMMAND,
|
||||
RflinkCommand,
|
||||
TMP_ENTITY,
|
||||
DATA_ENTITY_LOOKUP,
|
||||
EVENT_KEY_COMMAND,
|
||||
EVENT_KEY_SENSOR,
|
||||
SERVICE_SEND_COMMAND,
|
||||
TMP_ENTITY,
|
||||
RflinkCommand,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_STOP_COVER
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_STOP_COVER, SERVICE_TURN_OFF
|
||||
|
||||
|
||||
async def mock_rflink(
|
||||
|
@ -46,7 +46,9 @@ async def mock_rflink(
|
|||
return transport, protocol
|
||||
|
||||
mock_create = Mock(wraps=create_rflink_connection)
|
||||
monkeypatch.setattr("rflink.protocol.create_rflink_connection", mock_create)
|
||||
monkeypatch.setattr(
|
||||
"homeassistant.components.rflink.create_rflink_connection", mock_create
|
||||
)
|
||||
|
||||
await async_setup_component(hass, "rflink", config)
|
||||
await async_setup_component(hass, domain, config)
|
||||
|
|
|
@ -11,10 +11,10 @@ from homeassistant.const import (
|
|||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import callback, State, CoreState
|
||||
from homeassistant.core import CoreState, State, callback
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.components.rflink.test_init import mock_rflink
|
||||
|
|
|
@ -7,12 +7,13 @@ automatic sensor creation.
|
|||
|
||||
from homeassistant.components.rflink import (
|
||||
CONF_RECONNECT_INTERVAL,
|
||||
TMP_ENTITY,
|
||||
DATA_ENTITY_LOOKUP,
|
||||
EVENT_KEY_COMMAND,
|
||||
EVENT_KEY_SENSOR,
|
||||
TMP_ENTITY,
|
||||
)
|
||||
from homeassistant.const import STATE_UNKNOWN
|
||||
|
||||
from tests.components.rflink.test_init import mock_rflink
|
||||
|
||||
DOMAIN = "sensor"
|
||||
|
|
|
@ -10,10 +10,10 @@ from homeassistant.const import (
|
|||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import callback, State, CoreState
|
||||
from homeassistant.core import CoreState, State, callback
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.components.rflink.test_init import mock_rflink
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue