EuleMitKeule / device-tools

Device Tools: Create, modify and merge your Home Assistant devices.
72 stars 6 forks source link

'DeviceTools' object has no attribute '_device_modifications' #8

Closed bakerkj closed 6 months ago

bakerkj commented 6 months ago

I am running home assistant 2024.5 with device tools 1.8.2 and on startup I received the following traceback.

2024-05-01 16:44:40.870 ERROR (MainThread) [custom_components.device_tools] 'DeviceTools' object has no attribute '_device_modifications'
Traceback (most recent call last):
  File "/config/custom_components/device_tools/device_tools.py", line 84, in async_run
    self.async_get_entries()
  File "/config/custom_components/device_tools/device_tools.py", line 72, in async_get_entries
    if self._device_modifications == device_modifications:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'DeviceTools' object has no attribute '_device_modifications'
bakerkj commented 6 months ago

Could this be because self._run_task is being initilzied before self._device_modifications?


class DeviceTools:
    ...
    def __init__(self, hass: HomeAssistant, logger: logging.Logger) -> None:
        ...
        self._run_task = hass.async_create_background_task(self.async_run(), DOMAIN)
        self._device_modifications: dict[str, DeviceModification] = {}
        ....
`
EuleMitKeule commented 6 months ago

Yes, could be. Maybe you could try switching those statements and if it works open a PR?

bakerkj commented 6 months ago

Will do! I'll keep you posted.

bakerkj commented 6 months ago

@EuleMitKeule, I made the change. I have rebooted twice without seeing the same error again. I think the change is safe to merge as is, but I am happy to run with it this way awhile longer, and reboot a few more times and report back if you prefer.

EuleMitKeule commented 6 months ago

The change makes sense to me, I merged it and published a new release. Thank you!