diff options
| author | xengineering <me@xengineering.eu> | 2026-04-08 14:16:28 +0200 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-04-08 14:16:28 +0200 |
| commit | 18cbbf877b171fc23950e64dac5fa6abda6fb02b (patch) | |
| tree | b3270dccc583da68c0a8b38c5123e5747191292d /lib/data.dart | |
| parent | 5171ef6557c3f38a32e68313e51c4ca1e866835a (diff) | |
| download | sia-app-18cbbf877b171fc23950e64dac5fa6abda6fb02b.tar sia-app-18cbbf877b171fc23950e64dac5fa6abda6fb02b.tar.zst sia-app-18cbbf877b171fc23950e64dac5fa6abda6fb02b.zip | |
Add plug control
This allows the user to turn Wi-Fi plugs on and off.
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': |
