Move imports in mitemp_bt component (#28026)
* Move imports in mitemp_bt component * Fix pylint
This commit is contained in:
parent
a8c6b04906
commit
1a48c347a4
1 changed files with 14 additions and 17 deletions
|
@ -1,21 +1,30 @@
|
|||
"""Support for Xiaomi Mi Temp BLE environmental sensor."""
|
||||
import logging
|
||||
|
||||
import btlewrap
|
||||
from btlewrap.base import BluetoothBackendException
|
||||
from mitemp_bt import mitemp_bt_poller
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import (
|
||||
CONF_FORCE_UPDATE,
|
||||
CONF_MAC,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_MAC,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
try:
|
||||
import bluepy.btle # noqa: F401 pylint: disable=unused-import
|
||||
|
||||
BACKEND = btlewrap.BluepyBackend
|
||||
except ImportError:
|
||||
BACKEND = btlewrap.GatttoolBackend
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -60,17 +69,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the MiTempBt sensor."""
|
||||
from mitemp_bt import mitemp_bt_poller
|
||||
|
||||
try:
|
||||
import bluepy.btle # noqa: F401 pylint: disable=unused-import
|
||||
from btlewrap import BluepyBackend
|
||||
|
||||
backend = BluepyBackend
|
||||
except ImportError:
|
||||
from btlewrap import GatttoolBackend
|
||||
|
||||
backend = GatttoolBackend
|
||||
backend = BACKEND
|
||||
_LOGGER.debug("MiTempBt is using %s backend.", backend.__name__)
|
||||
|
||||
cache = config.get(CONF_CACHE)
|
||||
|
@ -152,8 +151,6 @@ class MiTempBtSensor(Entity):
|
|||
|
||||
This uses a rolling median over 3 values to filter out outliers.
|
||||
"""
|
||||
from btlewrap.base import BluetoothBackendException
|
||||
|
||||
try:
|
||||
_LOGGER.debug("Polling data for %s", self.name)
|
||||
data = self.poller.parameter_value(self.parameter)
|
||||
|
|
Loading…
Add table
Reference in a new issue