"""Store settings""" import logging from MaxIcsRegistry import MaxIcsRegistry from cachetools import cached, LRUCache, TTLCache class Settings: """Settings for BKC communication""" def __init__(self, staging: bool = False, registry=None, **kwargs) -> None: self.logger = logging.getLogger(self.__class__.__name__) if not registry: self.logger.warning( "Registry is not set when initializing Building. Calling registry..." ) registry = MaxIcsRegistry.from_env(staging=staging) building_center_info = self._get_node_information( registry=registry, node_name="building-knowledge-information-center" ) self.api_key = next(iter(building_center_info["api_in"].values()))["key"] if "base_url" in kwargs.keys(): self.base_url = kwargs["base_url"] else: self.base_url = "http://{}:{}/api/buildings".format( building_center_info["service_addr"], building_center_info["service_port"] ) def __str__(self): return "Settings __dict__: %s" % str(self.__dict__) @cached(cache=TTLCache(maxsize=1024, ttl=30)) def _get_node_information(self, registry: MaxIcsRegistry, node_name: str): node_info = registry.get_info(node_name) return node_info