hasscc / catlink

🐈️ Catlink scooper component for HomeAssistant
Apache License 2.0
28 stars 11 forks source link

[Bug]: 'Device' is not defined #21

Closed fuz2er closed 1 week ago

fuz2er commented 2 weeks ago

labels: ["bug"] assignees: [@al-one, @milosljubenovic]


What happened?

When my catlink account has an unsupported device, the Device class fails to load.

I changed the following code

https://github.com/hasscc/catlink/blob/1c074ef5708fbc154a9bfc875f97c880335f9209/custom_components/catlink/modules/devices_coordinator.py#L16-L18

to

from .account import Account
from .device import Device

and the error was solved. But I don't know if it will cause other problems.

Home Assistant Version

Relevant Log Output

2024-08-31 07:15:05.747 ERROR (MainThread) [custom_components.catlink.const] Unexpected error fetching catlink-xx-xxx-devices data
2024-08-30T23:15:05.762126555Z Traceback (most recent call last):
2024-08-30T23:15:05.762212559Z   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
2024-08-30T23:15:05.762276562Z     self.data = await self._async_update_data()
2024-08-30T23:15:05.762340565Z                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-08-30T23:15:05.762404568Z   File "/config/custom_components/catlink/modules/devices_coordinator.py", line 54, in _async_update_data
2024-08-30T23:15:05.762469571Z     dvc = Device(dat, self)
2024-08-30T23:15:05.762533574Z           ^^^^^^
2024-08-30T23:15:05.762593576Z NameError: name 'Device' is not defined
2024-08-30T23:15:05.781746449Z 2024-08-31 07:15:05.759 ERROR (MainThread) [homeassistant.setup] Error during setup of component catlink
2024-08-30T23:15:05.781932457Z Traceback (most recent call last):
2024-08-30T23:15:05.782002460Z   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
2024-08-30T23:15:05.782050463Z     self.data = await self._async_update_data()
2024-08-30T23:15:05.782261472Z                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-08-30T23:15:05.782324475Z   File "/config/custom_components/catlink/modules/devices_coordinator.py", line 54, in _async_update_data
2024-08-30T23:15:05.782419479Z     dvc = Device(dat, self)
2024-08-30T23:15:05.782472482Z           ^^^^^^
2024-08-30T23:15:05.782513484Z NameError: name 'Device' is not defined
2024-08-30T23:15:05.782633489Z 
2024-08-30T23:15:05.782722493Z The above exception was the direct cause of the following exception:
2024-08-30T23:15:05.782775496Z 
2024-08-30T23:15:05.782830498Z Traceback (most recent call last):
2024-08-30T23:15:05.782922502Z   File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in _async_setup_component
2024-08-30T23:15:05.782985505Z     result = await task
2024-08-30T23:15:05.783049508Z              ^^^^^^^^^^
2024-08-30T23:15:05.783112511Z   File "/config/custom_components/catlink/__init__.py", line 41, in async_setup
2024-08-30T23:15:05.783175514Z     await coordinator.async_config_entry_first_refresh()
2024-08-30T23:15:05.783238517Z   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 288, in async_config_entry_first_refresh
2024-08-30T23:15:05.783302520Z     raise ex
2024-08-30T23:15:05.783365523Z homeassistant.exceptions.ConfigEntryNotReady: name 'Device' is not defined
  ...

Checklist


By submitting this issue, you agree to follow our Code of Conduct.

milosljubenovic commented 2 weeks ago

Hi @fuz2er! ✌️

Thanks for noticing that. It won't cause any other issues, as type checking was due to circular import, which was resolved by modular design for the component.

You can indeed create PR to fix that!