Revert "Allow non-async functions in device automation (#72147)" (#72909)

This commit is contained in:
epenet 2022-06-03 08:00:47 +02:00 committed by GitHub
parent 3a8a816584
commit fe1c3d3be8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 38 deletions

View File

@ -189,22 +189,6 @@ def _async_set_entity_device_automation_metadata(
automation["metadata"]["secondary"] = bool(entry.entity_category or entry.hidden_by) automation["metadata"]["secondary"] = bool(entry.entity_category or entry.hidden_by)
async def _async_get_automation_for_device(
hass: HomeAssistant,
platform: DeviceAutomationPlatformType,
function_name: str,
device_id: str,
) -> list[dict[str, Any]]:
"""List device automations."""
automations = getattr(platform, function_name)(hass, device_id)
if asyncio.iscoroutine(automations):
# Using a coroutine to get device automations is deprecated
# enable warning when core is fully migrated
# then remove in Home Assistant Core xxxx.xx
return await automations # type: ignore[no-any-return]
return automations # type: ignore[no-any-return]
async def _async_get_device_automations_from_domain( async def _async_get_device_automations_from_domain(
hass: HomeAssistant, hass: HomeAssistant,
domain: str, domain: str,
@ -224,7 +208,7 @@ async def _async_get_device_automations_from_domain(
return await asyncio.gather( # type: ignore[no-any-return] return await asyncio.gather( # type: ignore[no-any-return]
*( *(
_async_get_automation_for_device(hass, platform, function_name, device_id) getattr(platform, function_name)(hass, device_id)
for device_id in device_ids for device_id in device_ids
), ),
return_exceptions=return_exceptions, return_exceptions=return_exceptions,
@ -310,12 +294,7 @@ async def _async_get_device_automation_capabilities(
return {} return {}
try: try:
capabilities = getattr(platform, function_name)(hass, automation) capabilities = await getattr(platform, function_name)(hass, automation)
if asyncio.iscoroutine(capabilities):
# Using a coroutine to get device automation capabitilites is deprecated
# enable warning when core is fully migrated
# then remove in Home Assistant Core xxxx.xx
capabilities = await capabilities
except InvalidDeviceAutomationConfig: except InvalidDeviceAutomationConfig:
return {} return {}

View File

@ -1,7 +1,6 @@
"""Device action validator.""" """Device action validator."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Awaitable
from typing import Any, Protocol, cast from typing import Any, Protocol, cast
import voluptuous as vol import voluptuous as vol
@ -36,14 +35,14 @@ class DeviceAutomationActionProtocol(Protocol):
) -> None: ) -> None:
"""Execute a device action.""" """Execute a device action."""
def async_get_action_capabilities( async def async_get_action_capabilities(
self, hass: HomeAssistant, config: ConfigType self, hass: HomeAssistant, config: ConfigType
) -> dict[str, vol.Schema] | Awaitable[dict[str, vol.Schema]]: ) -> dict[str, vol.Schema]:
"""List action capabilities.""" """List action capabilities."""
def async_get_actions( async def async_get_actions(
self, hass: HomeAssistant, device_id: str self, hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]] | Awaitable[list[dict[str, Any]]]: ) -> list[dict[str, Any]]:
"""List actions.""" """List actions."""

View File

@ -1,7 +1,6 @@
"""Validate device conditions.""" """Validate device conditions."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Awaitable
from typing import TYPE_CHECKING, Any, Protocol, cast from typing import TYPE_CHECKING, Any, Protocol, cast
import voluptuous as vol import voluptuous as vol
@ -36,14 +35,14 @@ class DeviceAutomationConditionProtocol(Protocol):
) -> condition.ConditionCheckerType: ) -> condition.ConditionCheckerType:
"""Evaluate state based on configuration.""" """Evaluate state based on configuration."""
def async_get_condition_capabilities( async def async_get_condition_capabilities(
self, hass: HomeAssistant, config: ConfigType self, hass: HomeAssistant, config: ConfigType
) -> dict[str, vol.Schema] | Awaitable[dict[str, vol.Schema]]: ) -> dict[str, vol.Schema]:
"""List condition capabilities.""" """List condition capabilities."""
def async_get_conditions( async def async_get_conditions(
self, hass: HomeAssistant, device_id: str self, hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]] | Awaitable[list[dict[str, Any]]]: ) -> list[dict[str, Any]]:
"""List conditions.""" """List conditions."""

View File

@ -1,7 +1,6 @@
"""Offer device oriented automation.""" """Offer device oriented automation."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Awaitable
from typing import Any, Protocol, cast from typing import Any, Protocol, cast
import voluptuous as vol import voluptuous as vol
@ -46,14 +45,14 @@ class DeviceAutomationTriggerProtocol(Protocol):
) -> CALLBACK_TYPE: ) -> CALLBACK_TYPE:
"""Attach a trigger.""" """Attach a trigger."""
def async_get_trigger_capabilities( async def async_get_trigger_capabilities(
self, hass: HomeAssistant, config: ConfigType self, hass: HomeAssistant, config: ConfigType
) -> dict[str, vol.Schema] | Awaitable[dict[str, vol.Schema]]: ) -> dict[str, vol.Schema]:
"""List trigger capabilities.""" """List trigger capabilities."""
def async_get_triggers( async def async_get_triggers(
self, hass: HomeAssistant, device_id: str self, hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]] | Awaitable[list[dict[str, Any]]]: ) -> list[dict[str, Any]]:
"""List triggers.""" """List triggers."""