OpenWRT 19.07.4 & ubus device_tracker: res["ubus_rpc_session"] TypeError: 'NoneType' object is not subscriptable

Hi everyone!

It seems like a recent update to either OpenWRT or Hass broke my ubus tracker.

Error setting up platform legacy
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 63, in async_setup_legacy
    scanner = await hass.async_add_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/ubus/device_tracker.py", line 40, in get_scanner
    scanner = DnsmasqUbusDeviceScanner(config[DOMAIN])
  File "/usr/src/homeassistant/homeassistant/components/ubus/device_tracker.py", line 149, in __init__
    super().__init__(config)
  File "/usr/src/homeassistant/homeassistant/components/ubus/device_tracker.py", line 85, in __init__
    self.session_id = _get_session_id(self.url, self.username, self.password)
  File "/usr/src/homeassistant/homeassistant/components/ubus/device_tracker.py", line 247, in _get_session_id
    return res["ubus_rpc_session"]
TypeError: 'NoneType' object is not subscriptable

The credentials are correct, the routers have rpcd-mod-file installed, and a user configured in /usr/share/rpcd/acl.d/user.json as per the documentation.

Just to be sure here is the relevant part of my configuration.yaml:

# Presence detection
device_tracker:
  - platform: ubus
    host: 192.168.0.1
    username: !secret openwrt_user
    password: !secret openwrt_password
    interval_seconds: 10
    consider_home: 600
    new_device_defaults:
      track_new_devices: False
  - platform: ubus
    host: 192.168.0.5
    username: !secret openwrt_user
    password: !secret openwrt_password
    interval_seconds: 10
    consider_home: 600
    new_device_defaults:
      track_new_devices: False

I read in a different topic that I could test the connection with curl but I don’t know what to make of the output:

curl --data-ascii '{"jsonrpc": "2.0", "id": 1, "method": "call", "params": ["00000000000000000000000000000000", "session", "login", {"username": "root", "password": "REDACTED"}]}' http://192.168.0.1/ubus/ -v
*   Trying 192.168.0.1...
* TCP_NODELAY set
* Connected to 192.168.0.1 (192.168.0.1) port 80 (#0)
> POST /ubus/ HTTP/1.1
> Host: 192.168.0.1
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 158
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 158 out of 158 bytes
< HTTP/1.1 404 Not Found
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< Keep-Alive: timeout=20
< Content-Type: text/html
< 
* Connection #0 to host 192.168.0.1 left intact

Is anyone using OpenWRT 19.07.04 together with Hass 0.116.*?

same error in another integration (mail_and_packages).

What integration are you referring to? Is it a custom component?

In general, the error means that you attempted to index an object that doesn’t have that functionality. You are trying to subscript an object which you think is a list or dict, but actually is None. This means that you tried to do:

None[something]

NoneType is the type of the None object which represents a lack of value, for example, list1 = list.sort(list1) : - here, you are setting it to None. None always has no data, so NoneType object is not subscriptable. In order to correct this error this should be list1.sort().