core: Keyboard Remote not working - restart impossible after update to 2023.6.0

The problem

The Keyboard Remote integration fails to load, which prevents Home Assistant Core from restarting and will (I assume) break my system on next “forced” restart (power outage or something like that)

As a temporary workaround, I have restored the last known working backup from 2023.5.4

What version of Home Assistant Core has the issue?

core-2023.6.0

What was the last working version of Home Assistant Core?

core-2023.5.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Keyboard Remote

Link to integration documentation on our website

https://www.home-assistant.io/integrations/keyboard_remote/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.loader
Source: components/keyboard_remote/__init__.py:8
First occurred: 06:56:13 (4 occurrences)
Last logged: 07:13:59

Unexpected exception importing component homeassistant.components.keyboard_remote
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 813, in get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/keyboard_remote/__init__.py", line 8, in <module>
    import aionotify
  File "/usr/local/lib/python3.11/site-packages/aionotify/__init__.py", line 5, in <module>
    from .base import Watcher
  File "/usr/local/lib/python3.11/site-packages/aionotify/base.py", line 10, in <module>
    from . import aioutils
  File "/usr/local/lib/python3.11/site-packages/aionotify/aioutils.py", line 122, in <module>
    @asyncio.coroutine
     ^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio' has no attribute 'coroutine'

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 43 (13 by maintainers)

Most upvoted comments

I suspect that this may be a side-effect of home assistant upgrading to Python 3.11.

I’ll try to look into this soon…

This fix was included in the 2023.6.2 release.

I can confirm that it also happens on my end.

Relevant YAML configuration to reproduce:

keyboard_remote:
  - device_descriptor: "/dev/input/event0"
    type: "key_down"

I’m happy to hear @frenck’s thoughts.

In the meantime, I’ve started re-working the integration to use the asyncinotify instead of aionotify.

@lanrat thanks! “un grand merci d’un petit francais”!

I’ll want to do some more testing, but I think I have the component updated to fully work with python 3.11.

If anyone is willing to help me test, replace the keyboard_remote directory of your install with the one from my branch here.

The entire keyboard_remote integration might need to be rewritten.

aionotify depends on asynctest which also does not have support for Python 3.11 and has been abandoned.

I am not the original author of keyboard_remote, I’m just a heavy user who has submitted a few patches before.

@frenck Maybe good to have you involved as well. For me, and probably more users, this is core functionality for my home assistant and will prevent me from updating until this is solved 😦 Unfortunately I don’t have the skill at the moment to support.

@Aaroneisele55

Can I somehow use that updated keyboard remote integration in my setup (HA OS) or do I have to wait for PyPi to be updated with the new aionotify version?

Not yet. Even without the PyPi problem, there are still bugs in the code that I’m working on fixing first. I’ll post here once more progress is made.

I’ve started work on a fix, but it appears to need more work that I initially thought.

  1. The latest aionotify library in pypi does not support Python 3.11, and appears to not have much active development.
  2. The fork of aionotify with support for Python 3.11 (https://github.com/rickwierenga/aionotify) is not on pypi, which is a requirement for being in included in HomeAssistant.
  3. The changes to aionotify and Python 3.11 will need some more of this integration to be worked out.

My branch with my fixes can be found here: https://github.com/lanrat/hass_core/tree/keyboard_Remote_py3.11

So far, I have upgraded aionotify and evdev to support Python 3.11, but until aionotify is in pypi, it won’t be able to be merged. There are some other misc logic errors too that have yet to be solved.

@Aaroneisele55 I think that’s the exact issue. I hope to experiment with this this weekend to verify a fix. But I welcome a PR if someone has time to get to it before me.

Hello, I checked the asyncio code and found the error, and someone else has already forked the repo with the error fixed in his version: https://github.com/rickwierenga/aionotify Could someone test if this fixes the error?