koying / openrgb_ha

OpenRGB integration for Home Assistant
110 stars 18 forks source link

Fix connectivity #4

Closed Spizhen closed 3 years ago

Spizhen commented 3 years ago

Hello. Thanks for adding the component to HACS. Someone had to do it =)

I ran into a problem: if you restart the OpenRGB server, the component cannot connect itself back to the server.

I tried to correct this situation as much as I could.

The PR adds a check for connecting to the server when updating devices. In this case, it becomes possible to reconnect.

koying commented 3 years ago

Thanks.

Although your code is welcome just because it makes it leaner, I can't immediately see how it alters the functionality to fix your issue.

Currently, orgb.update() would throw an exception, and follow the same path than testing for hass.data[DOMAIN]["online"], as far as I can see

Could you explain it to me?

Spizhen commented 3 years ago

As I understand it, "orgb.update()" is executed in any case, due to which an exception is not thrown. Hence, there is no attempt to need to assert that the connection is broken.

My change involves at least some kind of connection check. Otherwise, the devices no longer receive the real state from the OpenRGB server until the Home Assistant is restarted.

Have you tried rebooting the OpenRGB server and then trying to influence devices from the Home Assistant?

My solution does not pretend to be the best, since I am not a professional in the language. But it helped me solve this problem.

koying commented 3 years ago

Well orgb.update do throw an exception if the connection is broken (or is supposed to do so) I sleep my PC and the integration manges to reconnect (I actually mainly use it to apply a "scene" to the PC RGB after wakeup).

But anyway, if it works for you, I don't see anything preventing merging.

Thanks