Unifi Device_tracker problem

Just verified.
The error is gone with the above modification plus the one made by me:

        if (
            self.device.last_seen
            and (dt_util.utcnow()
            - dt_util.utc_from_timestamp(float(self.device.last_seen))
        ) < detection_time):
            return True
        return False

But now, there is another error :frowning:

2019-08-06 10:47:07 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 399, in _async_add_entity
    await entity.async_update_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 254, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 286, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/unifi/device_tracker.py", line 342, in device_state_attributes
    attributes["upgradable"] = self.device.upgradable
  File "/usr/local/lib/python3.7/site-packages/aiounifi/devices.py", line 101, in upgradable
    return self.raw['upgradable']
KeyError: 'upgradable'

I think it’s safe to assume that in that case, the device should be skipped.

Ok, that is weird, attributes shouldn’t be read when available is False. I will try to reproduce this at home.

Thanks!

I tracked down the issue…

It seems that if all the devices are Online at Home Assistant startup, the error doesn’t show up. But, if one of the devices goes offline, the last error appears again and it goes when the device is online again…
I can reproduce this by disconnecting one of the APs.

Also, if the AP was online at HA start, when it goes offline it appears as “Away” instead of “Unavailable”.
I think there should be a check if the device is Ubiquity AP, SW, Router, etc, it shouldn’t be tracked, or the property “state” should be used to mark the device Available/Unavailable

From my log, this is the device that was offline

 {'_id': '5c80363df36ecd0552456e07',
  ...
  ...
  ...
  'model': 'US48P750',
  ...
  ...
  ...
  'state': 0,
  ...

and this an online device

{'_id': '5c7bd427f36ecd05117e294d',
  ...
  ...
  ...
  'model': 'U7SHD',
  ...
  ...
  ...
  'state': 1,

Fixed it https://github.com/home-assistant/home-assistant/pull/25735

Unfortunately, the error is still present when there is a device that have a value for “last_seen”, but it’s offline in the controller ('state': 0)…

Here is the error:

2019-08-07 11:21:23 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 254, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 286, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/unifi/device_tracker.py", line 344, in device_state_attributes
    attributes["upgradable"] = self.device.upgradable
  File "/usr/local/lib/python3.7/site-packages/aiounifi/devices.py", line 101, in upgradable
    return self.raw['upgradable']
KeyError: 'upgradable'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 254, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 286, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/unifi/device_tracker.py", line 344, in device_state_attributes
    attributes["upgradable"] = self.device.upgradable
  File "/usr/local/lib/python3.7/site-packages/aiounifi/devices.py", line 101, in upgradable
    return self.raw['upgradable']
KeyError: 'upgradable'

You can easily reproduce this by unplugging an access point and wait untill it appears “Disconnected” in Unifi Controller.
As soon as it appears “Disconnected”, the error pops out in the logs.
When you plug it back in, as soon as it’s available in Unifi Controller, the error disappears.

I will make those parameters optional. But that won’t be until next hass release

I will change from looking at last_seen to verifying state as well as making the parameters in attributes optional just in case. Thanks for your help!

That would be great.
Just let me know if I can help testing or anything else.

Just run 0.97.2 :wink:

Hi,

I have also an issue with the device_tracker since upgrade from 0.97.3 to 0.100
When downgrading again unifi device tracker is working again.

Br,
Johannes

What is the issue?

2019-10-11 15:39:02 INFO (MainThread) [homeassistant.components.switch] Setting up switch.unifi
2019-10-11 15:39:02 ERROR (MainThread) [homeassistant.setup] Error during setup of component device_tracker

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 167, in _async_setup_component
hass, processed_config
File "/usr/src/homeassistant/homeassistant/components/device_tracker/__init__.py", line 142, in async_setup
legacy_platforms = await setup.async_extract_config(hass, config)
File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 114, in async_extract_config
platform.name, platform.type
ValueError: Unable to determine type for unifi: None

This is my config:

device_tracker:
  - platform: unifi
    host: !secret unifi_host
    username: !secret unifi_username
    password: !secret unifi_password
    verify_ssl: false
    ssid_filter:
      - 'SSID'

Br,
Johannes

Yes. That configuration is not supported anymore. Just remove it

2 Likes

Yes, of course…

I was reading the “integration webpage” several times and I was not able to understand the change…

Many thanks!

Br,
Johannes

1 Like

It was communicated as a breaking change in release notes of 0.99 that it would be removed with 0.100 :slight_smile:

I removed the ios and unifi from my configuration.yaml and everything is working again. Thank you very much. I guess I missed that in the release notes.

1 Like

bellyup64 I have the same config as you.

device_tracker:
  - platform: unifi_direct
    host: 192.168.1.4
    username: xxxxx
    password: !secret unifi_password

Robban write the this configutation is not supported anymore.
How did you change the configuration to get the device_tracker to work again?
Did you add any other configuration for Unifi ?

Br,
Fredrik

Unifi direct is a different integration

Robban, what do you mean?
Should I use Unifi direct?