From: Scott Gasch Date: Wed, 24 Aug 2022 01:27:09 +0000 (-0700) Subject: Update requirements; new homeassistant dep. Also don't import kazoo X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=119692e4487278e5d19c06cfe7dc062c2bd7efc5;p=python_utils.git Update requirements; new homeassistant dep. Also don't import kazoo unless we try to load args from zookeeper. --- diff --git a/config.py b/config.py index 1a362a3..a98db57 100644 --- a/config.py +++ b/config.py @@ -90,9 +90,6 @@ import re import sys from typing import Any, Dict, List, Optional, Tuple -from kazoo.client import KazooClient -from kazoo.protocol.states import WatchedEvent - import scott_secrets # This module is commonly used by others in here and should avoid @@ -225,7 +222,7 @@ class Config: # A zookeeper client that is lazily created so as to not incur # the latency of connecting to zookeeper for programs that are # not reading or writing their config data into zookeeper. - self.zk: Optional[KazooClient] = None + self.zk: Optional[Any] = None # Per known zk file, what is the max version we have seen? self.max_version: Dict[str, int] = {} @@ -378,7 +375,7 @@ class Config: sys.argv.append(value) arg = '' - def _process_dynamic_args(self, event: WatchedEvent): + def _process_dynamic_args(self, event): assert self.zk logger = logging.getLogger(__name__) contents, meta = self.zk.get(event.path, watch=self._process_dynamic_args) @@ -422,6 +419,8 @@ class Config: if loadfile is not None: zkpath = None if loadfile[:3] == 'zk:': + from kazoo.client import KazooClient + try: if self.zk is None: self.zk = KazooClient( @@ -544,6 +543,8 @@ class Config: zkpath = re.sub(r'//+', '/', zkpath) try: if not self.zk: + from kazoo.client import KazooClient + self.zk = KazooClient( hosts=scott_secrets.ZOOKEEPER_NODES, use_ssl=True, diff --git a/requirements.txt b/requirements.txt index a8673e9..6016dd9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,3 +25,4 @@ SpeechRecognition sphinx sqlalchemy tinytuya +homeassistant-api