janstol / yeedart

Simple Dart library that lets you control Yeelight devices over LAN.
MIT License
10 stars 4 forks source link

NotificationMessageStream not sending new events #6

Closed thomasaldershof closed 2 years ago

thomasaldershof commented 3 years ago

Hello,

I am trying to listen to state changes, to automatically update the app, but I get no events. This is the used code streamListener() { log("listening"); device.notificationMessageStream.listen((event) { log("received event"); event.params?.forEach( (key, value) { switch (key) { case 'power': properties['power'] = value; } }, ); notifyListeners(); }); }

First log is showing up. Received event is not when changing device state from the same device or e.g. Google home.

thomasaldershof commented 3 years ago

Alright turns out you don't automatically connect to a device. I am now sending a empty getProps to establish a connection.

Is there a better way? On your example page it seems creating the Device object is all that's needed. Maybe a device.connect() would be nice.

janstol commented 2 years ago

Yeah, you are right. Connection is created automatically when you send a command.

So in 0.3.1 I added device.connect() method which will allow you to listen on notificationMessageStream without sending any command prior to that.