From b9cc32d8a1ba845be330a3fa6b39188b19569ec6 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:29:46 +0200 Subject: [PATCH] Data Model: Make MQTT settings optional To allow running the data logger without configuring them. --- CHANGES.md | 2 ++ ds18b20_datalogger/model.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6845bf7..ecd343f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,8 @@ `version`. Thanks, @bee-mois. - Emit user admonition on `make-config` subcommand. Thanks, @bee-mois. +- Data Model: Make MQTT settings optional, to allow running the + data logger without configuring them. ## v0.0.3 - 2024-04-20 - Tests: Make sensor tests work, using a fake sysfs filesystem diff --git a/ds18b20_datalogger/model.py b/ds18b20_datalogger/model.py index db5f4a5..f3e89a1 100644 --- a/ds18b20_datalogger/model.py +++ b/ds18b20_datalogger/model.py @@ -66,8 +66,8 @@ class Settings: General settings container. """ - mqtt: MqttSettings - devicemap: DeviceMap + mqtt: t.Union[MqttSettings, None] + devicemap: t.Union[DeviceMap, None] @classmethod def from_file(cls, configfile: Path): @@ -75,7 +75,10 @@ def from_file(cls, configfile: Path): devicemap = DeviceMap() for item in data["one-wire"]: devicemap.devices.append(Device(**item)) - return cls(mqtt=MqttSettings(**data["mqtt"]), devicemap=devicemap) + mqtt = None + if "mqtt" in data: + mqtt = MqttSettings(**data["mqtt"]) + return cls(mqtt=mqtt, devicemap=devicemap) @dataclasses.dataclass