milanmeu / pyrituals

Async Python wrapper for the Rituals Perfume Genie API
https://pypi.org/project/pyrituals/
Other
6 stars 0 forks source link

Error when reading attribute speedc #1

Closed tobi-bo closed 3 years ago

tobi-bo commented 3 years ago

In HomeAssistant integration, which uses this library, I get the following error:

ValueError: invalid literal for int() with base 10: ''
2021-07-16 08:29:23 ERROR (MainThread) [homeassistant.components.switch] Error while setting up rituals_perfume_genie platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 258, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 666, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 419, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 456, in _async_write_ha_state
    extra_state_attributes = self.extra_state_attributes
  File "/usr/src/homeassistant/homeassistant/components/rituals_perfume_genie/switch.py", line 50, in extra_state_attributes
    "fan_speed": self._diffuser.perfume_amount,
  File "/usr/local/lib/python3.9/site-packages/pyrituals/__init__.py", line 63, in perfume_amount
    return int(self.hub_data["attributes"]["speedc"])

Versions: Home Assistant: 2021.7.2 pyrituals: 0.0.4

My guess: Either the speedc attribute is incorrect or it is not filled in all cases.

milanmeu commented 3 years ago

Hi @tobi-bo thanks for reporting this issue.

pyrituals

Fan, room and speed are indeed not in the Diffuser data on init, other properties can possibly return wrong/other data (types). It is up to the user of the library to retrieve all data before using these properties. We don't do this by default because not everyone will need this.

Docs: https://github.com/milanmeu/pyrituals/blob/main/README.md#diffuser-data

The docs don't provide more information about which properties are affected because this has changed in the past and can easily be change again (without affecting the official app).

Home Assistant

I have seen similar errors in my test environment and located the issue but I haven't implemented a solution yet.

@tobi-bo, please open a new issue in home-assistant/core as the issue is not in the package and so other Home Assistant users can easily find it. Please mention this issue in the new core issue.

I will try to implement a solution for this before 30 Juli (I don't have my diffuser with me on vacation).


Thanks for the detailed issue description @tobi-bo.

I am closing this issue here as it is in the Home Assistant integration not in the pyrituals package. If you are experiencing this or the related ValueError: 'fanc' exception please report it to the downstream software and mention this issue.

tobi-bo commented 3 years ago

Hi @milanmeu thanks for your quick response.

@tobi-bo, please open a new issue in home-assistant/core as the issue is not in the package and so other Home Assistant users can easily find it. Please mention this issue in the new core issue.

https://github.com/home-assistant/core/issues/53175

bramstroker commented 2 years ago

Please let me know if you want me to create a new issue.

This original issue seems to be the right place to inform you that this issue is still around in HA 2021.12.7. Pollutes my HA error log with a stacktrace each few minutes.

I have no way to suppress this specific error, because it is not catched and handled by homeassistant main code.

2021-12-31 13:35:03 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 134, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 325, in _handle_coordinator_update
    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/number/__init__.py", line 147, in state
    return self.value
  File "/usr/src/homeassistant/homeassistant/components/rituals_perfume_genie/number.py", line 53, in value
    return self._diffuser.perfume_amount
  File "/usr/local/lib/python3.9/site-packages/pyrituals/__init__.py", line 91, in perfume_amount
    return int(self.hub_data["attributes"]["speedc"])
ValueError: invalid literal for int() with base 10: ''