Do async_setup_platform in background (#36244)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
1 parent
d488c779fc
commit
276f3afb00
161 files changed
+1184
-305
No files matched your search
@@ -34,6 +34,7 @@ from homeassistant.components.stream.const import (
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_FILENAME,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
@@ -48,7 +49,6 @@ from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.network import get_url
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.setup import async_when_setup
|
||||
|
||||
from .const import DATA_CAMERA_PREFS, DOMAIN
|
||||
from .prefs import CameraPreferences
|
||||
@@ -259,7 +259,7 @@ async def async_setup(hass, config):
|
||||
|
||||
await component.async_setup(config)
|
||||
|
||||
async def preload_stream(hass, _):
|
||||
async def preload_stream(_):
|
||||
for camera in component.entities:
|
||||
camera_prefs = prefs.get(camera.entity_id)
|
||||
if not camera_prefs.preload_stream:
|
||||
@@ -273,7 +273,7 @@ async def async_setup(hass, config):
|
||||
|
||||
request_stream(hass, source, keepalive=True, options=camera.stream_options)
|
||||
|
||||
async_when_setup(hass, DOMAIN_STREAM, preload_stream)
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, preload_stream)
|
||||
|
||||
@callback
|
||||
def update_tokens(time):
|
||||
|
||||
@@ -11,6 +11,7 @@ from homeassistant.components.light import (
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_HOME,
|
||||
@@ -59,17 +60,35 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the triggers to control lights based on device presence."""
|
||||
conf = config[DOMAIN]
|
||||
disable_turn_off = conf[CONF_DISABLE_TURN_OFF]
|
||||
light_group = conf.get(CONF_LIGHT_GROUP)
|
||||
light_profile = conf[CONF_LIGHT_PROFILE]
|
||||
device_group = conf.get(CONF_DEVICE_GROUP)
|
||||
|
||||
async def activate_on_start(_):
|
||||
"""Activate automation."""
|
||||
await activate_automation(
|
||||
hass, device_group, light_group, light_profile, disable_turn_off
|
||||
)
|
||||
|
||||
if hass.is_running:
|
||||
await activate_on_start(None)
|
||||
else:
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, activate_on_start)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def activate_automation(
|
||||
hass, device_group, light_group, light_profile, disable_turn_off
|
||||
):
|
||||
"""Activate the automation."""
|
||||
logger = logging.getLogger(__name__)
|
||||
device_tracker = hass.components.device_tracker
|
||||
group = hass.components.group
|
||||
light = hass.components.light
|
||||
person = hass.components.person
|
||||
conf = config[DOMAIN]
|
||||
disable_turn_off = conf[CONF_DISABLE_TURN_OFF]
|
||||
light_group = conf.get(CONF_LIGHT_GROUP)
|
||||
light_profile = conf[CONF_LIGHT_PROFILE]
|
||||
|
||||
device_group = conf.get(CONF_DEVICE_GROUP)
|
||||
|
||||
if device_group is None:
|
||||
device_entity_ids = hass.states.async_entity_ids(device_tracker.DOMAIN)
|
||||
@@ -79,7 +98,7 @@ async def async_setup(hass, config):
|
||||
|
||||
if not device_entity_ids:
|
||||
logger.error("No devices found to track")
|
||||
return False
|
||||
return
|
||||
|
||||
# Get the light IDs from the specified group
|
||||
if light_group is None:
|
||||
@@ -89,7 +108,7 @@ async def async_setup(hass, config):
|
||||
|
||||
if not light_ids:
|
||||
logger.error("No lights found to turn on")
|
||||
return False
|
||||
return
|
||||
|
||||
@callback
|
||||
def anyone_home():
|
||||
@@ -219,7 +238,7 @@ async def async_setup(hass, config):
|
||||
)
|
||||
|
||||
if disable_turn_off:
|
||||
return True
|
||||
return
|
||||
|
||||
@callback
|
||||
def turn_off_lights_when_all_leave(entity, old_state, new_state):
|
||||
@@ -247,4 +266,4 @@ async def async_setup(hass, config):
|
||||
STATE_NOT_HOME,
|
||||
)
|
||||
|
||||
return True
|
||||
return
|
||||
@@ -24,7 +24,7 @@ class APICount(Entity):
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the API count."""
|
||||
self.count = None
|
||||
self.count = 0
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Added to hass."""
|
||||
@@ -38,7 +38,6 @@ class APICount(Entity):
|
||||
SIGNAL_WEBSOCKET_DISCONNECTED, self._update_count
|
||||
)
|
||||
)
|
||||
self._update_count()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
||||
@@ -291,7 +291,7 @@ class MiroboVacuum(StateVacuumEntity):
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Get the list of available fan speed steps of the vacuum cleaner."""
|
||||
return list(self._fan_speeds)
|
||||
return list(self._fan_speeds) if self._fan_speeds else []
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
||||
Reference in new issue
Block a user