ollo69 / ha_asuswrt_custom

AsusWrt Custom HA integration
Apache License 2.0
7 stars 0 forks source link

Feat: WAN Status Sensors #8

Closed PeteRager closed 1 year ago

PeteRager commented 1 year ago

Add sensors to track WAN status via async_get_wan_info

While all the info could be good to have

    Format: {"status": "1", "statusstr": "'Connected'", "type": "'dhcp'", "ipaddr": "'192.168.1.2'",
             "netmask": "'255.255.255.0'", "gateway": "'192.168.1.1'", "dns": "1.1.1.1'",
             "lease": "86400", "expires": "81967", "xtype": "''", "xipaddr": "'0.0.0.0'",
             "xnetmask": "'0.0.0.0'", "xgateway": "'0.0.0.0'", "xdns": "''", "xlease": "0",
             "xexpires": "0"}

The main ones needed are:

use case, assessing health of wan connection when internet ping sensors go down, to determine if cable modem or router may need to be restarted.

ollo69 commented 1 year ago

Good idea, I will add to next release.

ollo69 commented 1 year ago

This sensors are now available in new release.

PeteRager commented 1 year ago

That was fast!! I’ll load it up tomorrow.

PeteRager commented 1 year ago

Installed it today. Setup worked and I was able to enable those WAN entities and get data.

When I disconnect the coax from the modem, then sensors still reported as connected. I then ran home_assistant.update_entity on the connected status and that did not change it. I logged into the router and it showed its state as disconnected. I then restarted home assistant and the WAN entities did not change. They all showed the data from when it was last connected. So it kind of seem like we are getting the old data from the router.

Is there some debugging or data I should try to grab from the Asus, so we can see what is going on?

PeteRager commented 1 year ago

I ran a different test. In this test I pulled the power from the modem. Once I did this on the next scan cycle the integration reported ip as 0.0.0.0, gw as 0.0.0.0 and connected as connected.

It looks like as long as the media isn’t disconnected and it’s DNS lease is still valid it holds onto those values. Which I suppose is reasonable behavior. So it seems like the issue is the connected state not working in either scenario.

ollo69 commented 1 year ago

I think this is my fault. I released this version without really testing value returned by the router when disconnected. Just because I would leave test to you😁. I will check this better and will return with a new version.

PeteRager commented 1 year ago

Sounds good, I think this line is a bit optimistic

https://github.com/ollo69/ha_asuswrt_custom/blob/f92ab7f85c74a7e615bb70148e1bc6b0c068f48a/custom_components/asuswrt_custom/binary_sensor.py#L82

ollo69 commented 1 year ago

Released new version (and tested), now WAN sensor should work properly. Please give me your feedback.

PeteRager commented 1 year ago

Thanks. Will try tomorrow AM

PeteRager commented 1 year ago

Ran though the tests and it work. Thank you for the fast turn-around.