Move imports in hue component (#28121)
This commit is contained in:
parent
25fd930d67
commit
8bdec13bad
6 changed files with 48 additions and 48 deletions
|
@ -8,11 +8,11 @@ from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_FILENAME, CONF_HOST
|
from homeassistant.const import CONF_FILENAME, CONF_HOST
|
||||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||||
|
|
||||||
from .const import DOMAIN
|
|
||||||
from .bridge import HueBridge
|
from .bridge import HueBridge
|
||||||
|
from .config_flow import (
|
||||||
# Loading the config flow file will register the flow
|
configured_hosts,
|
||||||
from .config_flow import configured_hosts
|
) # Loading the config flow file will register the flow
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,31 @@
|
||||||
"""Hue binary sensor entities."""
|
"""Hue binary sensor entities."""
|
||||||
|
|
||||||
|
from aiohue.sensors import TYPE_ZLL_PRESENCE
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDevice,
|
|
||||||
DEVICE_CLASS_MOTION,
|
DEVICE_CLASS_MOTION,
|
||||||
|
BinarySensorDevice,
|
||||||
)
|
)
|
||||||
from homeassistant.components.hue.sensor_base import (
|
from homeassistant.components.hue.sensor_base import (
|
||||||
GenericZLLSensor,
|
GenericZLLSensor,
|
||||||
|
SensorManager,
|
||||||
async_setup_entry as shared_async_setup_entry,
|
async_setup_entry as shared_async_setup_entry,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
PRESENCE_NAME_FORMAT = "{} motion"
|
PRESENCE_NAME_FORMAT = "{} motion"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Defer binary sensor setup to the shared sensor module."""
|
"""Defer binary sensor setup to the shared sensor module."""
|
||||||
|
SensorManager.sensor_config_map.update(
|
||||||
|
{
|
||||||
|
TYPE_ZLL_PRESENCE: {
|
||||||
|
"binary": True,
|
||||||
|
"name_format": PRESENCE_NAME_FORMAT,
|
||||||
|
"class": HuePresence,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
await shared_async_setup_entry(hass, config_entry, async_add_entities, binary=True)
|
await shared_async_setup_entry(hass, config_entry, async_add_entities, binary=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Helper functions for Philips Hue."""
|
"""Helper functions for Philips Hue."""
|
||||||
from homeassistant.helpers.entity_registry import async_get_registry as get_ent_reg
|
|
||||||
from homeassistant.helpers.device_registry import async_get_registry as get_dev_reg
|
from homeassistant.helpers.device_registry import async_get_registry as get_dev_reg
|
||||||
|
from homeassistant.helpers.entity_registry import async_get_registry as get_ent_reg
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from time import monotonic
|
|
||||||
import random
|
import random
|
||||||
|
from time import monotonic
|
||||||
|
|
||||||
import aiohue
|
import aiohue
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
@ -14,21 +14,22 @@ from homeassistant.components.light import (
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_FLASH,
|
ATTR_FLASH,
|
||||||
ATTR_TRANSITION,
|
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
|
ATTR_TRANSITION,
|
||||||
EFFECT_COLORLOOP,
|
EFFECT_COLORLOOP,
|
||||||
EFFECT_RANDOM,
|
EFFECT_RANDOM,
|
||||||
FLASH_LONG,
|
FLASH_LONG,
|
||||||
FLASH_SHORT,
|
FLASH_SHORT,
|
||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
|
SUPPORT_COLOR,
|
||||||
SUPPORT_COLOR_TEMP,
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_EFFECT,
|
||||||
SUPPORT_FLASH,
|
SUPPORT_FLASH,
|
||||||
SUPPORT_COLOR,
|
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
Light,
|
Light,
|
||||||
)
|
)
|
||||||
from homeassistant.util import color
|
from homeassistant.util import color
|
||||||
|
|
||||||
from .helpers import remove_devices
|
from .helpers import remove_devices
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=5)
|
SCAN_INTERVAL = timedelta(seconds=5)
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
"""Hue sensor entities."""
|
"""Hue sensor entities."""
|
||||||
|
from aiohue.sensors import TYPE_ZLL_LIGHTLEVEL, TYPE_ZLL_TEMPERATURE
|
||||||
|
|
||||||
|
from homeassistant.components.hue.sensor_base import (
|
||||||
|
GenericZLLSensor,
|
||||||
|
SensorManager,
|
||||||
|
async_setup_entry as shared_async_setup_entry,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DEVICE_CLASS_ILLUMINANCE,
|
DEVICE_CLASS_ILLUMINANCE,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.components.hue.sensor_base import (
|
|
||||||
GenericZLLSensor,
|
|
||||||
async_setup_entry as shared_async_setup_entry,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
LIGHT_LEVEL_NAME_FORMAT = "{} light level"
|
LIGHT_LEVEL_NAME_FORMAT = "{} light level"
|
||||||
TEMPERATURE_NAME_FORMAT = "{} temperature"
|
TEMPERATURE_NAME_FORMAT = "{} temperature"
|
||||||
|
@ -17,6 +19,20 @@ TEMPERATURE_NAME_FORMAT = "{} temperature"
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Defer sensor setup to the shared sensor module."""
|
"""Defer sensor setup to the shared sensor module."""
|
||||||
|
SensorManager.sensor_config_map.update(
|
||||||
|
{
|
||||||
|
TYPE_ZLL_LIGHTLEVEL: {
|
||||||
|
"binary": False,
|
||||||
|
"name_format": LIGHT_LEVEL_NAME_FORMAT,
|
||||||
|
"class": HueLightLevel,
|
||||||
|
},
|
||||||
|
TYPE_ZLL_TEMPERATURE: {
|
||||||
|
"binary": False,
|
||||||
|
"name_format": TEMPERATURE_NAME_FORMAT,
|
||||||
|
"class": HueTemperature,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
await shared_async_setup_entry(hass, config_entry, async_add_entities, binary=False)
|
await shared_async_setup_entry(hass, config_entry, async_add_entities, binary=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
|
|
||||||
|
from aiohue import AiohueException
|
||||||
|
from aiohue.sensors import TYPE_ZLL_PRESENCE
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
|
||||||
from homeassistant.components import hue
|
from homeassistant.components import hue
|
||||||
|
@ -53,41 +55,12 @@ class SensorManager:
|
||||||
|
|
||||||
def __init__(self, hass, bridge, config_entry):
|
def __init__(self, hass, bridge, config_entry):
|
||||||
"""Initialize the sensor manager."""
|
"""Initialize the sensor manager."""
|
||||||
import aiohue
|
|
||||||
from .binary_sensor import HuePresence, PRESENCE_NAME_FORMAT
|
|
||||||
from .sensor import (
|
|
||||||
HueLightLevel,
|
|
||||||
HueTemperature,
|
|
||||||
LIGHT_LEVEL_NAME_FORMAT,
|
|
||||||
TEMPERATURE_NAME_FORMAT,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.bridge = bridge
|
self.bridge = bridge
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
self._component_add_entities = {}
|
self._component_add_entities = {}
|
||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
self.sensor_config_map.update(
|
|
||||||
{
|
|
||||||
aiohue.sensors.TYPE_ZLL_LIGHTLEVEL: {
|
|
||||||
"binary": False,
|
|
||||||
"name_format": LIGHT_LEVEL_NAME_FORMAT,
|
|
||||||
"class": HueLightLevel,
|
|
||||||
},
|
|
||||||
aiohue.sensors.TYPE_ZLL_TEMPERATURE: {
|
|
||||||
"binary": False,
|
|
||||||
"name_format": TEMPERATURE_NAME_FORMAT,
|
|
||||||
"class": HueTemperature,
|
|
||||||
},
|
|
||||||
aiohue.sensors.TYPE_ZLL_PRESENCE: {
|
|
||||||
"binary": True,
|
|
||||||
"name_format": PRESENCE_NAME_FORMAT,
|
|
||||||
"class": HuePresence,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
def register_component(self, binary, async_add_entities):
|
def register_component(self, binary, async_add_entities):
|
||||||
"""Register async_add_entities methods for components."""
|
"""Register async_add_entities methods for components."""
|
||||||
self._component_add_entities[binary] = async_add_entities
|
self._component_add_entities[binary] = async_add_entities
|
||||||
|
@ -117,15 +90,13 @@ class SensorManager:
|
||||||
|
|
||||||
async def async_update_items(self):
|
async def async_update_items(self):
|
||||||
"""Update sensors from the bridge."""
|
"""Update sensors from the bridge."""
|
||||||
import aiohue
|
|
||||||
|
|
||||||
api = self.bridge.api.sensors
|
api = self.bridge.api.sensors
|
||||||
|
|
||||||
try:
|
try:
|
||||||
start = monotonic()
|
start = monotonic()
|
||||||
with async_timeout.timeout(4):
|
with async_timeout.timeout(4):
|
||||||
await api.update()
|
await api.update()
|
||||||
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
|
except (asyncio.TimeoutError, AiohueException) as err:
|
||||||
_LOGGER.debug("Failed to fetch sensor: %s", err)
|
_LOGGER.debug("Failed to fetch sensor: %s", err)
|
||||||
|
|
||||||
if not self.bridge.available:
|
if not self.bridge.available:
|
||||||
|
@ -164,7 +135,7 @@ class SensorManager:
|
||||||
# finding the remaining ones that may or may not be related to the
|
# finding the remaining ones that may or may not be related to the
|
||||||
# presence sensors.
|
# presence sensors.
|
||||||
for item_id in api:
|
for item_id in api:
|
||||||
if api[item_id].type != aiohue.sensors.TYPE_ZLL_PRESENCE:
|
if api[item_id].type != TYPE_ZLL_PRESENCE:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
primary_sensor_devices[_device_id(api[item_id])] = api[item_id]
|
primary_sensor_devices[_device_id(api[item_id])] = api[item_id]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue