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

fix for state.persist #332

Merged
merged 10 commits into from
Mar 7, 2022
Merged

Conversation

dlashua
Copy link
Contributor

@dlashua dlashua commented Mar 4, 2022

fixes #331

@dlashua
Copy link
Contributor Author

dlashua commented Mar 4, 2022

The failing tests are due to the use of internal class properties externally.

The correct way to handle is it to write a class that extends RestoreEntity and provides methods to set these properties. However, as is, it should resolve the 2022.3 compatibility issues. Then, after some thought on how to implement this in a way that exposes entities to userland pyscripts, this temporary fix can be adjusted to fit in line with that plan.

@stefanuytterhoeven
Copy link

Made the changes to my state.py, and can confirm it works...

@craigbarratt
Copy link
Member

@dlashua - thanks for the patch! Couple of questions:

  • is this backward compatible with older versions of HA?
  • are there other breaking changes in HA 2022.3?

@dlashua
Copy link
Contributor Author

dlashua commented Mar 5, 2022

  • is this backward compatible with older versions of HA?

I don't think so. async_restore_entity_added was modified to expect an object passed to it. It then accesses attributes of that object. Is there a way to detect HA version and use different code depending on the version?

  • are there other breaking changes in HA 2022.3?

According to the release notes, no. But, the issue fixed here is also not mentioned in the release notes, so maybe?

I've not upgraded to 2022.3 yet, due to a lack of time. I just recently upgraded to 2022.2.

@dlashua
Copy link
Contributor Author

dlashua commented Mar 5, 2022

Oh my... all tests finally passed.

@dlashua dlashua changed the title Temporary fix for state.persist fix for state.persist Mar 5, 2022
@craigbarratt
Copy link
Member

I'm not sure how to detect the HA version, although hopefully it is easy. One approach would be to use try/except clauses to handle the new and old cases (which has the advantage that we don't need to explicitly test for the HA version).

@dlashua
Copy link
Contributor Author

dlashua commented Mar 5, 2022

After I finished fixing all the test failures, this will no longer load in Home Assistant.

ERROR (MainThread) [homeassistant.setup] Setup failed for pyscript: Integration not found.

But the files are in the right place (the same place they were in when I was testing the code changes). I have debug logging turned on and it's not providing any additional information. So... I'm not sure how I broke whatever is now broken.

I even deleted everything, recloned Home Assistant, and recloned the Pyscript component and I still have the same issue.

I'm out of time for now, perhaps @craigbarratt can figure out what went wrong?

@dlashua
Copy link
Contributor Author

dlashua commented Mar 5, 2022

Apparently the devcontainer got corrupted somehow. I have resolved that issue and this loads fine now.

@dlashua
Copy link
Contributor Author

dlashua commented Mar 5, 2022

This is now compatible with HASS Versions < 2022.3.0. I tested with 2022.2.9, but unless really old versions used some other method of restoring state, this should work.

@dlashua
Copy link
Contributor Author

dlashua commented Mar 5, 2022

I am now successfully running this in my "production" Home Assistant on version 2022.2.9.

For those needing a quick fix until this issue is ironed out and merged, you can install the master branch of github.com/dlashua/pyscript. If you use HACS, you can add this repo as a custom repository (it will show up as pyscript_dlashua). Then remove pyscript, install pyscript_dlashua instead, and then restart Home Assistant (apparently, HACS will allow two repos to provide files in the same custom_component at the same time, so, don't install pyscript_dlashua before removing pyscript or unknown things could happen).

@dlashua
Copy link
Contributor Author

dlashua commented Mar 5, 2022

I am now successfully running HASS 2022.3.1 without issues.

@craigbarratt craigbarratt merged commit 0a118b7 into custom-components:master Mar 7, 2022
@craigbarratt
Copy link
Member

Thanks for the fix

I'm going to upgrade some of the versions in tests/requirements_test.txt.

In particular, pytest-homeassistant-custom-component v0.7.0 is based on 2022.3.1 so the next step is to make sure all the tests run with that version.

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

Successfully merging this pull request may close these issues.

state.persist is broken in HA 2022.3
3 participants