diff options
Diffstat (limited to 'lib/data.dart')
| -rw-r--r-- | lib/data.dart | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/data.dart b/lib/data.dart index 14e6811..2016f6f 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -52,6 +52,7 @@ class AppState with ChangeNotifier { Map<String, bool> contacts = <String, bool>{}; Set<String> covers = <String>{}; + Set<String> plugs = <String>{}; late MqttServerClient _client; late Directory supportDir; @@ -143,6 +144,7 @@ class AppState with ChangeNotifier { void _onConnected() { _client.subscribe('$topicPrefix/contact/+/state', MqttQos.exactlyOnce); _client.subscribe('$topicPrefix/cover/+', MqttQos.exactlyOnce); + _client.subscribe('$topicPrefix/plug/+', MqttQos.exactlyOnce); _client.subscribe('$topicPrefix/server/health', MqttQos.exactlyOnce); process(MachineEvent.connected); @@ -151,6 +153,7 @@ class AppState with ChangeNotifier { void _onDisconnected() { contacts = <String, bool>{}; covers = <String>{}; + plugs = <String>{}; process(MachineEvent.disconnected); } @@ -184,6 +187,12 @@ class AppState with ChangeNotifier { _onCoverMessage(payload, id); return; } + + if (parts.length == 3 && parts[1] == 'plug') { + String id = parts[2]; + _onPlugMessage(payload, id); + return; + } } } @@ -211,6 +220,12 @@ class AppState with ChangeNotifier { covers.add(id); } + void _onPlugMessage(String payload, String id) { + if (payload != 'exists') return; + + plugs.add(id); + } + bool? _parseBool(String payload) { switch (payload.toLowerCase()) { case 'open': |
