From 38705a8c1825638750cbee3e03bd182db1445020 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 7 Apr 2026 15:26:25 +0200 Subject: Add AppState.covers This set contains all the covers the server offers. This commit does not include displaying it. --- lib/data.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/data.dart') diff --git a/lib/data.dart b/lib/data.dart index 201550e..a2e26b3 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -51,6 +51,7 @@ class AppState with ChangeNotifier { MachineState state = MachineState.init; Map contacts = {}; + Set covers = {}; late MqttServerClient _client; late Directory supportDir; @@ -141,6 +142,7 @@ class AppState with ChangeNotifier { void _onConnected() { _client.subscribe('$topicPrefix/contact/+/state', MqttQos.exactlyOnce); + _client.subscribe('$topicPrefix/cover/+', MqttQos.exactlyOnce); _client.subscribe('$topicPrefix/server/health', MqttQos.exactlyOnce); process(MachineEvent.connected); @@ -148,6 +150,7 @@ class AppState with ChangeNotifier { void _onDisconnected() { contacts = {}; + covers = {}; process(MachineEvent.disconnected); } @@ -175,6 +178,12 @@ class AppState with ChangeNotifier { _onContactMessage(payload, address); return; } + + if (parts.length == 3 && parts[1] == 'cover') { + String id = parts[2]; + _onCoverMessage(payload, id); + return; + } } } @@ -196,6 +205,12 @@ class AppState with ChangeNotifier { } } + void _onCoverMessage(String payload, String id) { + if (payload != 'exists') return; + + covers.add(id); + } + bool? _parseBool(String payload) { switch (payload.toLowerCase()) { case 'open': -- cgit v1.3