31 lines
722 B
Python
31 lines
722 B
Python
"""Define RainMachine utilities."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from homeassistant.backports.enum import StrEnum
|
|
|
|
|
|
class RunStates(StrEnum):
|
|
"""Define an enum for program/zone run states."""
|
|
|
|
NOT_RUNNING = "Not Running"
|
|
QUEUED = "Queued"
|
|
RUNNING = "Running"
|
|
|
|
|
|
RUN_STATE_MAP = {
|
|
0: RunStates.NOT_RUNNING,
|
|
1: RunStates.RUNNING,
|
|
2: RunStates.QUEUED,
|
|
}
|
|
|
|
|
|
def key_exists(data: dict[str, Any], search_key: str) -> bool:
|
|
"""Return whether a key exists in a nested dict."""
|
|
for key, value in data.items():
|
|
if key == search_key:
|
|
return True
|
|
if isinstance(value, dict):
|
|
return key_exists(value, search_key)
|
|
return False
|