mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 19:09:32 +00:00
Move imports to top level in websocket_api commands
This commit is contained in:
@@ -41,8 +41,11 @@ from homeassistant.helpers import (
|
|||||||
template,
|
template,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.condition import (
|
from homeassistant.helpers.condition import (
|
||||||
|
async_from_config as async_condition_from_config,
|
||||||
async_get_all_descriptions as async_get_all_condition_descriptions,
|
async_get_all_descriptions as async_get_all_condition_descriptions,
|
||||||
async_subscribe_platform_events as async_subscribe_condition_platform_events,
|
async_subscribe_platform_events as async_subscribe_condition_platform_events,
|
||||||
|
async_validate_condition_config,
|
||||||
|
async_validate_conditions_config,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entityfilter import (
|
from homeassistant.helpers.entityfilter import (
|
||||||
@@ -66,7 +69,9 @@ from homeassistant.helpers.service import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.trigger import (
|
from homeassistant.helpers.trigger import (
|
||||||
async_get_all_descriptions as async_get_all_trigger_descriptions,
|
async_get_all_descriptions as async_get_all_trigger_descriptions,
|
||||||
|
async_initialize_triggers,
|
||||||
async_subscribe_platform_events as async_subscribe_trigger_platform_events,
|
async_subscribe_platform_events as async_subscribe_trigger_platform_events,
|
||||||
|
async_validate_trigger_config,
|
||||||
)
|
)
|
||||||
from homeassistant.loader import (
|
from homeassistant.loader import (
|
||||||
IntegrationNotFound,
|
IntegrationNotFound,
|
||||||
@@ -885,10 +890,7 @@ async def handle_subscribe_trigger(
|
|||||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle subscribe trigger command."""
|
"""Handle subscribe trigger command."""
|
||||||
# Circular dep
|
trigger_config = await async_validate_trigger_config(hass, msg["trigger"])
|
||||||
from homeassistant.helpers import trigger # noqa: PLC0415
|
|
||||||
|
|
||||||
trigger_config = await trigger.async_validate_trigger_config(hass, msg["trigger"])
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def forward_triggers(
|
def forward_triggers(
|
||||||
@@ -905,7 +907,7 @@ async def handle_subscribe_trigger(
|
|||||||
)
|
)
|
||||||
|
|
||||||
connection.subscriptions[msg["id"]] = (
|
connection.subscriptions[msg["id"]] = (
|
||||||
await trigger.async_initialize_triggers(
|
await async_initialize_triggers(
|
||||||
hass,
|
hass,
|
||||||
trigger_config,
|
trigger_config,
|
||||||
forward_triggers,
|
forward_triggers,
|
||||||
@@ -935,13 +937,10 @@ async def handle_test_condition(
|
|||||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle test condition command."""
|
"""Handle test condition command."""
|
||||||
# Circular dep
|
|
||||||
from homeassistant.helpers import condition # noqa: PLC0415
|
|
||||||
|
|
||||||
# Do static + dynamic validation of the condition
|
# Do static + dynamic validation of the condition
|
||||||
config = await condition.async_validate_condition_config(hass, msg["condition"])
|
config = await async_validate_condition_config(hass, msg["condition"])
|
||||||
# Test the condition
|
# Test the condition
|
||||||
check_condition = await condition.async_from_config(hass, config)
|
check_condition = await async_condition_from_config(hass, config)
|
||||||
connection.send_result(
|
connection.send_result(
|
||||||
msg["id"], {"result": check_condition(hass, msg.get("variables"))}
|
msg["id"], {"result": check_condition(hass, msg.get("variables"))}
|
||||||
)
|
)
|
||||||
@@ -1028,16 +1027,16 @@ async def handle_validate_config(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Handle validate config command."""
|
"""Handle validate config command."""
|
||||||
# Circular dep
|
# Circular dep
|
||||||
from homeassistant.helpers import condition, script, trigger # noqa: PLC0415
|
from homeassistant.helpers import script # noqa: PLC0415
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
for key, schema, validator in (
|
for key, schema, validator in (
|
||||||
("triggers", cv.TRIGGER_SCHEMA, trigger.async_validate_trigger_config),
|
("triggers", cv.TRIGGER_SCHEMA, async_validate_trigger_config),
|
||||||
(
|
(
|
||||||
"conditions",
|
"conditions",
|
||||||
cv.CONDITIONS_SCHEMA,
|
cv.CONDITIONS_SCHEMA,
|
||||||
condition.async_validate_conditions_config,
|
async_validate_conditions_config,
|
||||||
),
|
),
|
||||||
("actions", cv.SCRIPT_SCHEMA, script.async_validate_actions_config),
|
("actions", cv.SCRIPT_SCHEMA, script.async_validate_actions_config),
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user