memberPlumbing/memberPlumbing/config.py

37 lines
1.0 KiB
Python

from ruamel.yaml import YAML
from .hid.DoorController import DoorController
from .MembershipWorks import MembershipWorks
class Config:
def __init__(self, path="config.yaml"):
with open(path) as f:
self._data = YAML().load(f)
self.__dict__.update(self._data)
# lazy init, because this actually talks to an external server
self._membershipworks = None
@property
def doors(self):
return {
doorName: DoorController(
doorData["ip"],
self.DOOR_USERNAME,
self.DOOR_PASSWORD,
name=doorName,
access=doorData["access"],
)
for doorName, doorData in self.doorControllers.items()
}
@property
def membershipworks(self):
if not self._membershipworks:
self._membershipworks = MembershipWorks()
self._membershipworks.login(
self.MEMBERSHIPWORKS_USERNAME, self.MEMBERSHIPWORKS_PASSWORD
)
return self._membershipworks