jlamendo/ha-sensor.owlet

owlet: Error on device update! KeyError: 'DISCOMFORT_ALRT'

Intecpsp opened this issue · 4 comments

I'm getting the below error in HA:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 477, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 702, in async_device_update
    await task
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/owlet/sensor.py", line 405, in update
    state, raw_json = self.__Owlet.vitals(self.__DSN)
  File "/config/custom_components/owlet/sensor.py", line 254, in vitals
    "DISCOMFORT_ALRT": bool(p["DISCOMFORT_ALRT"]["value"]),
KeyError: 'DISCOMFORT_ALRT'

Looking at the JSON response, I don't see this key coming back from the API. I have a brand new Smart Sock 3 and Owlet account (meaning no data anywhere). Is it possible this key isn't populated until the first use?

Yeah, you won't see any data until the sock has been used. After it's been used, the sock will give data letting the integration know that the sock is charging etc, but before that, it's kinda just a weird edge case.

I commented out that line (and maybe another? I can't remember) and restarted HA just to get the sensors created so that I can integrate them into my dashboard. Then just redownloaded from HACS to get back to the prod code. Now to wait until I get data!

Just a heads up that I'm also getting this same error in my logs when trying to setup. I have run my V3 owlet for the first time last night, so should have enough data. To temporarily fix that I've done:

"DISCOMFORT_ALRT": 0, and then got all my values back

Sock is working with no issues now. Issue was a new sock/account with no data #18 (comment)