mezz64 / pyEight

Python library to interface with the Eight Sleep API
MIT License
59 stars 15 forks source link

'NoneType' object is not subscriptable #21

Open themistymay opened 2 years ago

themistymay commented 2 years ago

Got the following error when using this in HA. Not sure if you want this issue here or in the HA repo.

homeassistant    | 2021-09-20 11:57:43 ERROR (MainThread) [homeassistant.components.sensor] eight_sleep: Error on device update!
homeassistant    | Traceback (most recent call last):
homeassistant    |   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
homeassistant    |     await entity.async_device_update(warning=False)
homeassistant    |   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 633, in async_device_update
homeassistant    |     await task
homeassistant    |   File "/usr/src/homeassistant/homeassistant/components/eight_sleep/sensor.py", line 326, in async_update
homeassistant    |     temp = self._eight.room_temperature()
homeassistant    |   File "/usr/local/lib/python3.9/site-packages/pyeight/eight.py", line 195, in room_temperature
homeassistant    |     if obj.current_values['processing']:
homeassistant    |   File "/usr/local/lib/python3.9/site-packages/pyeight/user.py", line 407, in current_values
homeassistant    |     'date': self.current_session_date,
homeassistant    |   File "/usr/local/lib/python3.9/site-packages/pyeight/user.py", line 167, in current_session_date
homeassistant    |     date = self.intervals[0]['ts']
homeassistant    | TypeError: 'NoneType' object is not subscriptable
themistymay commented 2 years ago

We just got our Eight Pod Pro so the account is brand new as well.

mezz64 commented 2 years ago

@themistymay Did this correct itself once you collected some data?

themistymay commented 2 years ago

I will retry. Give me a few days as I'm currently away.

themistymay commented 2 years ago

I have confirmed this is still an issue:

2021-12-16 09:39:09 ERROR (MainThread) [pyeight.eight] Error fetching Eight data: 403
2021-12-16 09:39:09 ERROR (MainThread) [pyeight.user] Unable to fetch eight intervals data.
2021-12-16 09:39:09 ERROR (MainThread) [pyeight.eight] Error fetching Eight data: 403
2021-12-16 09:39:09 ERROR (MainThread) [pyeight.user] Unable to fetch eight trend data.
2021-12-16 09:34:09 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up eight_sleep platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 257, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 613, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 748, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _async_write_ha_state
    state = self._stringify_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 511, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 363, in state
    value = self.native_value
  File "/usr/src/homeassistant/homeassistant/components/eight_sleep/sensor.py", line 173, in native_value
    return self._usrobj.current_sleep_score
  File "/usr/local/lib/python3.9/site-packages/pyeight/user.py", line 237, in current_sleep_score
    score = self.intervals[0]['score']
TypeError: 'NoneType' object is not subscriptable
mezz64 commented 2 years ago

Very late reply, but I noticed in your last snippet you are getting a 403 forbidden error. That usually only happens if the login info is incorrect. Please verify you have it entered correctly in your config. Others have had problems with certain special characters in the past.