Add dump config service to HomematicIP Cloud#28231
Merged
Merged
Conversation
2 tasks
Contributor
Author
|
Hi @pvizeli , @danielperna84 , |
Contributor
Author
|
Hi @MartinHjelmare, maybe you could look at this PR too. |
MartinHjelmare
requested changes
Nov 2, 2019
|
|
||
| SCHEMA_DUMP_HAP_CONFIG = vol.Schema( | ||
| { | ||
| vol.Required(ATTR_CONFIG_OUTPUT_PATH, default=""): cv.string, |
Member
There was a problem hiding this comment.
I think we should make this optional without default. Use dict.get to return None as default in the service handler.
| """Service to dump the configuration of a Homematic IP Access Point.""" | ||
| config_path = service.data[ATTR_CONFIG_OUTPUT_PATH] or hass.config.config_dir | ||
| config_file_prefix = ( | ||
| service.data[ATTR_CONFIG_OUTPUT_FILE_PREFIX] or DEFAULT_CONFIG_FILE_PREFIX |
Member
There was a problem hiding this comment.
Move the default to the service schema.
| { | ||
| vol.Required(ATTR_CONFIG_OUTPUT_PATH, default=""): cv.string, | ||
| vol.Required(ATTR_CONFIG_OUTPUT_FILE_PREFIX, default=""): cv.string, | ||
| vol.Required(ATTR_ANONYMIZE, default=True): cv.boolean, |
Member
There was a problem hiding this comment.
Items with default should be optional.
| if anonymize: | ||
| hap_sgtin = hap_sgtin[-4:] | ||
|
|
||
| config_file = f"{config_path}/{config_file_prefix}_{hap_sgtin}.json" |
Member
There was a problem hiding this comment.
Use pathlib.Path to construct the path. Use f-strings to create the filename.
|
|
||
| json_state = await hap.home.download_configuration() | ||
| json_state = handle_config(json_state, anonymize) | ||
| open(config_file, mode="w", encoding="utf8").write(json_state) |
Member
There was a problem hiding this comment.
MartinHjelmare
approved these changes
Nov 2, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR adds a service to dump the homematic ip cloud configurarion to a local file.
This can be used for self documention, or to support the development of the unterlying homematicip library.
The current process is really unhandy for normal users.
Pull request with documentation for home-assistant.io: home-assistant/home-assistant.io#10999
Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices: