diff options
| author | xengineering <me@xengineering.eu> | 2026-04-08 10:58:29 +0200 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-04-08 11:28:51 +0200 |
| commit | e4c61d1b669a43d292be1f40d5b36dbcb93500a4 (patch) | |
| tree | 9789c4af85f680d877be9af9e5fff1614b4e8c05 /lib | |
| parent | 5dc62a59bf12dcc0190c26eb3712c1b7eec3cfcd (diff) | |
| download | sia-app-e4c61d1b669a43d292be1f40d5b36dbcb93500a4.tar sia-app-e4c61d1b669a43d292be1f40d5b36dbcb93500a4.tar.zst sia-app-e4c61d1b669a43d292be1f40d5b36dbcb93500a4.zip | |
Add cover control with up / stop / down
This allows the user to move covers with the Sia app.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/data.dart | 12 | ||||
| -rw-r--r-- | lib/ui.dart | 42 |
2 files changed, 53 insertions, 1 deletions
diff --git a/lib/data.dart b/lib/data.dart index a2e26b3..14e6811 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -221,4 +221,16 @@ class AppState with ChangeNotifier { return null; } } + + void publish(String topic, String payload, MqttQos qos) { + final MqttClientPayloadBuilder builder = MqttClientPayloadBuilder(); + builder.addString(payload); + + _client.publishMessage( + '$topicPrefix/$topic', + qos, + builder.payload!, + retain: false, + ); + } } diff --git a/lib/ui.dart b/lib/ui.dart index 94b6b8e..66078da 100644 --- a/lib/ui.dart +++ b/lib/ui.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:mqtt_client/mqtt_client.dart'; import 'data.dart'; @@ -154,11 +155,50 @@ class CoverList extends StatelessWidget { physics: const NeverScrollableScrollPhysics(), itemCount: state.covers.length, itemBuilder: (BuildContext context, int index) { + String cover = state.covers.elementAt(index); return Column( children: <Widget>[ ListTile( leading: const Icon(Icons.roller_shades), - title: Text(state.covers.elementAt(index)), + title: Text(cover), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + IconButton( + icon: const Icon(Icons.arrow_upward), + constraints: const BoxConstraints(), + onPressed: () { + state.publish( + 'cover/$cover/movement', + 'retract', + MqttQos.exactlyOnce + ); + }, + ), + IconButton( + icon: const Icon(Icons.stop), + constraints: const BoxConstraints(), + onPressed: () { + state.publish( + 'cover/$cover/movement', + 'stop', + MqttQos.exactlyOnce + ); + }, + ), + IconButton( + icon: const Icon(Icons.arrow_downward), + constraints: const BoxConstraints(), + onPressed: () { + state.publish( + 'cover/$cover/movement', + 'extend', + MqttQos.exactlyOnce + ); + }, + ), + ], + ), ), ], ); |
