Vaskivskyi / ha-asusrouter

Monitor and control your AsusWRT-powered router from Home Assistant
https://asusrouter.vaskivskyi.com
Apache License 2.0
188 stars 17 forks source link

ASUS RT-AX89X failed to setup #32

Closed r3wt closed 2 years ago

r3wt commented 2 years ago

Same as other users here, it says "failed to setup", and then from the logs i can see the cause

Trace:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 335, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/asusrouter/__init__.py", line 27, in async_setup_entry
    await router.setup()
  File "/config/custom_components/asusrouter/router.py", line 248, in setup
    self._mac = await self._api.get_mac()
  File "/config/custom_components/asusrouter/bridge.py", line 232, in get_mac
    await self._async_get_device_info()
  File "/config/custom_components/asusrouter/bridge.py", line 199, in _async_get_device_info
    await self._api.async_initialize()
  File "/usr/local/lib/python3.9/site-packages/asusrouter/asusrouter.py", line 444, in async_initialize
    await self.async_monitor_devices()
  File "/usr/local/lib/python3.9/site-packages/asusrouter/asusrouter.py", line 381, in async_monitor_devices
    monitor_devices[mac] = parsers.connected_device(data[mac])
  File "/usr/local/lib/python3.9/site-packages/asusrouter/util/parsers.py", line 164, in connected_device
    values[key.get()] = key.method(raw[key.value]) if key.method else raw[key.value]
  File "/usr/local/lib/python3.9/site-packages/asusrouter/util/converters.py", line 42, in float_from_str
    return float(raw)
ValueError: could not convert string to float: '1170M'
Vaskivskyi commented 2 years ago

Hi @r3wt ,

Thanks for your feedback! πŸ‘πŸ»

Apparently, your router is reporting connected devices RX and TX speeds differently than others.

Could you please run this python snippet from your HA venv or any other environment with AsusRouter library already installed? Just put the code to some local script.py (without forgetting to put in your values for _host and _password in it). Then run it with python3 script.py.

"""Small test for available data from your AsusRouter"""

from asusrouter import AsusRouter
import asyncio

async def gather_data(host, username, password, port, use_ssl, cert_check):
    """Method to gether all the known data"""

    # Initialize
    router = AsusRouter(host = host, username = username, password = password, port = port, use_ssl = use_ssl, cert_check = cert_check)

    # Connect
    await router.connection.async_connect()

    # Get all the boolean data in raw
    data = await router.async_hook("get_clientlist()")
    for device in data["get_clientlist"]:
        try:
            info = data["get_clientlist"][device]
            print("RX: {}; TX: {}".format(info["curRx"], info["curTx"]))
        except Exception as ex:
            break

    # Disconnect
    await router.connection.async_disconnect()

loop = asyncio.get_event_loop()

# Please, put your values in here. _port = 0 means use default port
_host = "IP_or_hostname_here"
_username = "admin"
_password = "password"
_port = 0
_use_ssl = True
_cert_check = False

loop.run_until_complete(gather_data(_host, _username, _password, _port, _use_ssl, _cert_check))

loop.close()

This will print you all the RX and TX speeds for the connected devices (1 line per device). Some of them might be empty - that is fine.

RX: 54; TX: 72.2
RX:         ; TX: 130
RX: 54; TX: 72.2
RX: 6; TX: 72.2
Vaskivskyi commented 2 years ago

Hey, @r3wt ,

With the new 0.2.2 version, it is now possible to have partially parsed devices, so the problem you are experiencing won't be on the way to the integration set-up. But it will be generating warnings in the log with some additional info on which exactly values are wrong and what they report. So it would be easier to find the complete fix to this issue.

Could you try it?

perkmi commented 2 years ago

Hello,

Not OP but on 0.2.2 I get the same issue as OP on my RT-ACRH13

Trace:

Logger: homeassistant.config_entries
Source: custom_components/asusrouter/bridge.py:199
Integration: ASUS Router ([documentation](https://github.com/Vaskivskyi/ha-asusrouter), [issues](https://github.com/Vaskivskyi/ha-asusrouter/issues))
First occurred: 11:14:58 PM (1 occurrences)
Last logged: 11:14:58 PM

Error setting up entry 192.168.1.1 for asusrouter
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 335, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/asusrouter/__init__.py", line 27, in async_setup_entry
    await router.setup()
  File "/config/custom_components/asusrouter/router.py", line 248, in setup
    self._mac = await self._api.get_mac()
  File "/config/custom_components/asusrouter/bridge.py", line 232, in get_mac
    await self._async_get_device_info()
  File "/config/custom_components/asusrouter/bridge.py", line 199, in _async_get_device_info
    await self._api.async_initialize()
  File "/usr/local/lib/python3.9/site-packages/asusrouter/asusrouter.py", line 444, in async_initialize
    await self.async_monitor_devices()
  File "/usr/local/lib/python3.9/site-packages/asusrouter/asusrouter.py", line 381, in async_monitor_devices
    monitor_devices[mac] = parsers.connected_device(data[mac])
  File "/usr/local/lib/python3.9/site-packages/asusrouter/util/parsers.py", line 166, in connected_device
    values[key.get()] = key.method(raw[key.value]) if key.method else raw[key.value]
  File "/usr/local/lib/python3.9/site-packages/asusrouter/util/converters.py", line 42, in float_from_str
    return float(raw)
ValueError: could not convert string to float: '52M'
perkmi commented 2 years ago

Output of provided script

/config/shell # python3 asus.py 
RX: ; TX: 
RX: ; TX: 
RX: ; TX: 
RX: 52M; TX: 43M
RX: 117M; TX: 325M
RX: 13M; TX: 135M
RX: 39M; TX: 130M
RX: 39M; TX: 39M
RX: 72M; TX: 86M
RX: 13M; TX: 45M
RX: 175M; TX: 390M
RX: 81M; TX: 180M
RX: 780M; TX: 866M
RX: 130M; TX: 468M
RX: 6M; TX: 390M
RX: 526M; TX: 866M
RX: 780M; TX: 866M
RX: 6M; TX: 585M
RX: 6M; TX: 26M
RX: 175M; TX: 390M
RX: 650M; TX: 866M
RX: ; TX: 
Vaskivskyi commented 2 years ago

Hi, @Ekim0789 ,

Thanks for the information! πŸ‘πŸ»

Apparently, your devices are reporting speeds with "M" stated for "mega". Others do it silently, just providing numbers.

I'll implement the needed changes either today in the evening (CET), or in the nearest days

Vaskivskyi commented 2 years ago

@r3wt , @Ekim0789 ,

Could you try version 0.2.3 and check if this issue is solved?

perkmi commented 2 years ago

@Vaskivskyi,

Version 0.2.3 confirmed working on my RT-ACRH13, thanks!

r3wt commented 2 years ago

@Vaskivskyi I am pleased to report that 0.2.3 is working for me on RT-AX89X as well! Thank you @Vaskivskyi !!!

EDIT: Tomorrow I will run the supplied python script, and report you what it shows. I am interested in helping on the project to provide additional sensors if possible. I haven't been into the router from telnet or ssh yet to poke around, but if I find anything i will let you know. The ASUS-WRT integration in HA doesn't work well with my router, but so far this one is working much better. Again, thank you so much for providing the package for us.