Skip to content

Add dump config service to HomematicIP Cloud#28231

Merged
fabaff merged 5 commits into
home-assistant:devfrom
SukramJ:HmIP-dumpConfig
Nov 4, 2019
Merged

Add dump config service to HomematicIP Cloud#28231
fabaff merged 5 commits into
home-assistant:devfrom
SukramJ:HmIP-dumpConfig

Conversation

@SukramJ
Copy link
Copy Markdown
Contributor

@SukramJ SukramJ commented Oct 26, 2019

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:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

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

@SukramJ
Copy link
Copy Markdown
Contributor Author

SukramJ commented Nov 1, 2019

Hi @pvizeli , @danielperna84 ,
i think the request for review was started by a homematic related commit that was wrongly added to this branch, but feel free to review if you like.
BR.

@SukramJ
Copy link
Copy Markdown
Contributor Author

SukramJ commented Nov 2, 2019

Hi @MartinHjelmare, maybe you could look at this PR too.
Thanks a lot.


SCHEMA_DUMP_HAP_CONFIG = vol.Schema(
{
vol.Required(ATTR_CONFIG_OUTPUT_PATH, default=""): cv.string,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should make this optional without default. Use dict.get to return None as default in the service handler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

"""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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move the default to the service schema.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

{
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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Items with default should be optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if anonymize:
hap_sgtin = hap_sgtin[-4:]

config_file = f"{config_path}/{config_file_prefix}_{hap_sgtin}.json"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use pathlib.Path to construct the path. Use f-strings to create the filename.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


json_state = await hap.home.download_configuration()
json_state = handle_config(json_state, anonymize)
open(config_file, mode="w", encoding="utf8").write(json_state)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@fabaff fabaff merged commit 7cbd55a into home-assistant:dev Nov 4, 2019
@SukramJ SukramJ deleted the HmIP-dumpConfig branch November 4, 2019 10:20
@lock lock Bot locked and limited conversation to collaborators Nov 5, 2019
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.

4 participants