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

Add storage helper and migrate config entries #15045

Merged
merged 8 commits into from
Jun 25, 2018
Merged

Add storage helper and migrate config entries #15045

merged 8 commits into from
Jun 25, 2018

Conversation

balloob
Copy link
Member

@balloob balloob commented Jun 18, 2018

Description:

This adds a storage helper. This will make it easier for components and core pieces to store and load data.

  • Stored data needs to be JSON serializable. However when and where the config is stored is opaque to the developer. This leaves options open for the future 👍
  • Optionally add a write delay in case you expect a lot of writes
  • If delayed write is scheduled, load will return correct config
  • If delayed write, shutting down Home Assistant will trigger the write
  • Add a migrator from old formats so that it helps existing code migrate to the storage helper.
  • Track versioned data and migrate if necessary

Since I did not want to add logic that is unused, I've migrated the config entries logic to use the new storage helper.

Bonus:

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@balloob
Copy link
Member Author

balloob commented Jun 19, 2018

To do: pass in version and migrate function to store constructor -> DONE

except json.SerializationError as err:
_LOGGER.error('Error writing config for %s: %s', self.key, err)
except json.WriteError as err:
_LOGGER.error('Error writing config for %s: %s', self.key, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should take that toggether like:
except (json.xy, json.ser) as err:

self._async_cleanup_delay_listener()
await self._handle_write_data()

async def _handle_write_data(self, *_args):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you use for all async function async. That is the only function they use a other name concept

@pvizeli
Copy link
Member

pvizeli commented Jun 20, 2018

Future: It would be nice to add a voluptuous schema for data partition. That make it easy to add defaults or changes over the schema.

@balloob
Copy link
Member Author

balloob commented Jun 21, 2018

I don't want to include voluptuous, the idea is that this is written/read by code, not humans. If defaults change, they can do a one time migration to create those. It should not run on every run.

Copy link
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplify the code, I suggest to register the STOP event once and if they is reach, we can check if data are available and write it down or do nothing. So we need only handle the delay listener and can cleanup a lot of logic and code.

@balloob
Copy link
Member Author

balloob commented Jun 25, 2018

I don't want to register the STOP event during initialization because it means that startup of Home Assistant is slower. With the current logic, although it looks a bit complicated, we make sure that we only register handlers when we need it and and as little as possible.

@balloob balloob merged commit ae51dc0 into dev Jun 25, 2018
@ghost ghost removed the in progress label Jun 25, 2018
@balloob balloob deleted the storage-helper branch June 25, 2018 16:53
pvizeli added a commit that referenced this pull request Jun 25, 2018
pvizeli added a commit that referenced this pull request Jun 25, 2018
* Revert "Fix #14919. Should throw exception when camera stream closed by frontend (#15028)"

This reverts commit 508d045.

* Revert "Fix pylintrc section order and option placements (#15120)"

This reverts commit dbae410.

* Revert "Add storage helper and migrate config entries (#15045)"

This reverts commit ae51dc0.

* Revert "Add language to dark sky weather component (#15130)"

This reverts commit 672a3c7.
@balloob balloob mentioned this pull request Jul 6, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants