def from_env(cls): doors = [ Door( name=door["name"], pin_id=door["pin_id"], readers=door["readers"], ) for door in json.loads(get_env_var('DOORS')) ] door_manager.configure(doors=doors) nfc_reader_manager.configure(doors=doors) return cls( master_keys=json.loads(get_env_var('MASTER_KEYS')), doors=doors, door_open_seconds=int(get_env_var('DOOR_OPEN_SECONDS')), )
async def refresh_from_envs(self) -> None: doors = [ Door( name=door["name"], pin_id=door["pin_id"], readers=door["readers"], ) for door in json.loads(get_env_var('DOORS')) ] door_manager.configure(doors=doors) nfc_reader_manager.configure(doors=doors)
def test_get_env_var(monkeypatch): monkeypatch.setenv("CLIENT_ID", "1") assert get_env_var("CLIENT_ID") == "1"
def test_get_env_var_except(monkeypatch): monkeypatch.delenv("CLIENT_ID", raising=False) with pytest.raises(ConfigError): get_env_var("CLIENT_ID")
def test_get_env_var_default(monkeypatch): monkeypatch.delenv("CLIENT_ID", raising=False) assert get_env_var("CLIENT_ID", default="120") is "120"
def test_get_env_var_allow_empty(monkeypatch): monkeypatch.delenv("CLIENT_ID", raising=False) assert get_env_var("CLIENT_ID", allow_empty=True) is None
def test_get_env_var_with_prefix(monkeypatch): monkeypatch.setenv("PRF_CLIENT_ID", "1") assert get_env_var("CLIENT_ID", prefix="PRF") == "1"
import logging from nfcclient.utils import get_env_var CLIENT_ID = get_env_var("CLIENT_ID", "1") HUB_HOST_URL = get_env_var("HUB_HOST_URL", "https://panel.lesnahub.pl") WEB = { "HOST": "localhost", "PORT": 8000, } DEBUG = False NFC_READER_MODULE = "nfcclient.nfc_reader.nfc_reader.NFCReaderImpl" NFC_REFRESHING_FEATURE = True NFC_REFRESHING_FEATURE_READ_MAX = 700 READER_TIMEOUT = 0.5 READ_PERIOD = 1 try: from .local import * except ImportError: # pragma: no cover pass logging.basicConfig( format='%(asctime)s %(levelname)-8s %(message)s', level=logging.DEBUG if DEBUG else logging.INFO, datefmt='%Y-%m-%d %H:%M:%S', )