summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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':