jpcornil-git / HA-mcp23017

MCP23017 implementation for Home Assistant (threadsafe, lower latency and config flow support)
18 stars 7 forks source link

hass.components.persistent_notification deprecation #29

Closed glcos closed 4 months ago

glcos commented 4 months ago

I attempted to create a sensor with a wrong I2C address and HA created a notification. In the log I see this (notice the last line):

2024-07-14 10:15:12.261 ERROR (SyncWorker_52) [custom_components.mcp23017] Unable to access mcp23017-0x20 ([Errno 121] Remote I/O error)
2024-07-14 10:15:22.261 WARNING (MainThread) [homeassistant.components.binary_sensor] Setup of binary_sensor platform mcp23017 is taking over 10 seconds.
2024-07-14 10:16:12.261 ERROR (MainThread) [homeassistant.components.binary_sensor] Setup of platform mcp23017 is taking longer than 60 seconds. Startup will proceed without waiting any longer.
2024-07-14 10:16:12.265 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry 0x20:pin 7 ('mains_power_detected':binary_sensor) for mcp23017
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/mcp23017/__init__.py", line 213, in __init__
    self._bus.read_byte(self._address)
  File "/srv/homeassistant/lib/python3.12/site-packages/smbus2/smbus2.py", line 396, in read_byte
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/mcp23017/__init__.py", line 166, in async_get_or_create
    component = await hass.async_add_executor_job(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/mcp23017/__init__.py", line 220, in __init__
    raise ValueError(error) from error
ValueError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/config_entries.py", line 801, in async_unload
    result = await component.async_unload_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/mcp23017/__init__.py", line 146, in async_unload_entry
    type(component).__name__,
         ^^^^^^^^^
UnboundLocalError: cannot access local variable 'component' where it is not associated with a value
2024-07-14 10:16:12.277 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'mcp23017' accesses hass.components.persistent_notification. This is deprecated and will stop working in Home Assistant 2024.9, it should be updated to import functions used from persistent_notification directly at custom_components/mcp23017/__init__.py, line 194: hass.components.persistent_notification.create(, please create a bug report at https://github.com/jpcornil-git/HA-mcp23017/issues

This is not an urgent issue as the integration is running absolutely fine, but I think it is worth reporting in order to improve code quality.

jpcornil-git commented 4 months ago

Thanks for reporting (I'll have to fix anyway in a few months) !

Could you try b89d7dd ? (the deprecation warning as well as the stack trace are addressed in 889617c but I added a better config flow handling for wrong i2c address on top of it)

Cheers, jpc

glcos commented 4 months ago

I tested the latest code, no warnings on log file and integration working properly. Attempted to configure an I2C entity with wrong address on purpose, now I get a popup telling so.

immagine

I would say that now everything is working as expected!

jpcornil-git commented 4 months ago

I just made a new release that includes these two changes. Thanks again for reporting/testing Cheers, jpc