import asyncio from functools import wraps from enum import IntEnum def async_debounce(wait): def decorator(func): task: asyncio.Task | None = None @wraps(func) async def debounced(*args, **kwargs): nonlocal task if task and not task.done(): return async def call_func(): await asyncio.sleep(wait) await func(*args, **kwargs) task = asyncio.create_task(call_func()) return task return debounced return decorator class OutputMatch(IntEnum): """Enum for how an output was matched to a workspace group This is used to break ties between contexts that have the same compatibility score. Output name matching is considered weaker than matching by make, model, and serial number, however, it is generic and can be used to match, say, projectors in conference rooms. NO_MATCH: The output was not matched to the workspace group NAME_MATCH: The output was matched by name to the workspace group ID_MATCH: The output was matched by its make, model, and serial number to the workspace group """ NO_MATCH = 0 NAME_MATCH = 1 ID_MATCH = 2