summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2026-04-07 15:26:25 +0200
committerxengineering <me@xengineering.eu>2026-04-07 16:49:20 +0200
commit38705a8c1825638750cbee3e03bd182db1445020 (patch)
tree7529aeeafa7bcdf3af9a69b49a4f0ac56de14443 /lib
parent129c825a77fb3cc039ab978785d72f92023ef1ab (diff)
downloadsia-app-38705a8c1825638750cbee3e03bd182db1445020.tar
sia-app-38705a8c1825638750cbee3e03bd182db1445020.tar.zst
sia-app-38705a8c1825638750cbee3e03bd182db1445020.zip
Add AppState.covers
This set contains all the covers the server offers. This commit does not include displaying it.
Diffstat (limited to 'lib')
-rw-r--r--lib/data.dart15
1 files changed, 15 insertions, 0 deletions
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<String, bool> contacts = <String, bool>{};
+ Set<String> covers = <String>{};
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 = <String, bool>{};
+ covers = <String>{};
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':