Commit c92d4e66 authored by Marc-Andre Santune's avatar Marc-Andre Santune
Browse files

allow uid to be None when init

parent 140e6d96
......@@ -7,7 +7,6 @@ import requests
from requests.exceptions import HTTPError
from retrying import retry
from simplejson import JSONDecodeError
from .settings import Settings
MAX_RETRIES = 5 # max retries number
......@@ -21,21 +20,30 @@ class BuildingGeneric:
"""Stores the methods used to receive or update the building info from ES doc"""
def __init__(self, uid: str, **kwargs) -> None:
def __init__(self, uid: str = None, **kwargs) -> None:
staging = kwargs.get("staging", False)
registry = kwargs.get("registry")
self.logger = logging.getLogger(self.__class__.__name__)
self._uid = uid
self._building = None
self.settings = Settings(staging=staging, registry=registry)
self.fetch()
if self._uid:
self.fetch()
def __getitem__(self, item):
return self._building.get(item)
# ----------------- Building level ---------------------
def post_building(self, payload) -> None:
"""Post a new building"""
res = self._req_with_retries("post", join(self.settings.base_url), json=payload)
self._uid = res["id"]
self.fetch()
def fetch(self) -> None:
"""Fetch the building document"""
self._building = self._req_with_retries("get", join(self.settings.base_url, self._uid))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment