libdyson-wg / ha-dyson

Home Assistant custom integration for Wi-Fi connected Dyson devices
MIT License
208 stars 23 forks source link

Device does not become unavailable when connection is failed. #144

Open robinhood-code opened 3 months ago

robinhood-code commented 3 months ago

I have a fan which appeared to be normal as I could use the remote to turn it on / off, as well as showing as a normal device in HA. However, I noticed I was getting the following error message in HA while I had no idea what it was:

ERROR: Error fetching environmental data: Failed to request environmental data

and then when I tried to turn my fan on, I got the following error and was unable to turn off the fan via HA:

image

And at this moment, I finally realized the fan may have trouble connecting to the wifi so I turned off the fan at the socket, waited a few minutes, and then turn the socket back on. The fan successfully connected to the wifi and is working in HA again and there is no more error messages.

So in this case shouldn't the device become unavailable in HA with a more meaningful error message in the HA log?

Thanks.

dotvezz commented 3 months ago

Sorry for the slow response here!

You're right, it does make make sense to make it unavailable. I'll try to work out a way to accomplish that without unintended side-effects. My biggest concern is making sure we're able to reliably toggle the availability state. We have a few possible things we can use, like persistent MQTT connections and message intervals. I think we can even use ICMP pings with the fan devices if we need to!

I do need to temper expectations just a bit though. I'm going to approach this with caution since there's less certainty with our connection scheme that in other common home automation setups. For Z-Wave, and Zigbee (and maybe Matter?) devices, connection status is a part of the protocol and immediately available. But we're piggybacking on TCP/IP since Dyosn devices are simple Wi-Fi devices.

While it's really nice that we get a direct connection to the devices so we don't need the cloud, we also don't get native visibility on network connectivity. MQTT should. give us a really strong approximation though! For now I'll check into using connect/disconnect callbacks to handle the state change.

robinhood-code commented 3 months ago

Thanks for getting back, I understand what you are trying to achieve is find a reliable way to continuously monitor the online status of the device and reflect that in the HA status.

But what I was asking was simple to update the HA status whenever you have error such as the “DysonNotConnected” exception above ? Or is it not an appropriate way how the availability status should be updated ? Thanks again for looking into this.

dotvezz commented 3 months ago

I was asking was simple to update the HA status whenever you have error such as the “DysonNotConnected” exception above ? Or is it not an appropriate way how the availability status should be updated ? Thanks again for looking into this.

The thing is we need to be able to mark it available again when connectivity is restored.