From 18cbbf877b171fc23950e64dac5fa6abda6fb02b Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 8 Apr 2026 14:16:28 +0200 Subject: Add plug control This allows the user to turn Wi-Fi plugs on and off. --- 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 14e6811..2016f6f 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -52,6 +52,7 @@ class AppState with ChangeNotifier { Map contacts = {}; Set covers = {}; + Set plugs = {}; 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 = {}; covers = {}; + plugs = {}; 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': -- cgit v1.3