Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not compatible with Python 3.11 #17

Closed
syphernl opened this issue May 10, 2023 · 6 comments
Closed

Not compatible with Python 3.11 #17

syphernl opened this issue May 10, 2023 · 6 comments

Comments

@syphernl
Copy link

After updating Python to 3.11 this component is failing:

2023-05-10 10:20:32.082 ERROR (MainThread) [homeassistant.loader] Unexpected exception importing component custom_components.saver
Traceback (most recent call last):
  File "/srv/hass/lib/python3.11/site-packages/homeassistant/loader.py", line 813, in get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/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 "/home/hass/.homeassistant/custom_components/saver/__init__.py", line 77, in <module>
    class SaverEntity(RestoreEntity):
  File "/home/hass/.homeassistant/custom_components/saver/__init__.py", line 149, in SaverEntity
    @asyncio.coroutine
     ^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio' has no attribute 'coroutine'
@PiotrMachowski
Copy link
Owner

Can you try to make a following change in the code (in __init__.py file) and check if it works?

...
-    @asyncio.coroutine
-    def async_added_to_hass(self):
-        state = yield from self.async_get_last_state()
+    async def async_added_to_hass(self):
+        state = await self.async_get_last_state()
         if state is not None \
                 and state.attributes is not None \
...

@syphernl
Copy link
Author

After changing that a new error popups up:

Traceback (most recent call last):
  File "/srv/hass/lib/python3.11/site-packages/homeassistant/loader.py", line 813, in get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/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 936, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1074, in get_code
  File "<frozen importlib._bootstrap_external>", line 1004, in source_to_code
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/hass/.homeassistant/custom_components/saver/__init__.py", line 150
    state = yield from self.async_get_last_state()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'yield from' inside async function

@PiotrMachowski
Copy link
Owner

It looks like you haven't applied all changes from the fragment I have posted above. The updated code should look the following way:

    @property
    def state(self):
        return len(self._entities_db) + len(self._variables_db)

    async def async_added_to_hass(self):
        state = await self.async_get_last_state()
        if state is not None \
                and state.attributes is not None \
                and "variables" in state.attributes and not isinstance(state.attributes["entities"], list) \
                and "entities" in state.attributes and not isinstance(state.attributes["variables"], list):
            self._variables_db = state.attributes["variables"]
            self._entities_db = state.attributes["entities"]

@syphernl
Copy link
Author

state = await self.async_get_last_state()

Ah you're right. I only changed the first part earlier today. The full change seems to work fine as entity saver.saver is now back.

@PiotrMachowski
Copy link
Owner

Great, thank you. I will adjust the integration 👍

@PiotrMachowski
Copy link
Owner

Fixed in v1.1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants