Skip to content

Commit

Permalink
Data Model: Make MQTT settings optional
Browse files Browse the repository at this point in the history
To allow running the data logger without configuring them.
  • Loading branch information
amotl committed Apr 21, 2024
1 parent 555248e commit 9a29dd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions ds18b20_datalogger/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ 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):
data = yaml.safe_load(configfile.read_text())
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
Expand Down

0 comments on commit 9a29dd7

Please sign in to comment.