-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add dump config service to HomematicIP Cloud #28231
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import logging | ||
|
|
||
| from homematicip.aio.group import AsyncHeatingGroup | ||
| from homematicip.base.helpers import handle_config | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
|
|
@@ -26,17 +27,23 @@ | |
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| ATTR_ACCESSPOINT_ID = "accesspoint_id" | ||
| ATTR_ANONYMIZE = "anonymize" | ||
| ATTR_CLIMATE_PROFILE_INDEX = "climate_profile_index" | ||
| ATTR_CONFIG_OUTPUT_FILE_PREFIX = "config_output_file_prefix" | ||
| ATTR_CONFIG_OUTPUT_PATH = "config_output_path" | ||
| ATTR_DURATION = "duration" | ||
| ATTR_ENDTIME = "endtime" | ||
| ATTR_TEMPERATURE = "temperature" | ||
| ATTR_ACCESSPOINT_ID = "accesspoint_id" | ||
|
|
||
| DEFAULT_CONFIG_FILE_PREFIX = "hmip-config" | ||
|
|
||
| SERVICE_ACTIVATE_ECO_MODE_WITH_DURATION = "activate_eco_mode_with_duration" | ||
| SERVICE_ACTIVATE_ECO_MODE_WITH_PERIOD = "activate_eco_mode_with_period" | ||
| SERVICE_ACTIVATE_VACATION = "activate_vacation" | ||
| SERVICE_DEACTIVATE_ECO_MODE = "deactivate_eco_mode" | ||
| SERVICE_DEACTIVATE_VACATION = "deactivate_vacation" | ||
| SERVICE_DUMP_HAP_CONFIG = "dump_hap_config" | ||
| SERVICE_SET_ACTIVE_CLIMATE_PROFILE = "set_active_climate_profile" | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema( | ||
|
|
@@ -96,6 +103,14 @@ | |
| } | ||
| ) | ||
|
|
||
| SCHEMA_DUMP_HAP_CONFIG = vol.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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Items with default should be optional.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| } | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: | ||
| """Set up the HomematicIP Cloud component.""" | ||
|
|
@@ -239,6 +254,33 @@ async def _set_active_climate_profile(service): | |
| schema=SCHEMA_SET_ACTIVE_CLIMATE_PROFILE, | ||
| ) | ||
|
|
||
| async def _async_dump_hap_config(service): | ||
| """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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the default to the service schema.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| ) | ||
| anonymize = service.data[ATTR_ANONYMIZE] | ||
|
|
||
| for hap in hass.data[DOMAIN].values(): | ||
| hap_sgtin = hap.config_entry.title | ||
|
|
||
| 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. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| hass.services.async_register( | ||
| DOMAIN, | ||
| SERVICE_DUMP_HAP_CONFIG, | ||
| _async_dump_hap_config, | ||
| schema=SCHEMA_DUMP_HAP_CONFIG, | ||
| ) | ||
|
|
||
| def _get_home(hapid: str): | ||
| """Return a HmIP home.""" | ||
| hap = hass.data[DOMAIN].get(hapid) | ||
|
|
||
There was a problem hiding this comment.
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
Noneas default in the service handler.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done