jpcornil-git / HA-mcp23017

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

Deprecation warnings since Home Assistant 2022.6.0 #9

Closed megapearl closed 2 years ago

megapearl commented 2 years ago

Hi,

After updating to Home Assistant 2022.6.0 the component gives some deprecation warnings:

Logger: homeassistant.helpers.frame
Source: helpers/frame.py:103
First occurred: 10:47:43 (1 occurrences)
Last logged: 10:47:43

Detected integration that uses deprecated `async_get_registry` to access device registry, use async_get instead. Please report issue to the custom component author for mcp23017 using this method at custom_components/mcp23017/__init__.py, line 150: devices = await device_registry.async_get_registry(hass)

I tried to change 'devices = await device_registry.async_get_registry(hass)' to 'devices = await device_registry.async_get(hass)' at line 150 in init.py as mentioned above, but that gives the error below, so it's not as simple as that unfortunately.

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/mcp23017/binary_sensor.py", line 72, in async_setup_entry
    binary_sensor_entity.device = await async_get_or_create(
  File "/home/homeassistant/.homeassistant/custom_components/mcp23017/__init__.py", line 150, in async_get_or_create
    devices = await device_registry.async_get(hass)
TypeError: object DeviceRegistry can't be used in 'await' expression

The component though is working fine, so no rush, but if you have some time maybe you can look into it.

Best Regards, Donald..

jpcornil-git commented 2 years ago

Thank for the head up.

I just committed https://github.com/jpcornil-git/HA-mcp23017/commit/66cb6d1fe32bc78829c4712effcd4a3a4cb93682 to address this -> could you give it a try (I've not upgraded yet and therefore unable to test right now) ?

async_get_registry was a coroutine (L718 of https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/device_registry.py#L705) while async_get is not (cfr. L705 ) and shouldn't therefore be awaited.

megapearl commented 2 years ago

Tested Commit #66cb6d1 (using HACS 'main' branch) and this does not give any deprecation warnings anymore. And tested the binary_sensors and switches, all still working as expected.

Thanks Again!

jpcornil-git commented 2 years ago

This is now included in v1.1.1 (bumped homeassistant requirement to 2021.3.0 to match related change)