Error doing job: Task exception was never retrieved - upnp/sensor.py

Hello All,

My Home Assistant log keeps showing up with the below errors but I can’t seem to make sense of it.
I’ve checked my configuration.yaml file and it doesn’t have any specific upnp config.

Running version 0.102.3

Anyone know where I can look?

Thank you!

2020-01-03 16:32:17 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 275, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 309, in _async_write_ha_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 129, in state
    return format(self._state, "d")
TypeError: unsupported format string passed to NoneType.__format__
2020-01-03 16:32:17 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 275, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 309, in _async_write_ha_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 129, in state
    return format(self._state, "d")
TypeError: unsupported format string passed to NoneType.__format__
2020-01-03 16:32:17 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 275, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 309, in _async_write_ha_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 129, in state
    return format(self._state, "d")
TypeError: unsupported format string passed to NoneType.__format__
2020-01-03 16:32:17 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 275, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 309, in _async_write_ha_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 129, in state
    return format(self._state, "d")
TypeError: unsupported format string passed to NoneType.__format__

Looks like a bug was introduced into the code way back in the 0.80.0 release by this change of PR #16300. Prior to that the state was checked that it wasn’t None before attempting to format it.

I searched the issues and discovered a couple of times where people have reported this exact exception, but they seemed to have been overlooked.

I’ll open a PR to fix this.

Update: PR #30444 opened.

1 Like

Fantastic - thank you! :grin:

1 Like

Just an FYI. The PR was merged and targeted for the 0.104.0 release.

I’m running HassOS 4.9 and Home Assistant Core 0.110.3, and I’m seeing

Logger: homeassistant.components.sensor
Source: components/upnp/sensor.py:201
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 6 June 2020, 18:51:22 (2 occurrences)
Last logged: 6 June 2020, 18:51:22

* Error while setting up upnp platform for sensor
* upnp: Error on device update!

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 446, in _async_add_entity
    entity.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 297, in async_write_ha_state
    self._async_write_ha_state()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 201, in state
    return format(value, "d")
TypeError: unsupported format string passed to NoneType.__format__

I think PR #30444 has been undone by PR #33108

I suggest something like this in RawUpnpSensor:

--- sensor.py.orig	2020-06-07 14:58:55.000000000 +1000
+++ sensor.py	2020-06-07 16:04:13.000000000 +1000
@@ -198,6 +198,8 @@
         """Return the state of the device."""
         device_value_key = self._sensor_type["device_value_key"]
         value = self._coordinator.data[device_value_key]
+        if value is None:
+            return None
         return format(value, "d")

The format() in DerivedUpnpSensor may be safe.

Looks like you’re probably right, but you need to open an issue in github if you want this fixed.

+1
Running fresh install of 0.110.5 in Windows with Python 3.8.
Issue is when HA auto discovered my TP-Link router and tried to add it as a uPnP device.

Log:

2020-06-09 08:59:23 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up upnp platform for sensor
Traceback (most recent call last):
  File "C:\Users\lucas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\homeassistant\helpers\entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "C:\Users\lucas\AppData\Local\Programs\Python\Python38-32\lib\asyncio\tasks.py", line 483, in wait_for
    return fut.result()
  File "C:\Users\lucas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\homeassistant\components\upnp\sensor.py", line 89, in async_setup_entry
    device: Device = hass.data[DOMAIN]["devices"][udn]
KeyError: 'uuid:060b7353-fca6-4070-85f4-1fbfb9add62c'

Issue opened in github: https://github.com/home-assistant/core/issues/36698

1 Like

Hello everybody,

Yet another Task exception was never retrieved .
From HA → Configuration → Logs I keep getting these messages:

Logger: homeassistant
Source: /usr/src/homeassistant/homeassistant/runner.py:90
First occurred: November 21, 2021, 6:03:47 PM (90 occurrences)
Last logged: November 21, 2021, 6:10:49 PM
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/search.py", line 83, in _async_on_data
    await self.async_callback(headers)
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/ssdp_listener.py", line 392, in _on_search
    ) = self._device_tracker.see_search(headers)
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/ssdp_listener.py", line 156, in see_search
    udn = headers["_udn"]
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/utils.py", line 57, in __getitem__
    return self._data[self._case_map[key.lower()]]
KeyError: '_udn'
  • What does it mean?
  • Where does it come from?
  • How can it be prevented?

I have searched the config directory for things similar like :
grep -i udn $(find . -name \*.yaml)
but found nothing that I consider to be wrong.

Can somebody give me a hint where to look for?
Thanks in Advance, Yann

Same Problem here:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression
2021-12-03 13:26:48 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 24, in _matched_event
    await at_start_cb(hass)
TypeError: object NoneType can't be used in 'await' expression

Home Assistant 2021.12.0.dev20211203

Version	core-2021.12.0.dev20211203
Installationstyp	Home Assistant Container
Entwicklung	true
Supervisor	false
Docker	true
Benutzer	root
Virtuelle Umgebung	false
Python-Version	3.9.7
Betriebssystemfamilie	Linux
Betriebssystem-Version	5.8.0-63-generic
CPU-Architektur	x86_64
Zeitzone	Europe/Vaduz