import abc
import logging
import voluptuous as vol
from . import selector as selector
from .automation import get_absolute_description_key as get_absolute_description_key, get_relative_description_key as get_relative_description_key, move_options_fields_to_top_level as move_options_fields_to_top_level
from .integration_platform import async_process_integration_platforms as async_process_integration_platforms
from .selector import TargetSelector as TargetSelector
from .target import TargetSelection as TargetSelection, async_extract_referenced_entity_ids as async_extract_referenced_entity_ids
from .template import Template as Template, render_complex as render_complex
from .trace import TraceElement as TraceElement, trace_append_element as trace_append_element, trace_path as trace_path, trace_path_get as trace_path_get, trace_stack_cv as trace_stack_cv, trace_stack_pop as trace_stack_pop, trace_stack_push as trace_stack_push, trace_stack_top as trace_stack_top
from .typing import ConfigType as ConfigType, TemplateVarsType as TemplateVarsType
from _typeshed import Incomplete
from collections.abc import Callable, Container, Coroutine, Generator, Iterable
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import time as dt_time, timedelta
from homeassistant.const import ATTR_DEVICE_CLASS as ATTR_DEVICE_CLASS, CONF_ABOVE as CONF_ABOVE, CONF_AFTER as CONF_AFTER, CONF_ATTRIBUTE as CONF_ATTRIBUTE, CONF_BEFORE as CONF_BEFORE, CONF_BELOW as CONF_BELOW, CONF_CONDITION as CONF_CONDITION, CONF_DEVICE_ID as CONF_DEVICE_ID, CONF_ENABLED as CONF_ENABLED, CONF_ENTITY_ID as CONF_ENTITY_ID, CONF_FOR as CONF_FOR, CONF_ID as CONF_ID, CONF_MATCH as CONF_MATCH, CONF_OPTIONS as CONF_OPTIONS, CONF_SELECTOR as CONF_SELECTOR, CONF_STATE as CONF_STATE, CONF_TARGET as CONF_TARGET, CONF_VALUE_TEMPLATE as CONF_VALUE_TEMPLATE, CONF_WEEKDAY as CONF_WEEKDAY, ENTITY_MATCH_ALL as ENTITY_MATCH_ALL, ENTITY_MATCH_ANY as ENTITY_MATCH_ANY, STATE_UNAVAILABLE as STATE_UNAVAILABLE, STATE_UNKNOWN as STATE_UNKNOWN, WEEKDAYS as WEEKDAYS
from homeassistant.core import HomeAssistant as HomeAssistant, State as State, callback as callback, split_entity_id as split_entity_id
from homeassistant.exceptions import ConditionError as ConditionError, ConditionErrorContainer as ConditionErrorContainer, ConditionErrorIndex as ConditionErrorIndex, ConditionErrorMessage as ConditionErrorMessage, HomeAssistantError as HomeAssistantError, TemplateError as TemplateError
from homeassistant.loader import Integration as Integration, IntegrationNotFound as IntegrationNotFound, async_get_integration as async_get_integration, async_get_integrations as async_get_integrations
from homeassistant.util.async_ import run_callback_threadsafe as run_callback_threadsafe
from homeassistant.util.hass_dict import HassKey as HassKey
from homeassistant.util.yaml import load_yaml_dict as load_yaml_dict
from typing import Any, Final, Literal, Protocol, TypedDict, Unpack, overload, override

ASYNC_FROM_CONFIG_FORMAT: str
FROM_CONFIG_FORMAT: str
VALIDATE_CONFIG_FORMAT: str
_LOGGER: Incomplete
_PLATFORM_ALIASES: dict[str | None, str | None]
INPUT_ENTITY_ID: Incomplete
CONDITION_DESCRIPTION_CACHE: HassKey[dict[str, dict[str, Any] | None]]
CONDITION_DISABLED_CONDITIONS: HassKey[set[str]]
CONDITION_PLATFORM_SUBSCRIPTIONS: HassKey[list[Callable[[set[str]], Coroutine[Any, Any, None]]]]
CONDITIONS: HassKey[dict[str, str]]
_FIELD_DESCRIPTION_SCHEMA: Incomplete
_CONDITION_DESCRIPTION_SCHEMA: Incomplete

def starts_with_dot(key: str) -> str: ...

_CONDITIONS_DESCRIPTION_SCHEMA: Incomplete

async def async_setup(hass: HomeAssistant) -> None: ...
@callback
def async_subscribe_platform_events(hass: HomeAssistant, on_event: Callable[[set[str]], Coroutine[Any, Any, None]]) -> Callable[[], None]: ...
async def _register_condition_platform(hass: HomeAssistant, integration_domain: str, platform: ConditionProtocol) -> None: ...

_CONDITION_BASE_SCHEMA: Incomplete
_CONDITION_SCHEMA: Incomplete

class Condition(abc.ABC, metaclass=abc.ABCMeta):
    _hass: HomeAssistant
    @classmethod
    async def async_validate_complete_config(cls, hass: HomeAssistant, complete_config: ConfigType) -> ConfigType: ...
    @classmethod
    @abc.abstractmethod
    async def async_validate_config(cls, hass: HomeAssistant, config: ConfigType) -> ConfigType: ...
    def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None: ...
    @abc.abstractmethod
    async def async_get_checker(self) -> ConditionChecker: ...

ATTR_BEHAVIOR: Final[str]
BEHAVIOR_ANY: Final[str]
BEHAVIOR_ALL: Final[str]
STATE_CONDITION_OPTIONS_SCHEMA: dict[vol.Marker, Any]
ENTITY_STATE_CONDITION_SCHEMA_ANY_ALL: Incomplete

class EntityConditionBase(Condition, metaclass=abc.ABCMeta):
    _domain: str
    _schema: vol.Schema
    @override
    @classmethod
    async def async_validate_config(cls, hass: HomeAssistant, config: ConfigType) -> ConfigType: ...
    _target_selection: Incomplete
    _behavior: Incomplete
    def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None: ...
    def entity_filter(self, entities: set[str]) -> set[str]: ...
    @abc.abstractmethod
    def is_valid_state(self, entity_state: State) -> bool: ...
    @override
    async def async_get_checker(self) -> ConditionChecker: ...

class EntityStateConditionBase(EntityConditionBase):
    _states: set[str]
    def is_valid_state(self, entity_state: State) -> bool: ...

def make_entity_state_condition(domain: str, states: str | set[str]) -> type[EntityStateConditionBase]: ...

class EntityStateAttributeConditionBase(EntityConditionBase):
    _attribute: str
    _attribute_states: set[str]
    def is_valid_state(self, entity_state: State) -> bool: ...

def make_entity_state_attribute_condition(domain: str, attribute: str, attribute_states: str | set[str]) -> type[EntityStateAttributeConditionBase]: ...

class ConditionProtocol(Protocol):
    async def async_get_conditions(self, hass: HomeAssistant) -> dict[str, type[Condition]]: ...

@dataclass(slots=True)
class ConditionConfig:
    options: dict[str, Any] | None = ...
    target: dict[str, Any] | None = ...

class ConditionCheckParams(TypedDict, total=False):
    variables: TemplateVarsType

class ConditionChecker(Protocol):
    def __call__(self, **kwargs: Unpack[ConditionCheckParams]) -> bool: ...
type ConditionCheckerType = Callable[[HomeAssistant, TemplateVarsType], bool]
type ConditionCheckerTypeOptional = Callable[[HomeAssistant, TemplateVarsType], bool | None]

def condition_trace_append(variables: TemplateVarsType, path: str) -> TraceElement: ...
def condition_trace_set_result(result: bool, **kwargs: Any) -> None: ...
def condition_trace_update_result(**kwargs: Any) -> None: ...
@contextmanager
def trace_condition(variables: TemplateVarsType) -> Generator[TraceElement]: ...
@overload
def trace_condition_function(condition: ConditionCheckerType) -> ConditionCheckerType: ...
@overload
def trace_condition_function(condition: ConditionCheckerTypeOptional) -> ConditionCheckerTypeOptional: ...
async def _async_get_condition_platform(hass: HomeAssistant, condition_key: str) -> tuple[str, ConditionProtocol | None]: ...
async def _async_get_checker(condition: Condition) -> ConditionCheckerType: ...
async def async_from_config(hass: HomeAssistant, config: ConfigType) -> ConditionCheckerTypeOptional: ...
async def async_and_from_config(hass: HomeAssistant, config: ConfigType) -> ConditionCheckerType: ...
async def async_or_from_config(hass: HomeAssistant, config: ConfigType) -> ConditionCheckerType: ...
async def async_not_from_config(hass: HomeAssistant, config: ConfigType) -> ConditionCheckerType: ...
def numeric_state(hass: HomeAssistant, entity: str | State | None, below: float | str | None = None, above: float | str | None = None, value_template: Template | None = None, variables: TemplateVarsType = None) -> bool: ...
def async_numeric_state(hass: HomeAssistant, entity: str | State | None, below: float | str | None = None, above: float | str | None = None, value_template: Template | None = None, variables: TemplateVarsType = None, attribute: str | None = None) -> bool: ...
def async_numeric_state_from_config(config: ConfigType) -> ConditionCheckerType: ...
def state(hass: HomeAssistant, entity: str | State | None, req_state: Any, for_period: timedelta | None = None, attribute: str | None = None, variables: TemplateVarsType = None) -> bool: ...
def state_from_config(config: ConfigType) -> ConditionCheckerType: ...
def template(hass: HomeAssistant, value_template: Template, variables: TemplateVarsType = None) -> bool: ...
def async_template(hass: HomeAssistant, value_template: Template, variables: TemplateVarsType = None, trace_result: bool = True) -> bool: ...
def async_template_from_config(config: ConfigType) -> ConditionCheckerType: ...
def time(hass: HomeAssistant, before: dt_time | str | None = None, after: dt_time | str | None = None, weekday: str | Container[str] | None = None) -> bool: ...
def time_from_config(config: ConfigType) -> ConditionCheckerType: ...
async def async_trigger_from_config(hass: HomeAssistant, config: ConfigType) -> ConditionCheckerType: ...
def numeric_state_validate_config(hass: HomeAssistant, config: ConfigType) -> ConfigType: ...
def state_validate_config(hass: HomeAssistant, config: ConfigType) -> ConfigType: ...
async def async_validate_condition_config(hass: HomeAssistant, config: ConfigType) -> ConfigType: ...
async def async_validate_conditions_config(hass: HomeAssistant, conditions: list[ConfigType]) -> list[ConfigType | Template]: ...
async def async_conditions_from_config(hass: HomeAssistant, condition_configs: list[ConfigType], logger: logging.Logger, name: str) -> Callable[[TemplateVarsType], bool]: ...
@callback
def async_extract_entities(config: ConfigType | Template) -> set[str]: ...
@callback
def async_extract_devices(config: ConfigType | Template) -> set[str]: ...
@callback
def async_extract_targets(config: ConfigType | Template, target_type: Literal['area_id', 'floor_id', 'label_id']) -> set[str]: ...
@callback
def _get_targets_from_condition_config(config: ConfigType, target: Literal['entity_id', 'device_id', 'area_id', 'floor_id', 'label_id']) -> list[str]: ...
def _load_conditions_file(integration: Integration) -> dict[str, Any]: ...
def _load_conditions_files(integrations: Iterable[Integration]) -> dict[str, dict[str, Any]]: ...
async def async_get_all_descriptions(hass: HomeAssistant) -> dict[str, dict[str, Any] | None]: ...
