Update homekit_controller import style (#25940)

This commit is contained in:
Jc2k 2019-08-14 17:14:15 +01:00 committed by Paulus Schoutsen
parent d8e2518e0d
commit 002f74c76b
9 changed files with 24 additions and 52 deletions

View File

@ -1,6 +1,9 @@
"""Support for Homekit device discovery.""" """Support for Homekit device discovery."""
import logging import logging
import homekit
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
@ -63,9 +66,6 @@ class HomeKitEntity(Entity):
def setup(self): def setup(self):
"""Configure an entity baed on its HomeKit characterstics metadata.""" """Configure an entity baed on its HomeKit characterstics metadata."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
accessories = self._accessory.accessories accessories = self._accessory.accessories
get_uuid = CharacteristicsTypes.get_uuid get_uuid = CharacteristicsTypes.get_uuid
@ -95,9 +95,6 @@ class HomeKitEntity(Entity):
def _setup_characteristic(self, char): def _setup_characteristic(self, char):
"""Configure an entity based on a HomeKit characteristics metadata.""" """Configure an entity based on a HomeKit characteristics metadata."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
# Build up a list of (aid, iid) tuples to poll on update() # Build up a list of (aid, iid) tuples to poll on update()
self.pollable_characteristics.append((self._aid, char["iid"])) self.pollable_characteristics.append((self._aid, char["iid"]))
@ -211,9 +208,6 @@ async def async_setup_entry(hass, entry):
async def async_setup(hass, config): async def async_setup(hass, config):
"""Set up for Homekit devices.""" """Set up for Homekit devices."""
# pylint: disable=import-error
import homekit
map_storage = hass.data[ENTITY_MAP] = EntityMapStorage(hass) map_storage = hass.data[ENTITY_MAP] = EntityMapStorage(hass)
await map_storage.async_initialize() await map_storage.async_initialize()

View File

@ -1,6 +1,8 @@
"""Support for Homekit Alarm Control Panel.""" """Support for Homekit Alarm Control Panel."""
import logging import logging
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.alarm_control_panel import AlarmControlPanel from homeassistant.components.alarm_control_panel import AlarmControlPanel
from homeassistant.const import ( from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_BATTERY_LEVEL,
@ -64,9 +66,6 @@ class HomeKitAlarmControlPanel(HomeKitEntity, AlarmControlPanel):
def get_characteristic_types(self): def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about.""" """Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [ return [
CharacteristicsTypes.SECURITY_SYSTEM_STATE_CURRENT, CharacteristicsTypes.SECURITY_SYSTEM_STATE_CURRENT,
CharacteristicsTypes.SECURITY_SYSTEM_STATE_TARGET, CharacteristicsTypes.SECURITY_SYSTEM_STATE_TARGET,

View File

@ -1,6 +1,8 @@
"""Support for Homekit climate devices.""" """Support for Homekit climate devices."""
import logging import logging
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.climate import ( from homeassistant.components.climate import (
ClimateDevice, ClimateDevice,
DEFAULT_MIN_HUMIDITY, DEFAULT_MIN_HUMIDITY,
@ -84,9 +86,6 @@ class HomeKitClimateDevice(HomeKitEntity, ClimateDevice):
def get_characteristic_types(self): def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about.""" """Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [ return [
CharacteristicsTypes.HEATING_COOLING_CURRENT, CharacteristicsTypes.HEATING_COOLING_CURRENT,
CharacteristicsTypes.HEATING_COOLING_TARGET, CharacteristicsTypes.HEATING_COOLING_TARGET,

View File

@ -3,6 +3,7 @@ import os
import json import json
import logging import logging
import homekit
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
@ -62,8 +63,6 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
def __init__(self): def __init__(self):
"""Initialize the homekit_controller flow.""" """Initialize the homekit_controller flow."""
import homekit # pylint: disable=import-error
self.model = None self.model = None
self.hkid = None self.hkid = None
self.devices = {} self.devices = {}
@ -224,8 +223,6 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
async def async_step_pair(self, pair_info=None): async def async_step_pair(self, pair_info=None):
"""Pair with a new HomeKit accessory.""" """Pair with a new HomeKit accessory."""
import homekit # pylint: disable=import-error
# If async_step_pair is called with no pairing code then we do the M1 # If async_step_pair is called with no pairing code then we do the M1
# phase of pairing. If this is successful the device enters pairing # phase of pairing. If this is successful the device enters pairing
# mode. # mode.

View File

@ -3,6 +3,14 @@ import asyncio
import datetime import datetime
import logging import logging
from homekit.exceptions import (
AccessoryDisconnectedError,
AccessoryNotFoundError,
EncryptionError,
)
from homekit.model.services import ServicesTypes
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from .const import DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, ENTITY_MAP from .const import DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, ENTITY_MAP
@ -16,10 +24,6 @@ _LOGGER = logging.getLogger(__name__)
def get_accessory_information(accessory): def get_accessory_information(accessory):
"""Obtain the accessory information service of a HomeKit device.""" """Obtain the accessory information service of a HomeKit device."""
# pylint: disable=import-error
from homekit.model.services import ServicesTypes
from homekit.model.characteristics import CharacteristicsTypes
result = {} result = {}
for service in accessory["services"]: for service in accessory["services"]:
stype = service["type"].upper() stype = service["type"].upper()
@ -163,9 +167,6 @@ class HKDevice:
async def async_refresh_entity_map(self, config_num): async def async_refresh_entity_map(self, config_num):
"""Handle setup of a HomeKit accessory.""" """Handle setup of a HomeKit accessory."""
# pylint: disable=import-error
from homekit.exceptions import AccessoryDisconnectedError
try: try:
async with self.pairing_lock: async with self.pairing_lock:
self.accessories = await self.hass.async_add_executor_job( self.accessories = await self.hass.async_add_executor_job(
@ -205,8 +206,6 @@ class HKDevice:
self._add_new_entities(self.listeners) self._add_new_entities(self.listeners)
def _add_new_entities(self, callbacks): def _add_new_entities(self, callbacks):
from homekit.model.services import ServicesTypes
for accessory in self.accessories: for accessory in self.accessories:
aid = accessory["aid"] aid = accessory["aid"]
for service in accessory["services"]: for service in accessory["services"]:
@ -225,8 +224,6 @@ class HKDevice:
def async_load_platforms(self): def async_load_platforms(self):
"""Load any platforms needed by this HomeKit device.""" """Load any platforms needed by this HomeKit device."""
from homekit.model.services import ServicesTypes
for accessory in self.accessories: for accessory in self.accessories:
for service in accessory["services"]: for service in accessory["services"]:
stype = ServicesTypes.get_short(service["type"].upper()) stype = ServicesTypes.get_short(service["type"].upper())
@ -246,13 +243,6 @@ class HKDevice:
async def async_update(self, now=None): async def async_update(self, now=None):
"""Poll state of all entities attached to this bridge/accessory.""" """Poll state of all entities attached to this bridge/accessory."""
# pylint: disable=import-error
from homekit.exceptions import (
AccessoryDisconnectedError,
AccessoryNotFoundError,
EncryptionError,
)
if not self.pollable_characteristics: if not self.pollable_characteristics:
_LOGGER.debug("HomeKit connection not polling any characteristics.") _LOGGER.debug("HomeKit connection not polling any characteristics.")
return return

View File

@ -1,6 +1,8 @@
"""Support for Homekit covers.""" """Support for Homekit covers."""
import logging import logging
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_POSITION, ATTR_POSITION,
ATTR_TILT_POSITION, ATTR_TILT_POSITION,
@ -76,9 +78,6 @@ class HomeKitGarageDoorCover(HomeKitEntity, CoverDevice):
def get_characteristic_types(self): def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about.""" """Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [ return [
CharacteristicsTypes.DOOR_STATE_CURRENT, CharacteristicsTypes.DOOR_STATE_CURRENT,
CharacteristicsTypes.DOOR_STATE_TARGET, CharacteristicsTypes.DOOR_STATE_TARGET,
@ -154,9 +153,6 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
def get_characteristic_types(self): def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about.""" """Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [ return [
CharacteristicsTypes.POSITION_STATE, CharacteristicsTypes.POSITION_STATE,
CharacteristicsTypes.POSITION_CURRENT, CharacteristicsTypes.POSITION_CURRENT,

View File

@ -1,6 +1,8 @@
"""Support for Homekit lights.""" """Support for Homekit lights."""
import logging import logging
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP, ATTR_COLOR_TEMP,
@ -50,9 +52,6 @@ class HomeKitLight(HomeKitEntity, Light):
def get_characteristic_types(self): def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about.""" """Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [ return [
CharacteristicsTypes.ON, CharacteristicsTypes.ON,
CharacteristicsTypes.BRIGHTNESS, CharacteristicsTypes.BRIGHTNESS,

View File

@ -1,6 +1,8 @@
"""Support for HomeKit Controller locks.""" """Support for HomeKit Controller locks."""
import logging import logging
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.lock import LockDevice from homeassistant.components.lock import LockDevice
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_LOCKED, STATE_UNLOCKED from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_LOCKED, STATE_UNLOCKED
@ -46,9 +48,6 @@ class HomeKitLock(HomeKitEntity, LockDevice):
def get_characteristic_types(self): def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about.""" """Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [ return [
CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE, CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE,
CharacteristicsTypes.LOCK_MECHANISM_TARGET_STATE, CharacteristicsTypes.LOCK_MECHANISM_TARGET_STATE,

View File

@ -1,6 +1,8 @@
"""Support for Homekit switches.""" """Support for Homekit switches."""
import logging import logging
from homekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.switch import SwitchDevice from homeassistant.components.switch import SwitchDevice
from . import KNOWN_DEVICES, HomeKitEntity from . import KNOWN_DEVICES, HomeKitEntity
@ -41,9 +43,6 @@ class HomeKitSwitch(HomeKitEntity, SwitchDevice):
def get_characteristic_types(self): def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about.""" """Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [CharacteristicsTypes.ON, CharacteristicsTypes.OUTLET_IN_USE] return [CharacteristicsTypes.ON, CharacteristicsTypes.OUTLET_IN_USE]
def _update_on(self, value): def _update_on(self, value):