dominicusmento / CSharpTradFriLibrary

This is a .NET Standard (2.0) library to communicate with the IKEA Home (Tradfri) ZigBee-based Gateway.
GNU General Public License v3.0
37 stars 20 forks source link

Lights are not turning on/off when observing device #22

Closed scheelings closed 5 years ago

scheelings commented 5 years ago

Hi,

I have created a UI app similar to the old GUI application which works with the .Net Standard library. I have added 2 buttons:

  1. button which will turn all lights on: private async void button1_Click(object sender, EventArgs e) { foreach (var device in _devices) { if (device.DeviceType == DeviceType.Light) await _tradfriController.DeviceController.SetLight(device, true); } } _devices is my List instance with all devices, retrieved with tradfriController.GatewayController.GetDeviceObjects
  2. button which will turn the lights on using the group (I only have 1 group with 4 lights): await _tradfriController.GroupController.SetLight(_group, true);

Button 1 only turns the last light (of 4 lights) on (or off). Button 2 does not turn a light on/off at all.

So, I tried to turn the lights on/off individually. I have tried to call await _tradfriController.DeviceController.SetLight(xx, true); for all 4 light device ID's, but it does not matter which ID I pass to the SetLight method, it always turns on/off the last light.

I think this is really strange behavior, so I analyzed my code a bit more and I also added the ObserveDevice method calls on the DeviceController property of the tradfriController instance. When I removed these method call, all lights and groups are correctly turned on/off. So there is some strange behavior with the ObserveDevice method.

Does anyone have an idea what the problem is?

Thanks, Danny

P.s. I am using a copy of the Tradfri project, where I set the CoapClient property of the TradfriController to public, so I am able to use this property for the ObserveDevice method call.

scheelings commented 5 years ago

I was able to create a workaround by creating a 2nd instance of the TradfriController which I use for observing the devices. It works but in my opinion the library should handle this.

dominicusmento commented 5 years ago

Yes, you are right, library should handle it... I'll check it as soon as I find some time for it.

dominicusmento commented 5 years ago

This is now fixed by rewriting the observable part