Add timers

This commit is contained in:
Michael Hansen
2024-05-24 15:14:15 -05:00
parent 9b35e0334f
commit 16847ef5e9
8 changed files with 127 additions and 7 deletions
+10 -2
View File
@@ -1,24 +1,32 @@
"""Miscellaneous utilities."""
import argparse
import asyncio
import json
import logging
import re
import shlex
import unicodedata
import uuid
from functools import lru_cache
from typing import List, Optional
from typing import List, Optional, Union
from wyoming.event import Eventable
_LOGGER = logging.getLogger()
async def run_event_command(
command: Optional[List[str]], command_input: Optional[str] = None
command: Optional[List[str]], command_input: Optional[Union[str, Eventable]] = None
) -> None:
"""Run a custom event command with optional input."""
if not command:
return
if isinstance(command_input, Eventable):
# Convert event to JSON
event_dict = command_input.event().to_dict()
command_input = json.dumps(event_dict, ensure_ascii=False)
_LOGGER.debug("Running %s", command)
program, *program_args = command
proc = await asyncio.create_subprocess_exec(