From 37e090782d756ecaf7b83f9379c5a4a3021ce3ee Mon Sep 17 00:00:00 2001 From: bj00rn Date: Fri, 15 Nov 2024 13:53:52 +0100 Subject: [PATCH] feat: rename maintenance settings -> installer settings --- README.md | 26 ++++++---- custom_components/saleryd_hrv/__init__.py | 51 ++++++++++++------- custom_components/saleryd_hrv/config_flow.py | 12 ++--- custom_components/saleryd_hrv/const.py | 11 ++-- custom_components/saleryd_hrv/services.yaml | 19 ------- custom_components/saleryd_hrv/strings.json | 20 ++++---- .../saleryd_hrv/translations/en.json | 18 +++---- 7 files changed, 83 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 27f9bfe..0ad62c8 100644 --- a/README.md +++ b/README.md @@ -71,16 +71,24 @@ Switch | Description | State attributes ## Services +### Normal operation + +Control normal operation of the unit Name | Description | Fields -- | -- | -- `set_cooling_mode` | Set cooling mode | device: `str` target device, value: `integer` (0=On, 1=Off) `set_fireplace_mode` | Set fireplace mode | device: `str` target device, value: `integer` (0=On, 1=Off) `set_temperature_mode` | Set temperature mode | device: `str` target device, value: `integer` (0=Normal,1=Economy,2=Cool) `set_ventilation_mode` | Set ventilation mode | device: `str` target device, value: `integer` (0=Home,1=Away,2=Boost) -`set_system_active_mode` | Set system active mode. (Maintenance settings must be enabled) | device: `str` target device, value: `integer` (0=Off,1=On,2=Reset) -`set_target_temperature_normal` | Set target temperature for normal temperature mode. (Maintenance settings must be enabled) | device: `str` target device, value: `number` (temperature 10-30 degrees celcius) -`set_target_temperature_cool` | Set target temperature for cool temperature mode. (Maintenance settings must be enabled) | device: `str` target device, value: `number` (temperature 10-30 degrees celcius) -`set_target_temperature_economy` | Set target temperature for economy temperature mode. (Maintenance settings must be enabled) | device: `str` target device, value: `number` (temperature 10-30 degrees celcius) + +### Installer settings +Alter installer settings of the unit, Installer settings must be enabled. +Name | Description | Fields +-- | -- | -- +`set_system_active_mode` | Set system active mode`*`| device: `str` target device, value: `integer` (0=Off,1=On,2=Reset) +`set_target_temperature_normal` | Set target temperature for normal temperature mode`*`| device: `str` target device, value: `number` (temperature 10-30 degrees celcius) +`set_target_temperature_cool` | Set target temperature for cool temperature mode`*`| device: `str` target device, value: `number` (temperature 10-30 degrees celcius) +`set_target_temperature_economy` | Set target temperature for economy temperature mode`*`| device: `str` target device, value: `number` (temperature 10-30 degrees celcius) ## Experimental features @@ -134,8 +142,8 @@ Setting | Description | Default Name | System name. Must be unique. | Websocket IP | IP adress of the HRV system on the local WIFI network | Port | Port number for websocket connection | 3001 -Enable maintenance settings | Enable altering HRV system configuration set by the installer from Home Assistant. Don't alter these settings unless you know what you are doing | False -Maintenance password | Maintenance password. Required for maintenance settings | +Enable installer settings | Altering HRV system configuration set by the installer from Home Assistant. Don't alter these settings unless you know what you are doing | False +Installer password | Installer password. Required for installer settings | ## Troubleshooting @@ -146,9 +154,9 @@ Maintenance password | Maintenance password. Required for maintenance settings * Confirm websocket port by connecting to the UI using a browser and take note of websocket port using debug console in browser. * The system HRV can only handle a few connected clients. Shut down any additional clients/browsers and try again. -### I can't modify maintenance settings -* Ensure maintenance settings are enabled in integration configuration -* Ensure maintenace password is correct +### I can't modify installer settings +* Ensure installer settings are enabled in integration configuration +* Ensure installer password is correct ### Contributing diff --git a/custom_components/saleryd_hrv/__init__.py b/custom_components/saleryd_hrv/__init__.py index e4ae559..9a14137 100644 --- a/custom_components/saleryd_hrv/__init__.py +++ b/custom_components/saleryd_hrv/__init__.py @@ -21,13 +21,15 @@ type SalerydLokeConfigurationEntry = ConfigEntry[SalerydLokeDataUpdateCoordinator] from .const import ( - CONF_ENABLE_MAINTENANCE_SETTINGS, - CONF_MAINTENANCE_PASSWORD, + CONF_ENABLE_INSTALLER_SETTINGS, + CONF_INSTALLER_PASSWORD, CONF_VALUE, CONF_WEBSOCKET_IP, CONF_WEBSOCKET_PORT, CONFIG_VERSION, DEFAULT_NAME, + DEPRECATED_CONF_ENABLE_MAINTENANCE_SETTINGS, + DEPRECATED_CONF_MAINTENANCE_PASSWORD, DOMAIN, LOGGER, PLATFORMS, @@ -61,8 +63,8 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if entry.version is None or entry.version < 2: new_data = entry.data.copy() new_data |= { - CONF_ENABLE_MAINTENANCE_SETTINGS: False, - CONF_MAINTENANCE_PASSWORD: None, + CONF_ENABLE_INSTALLER_SETTINGS: False, + CONF_INSTALLER_PASSWORD: None, } LOGGER.info("Upgrading entry to version 2") @@ -77,6 +79,21 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: unique_id=unique_id, ) + if entry.version is None or entry.version < 4: + new_data = entry.data.copy() + new_data[CONF_ENABLE_INSTALLER_SETTINGS] = new_data.pop( + DEPRECATED_CONF_ENABLE_MAINTENANCE_SETTINGS + ) + new_data[CONF_INSTALLER_PASSWORD] = new_data.pop( + DEPRECATED_CONF_MAINTENANCE_PASSWORD + ) + + hass.config_entries.async_update_entry( + entry, + new_data, + version=4, + ) + return True @@ -103,15 +120,21 @@ def _get_entry_from_service_data( def setup_hass_services(hass: HomeAssistant) -> None: """Register ingegration services.""" - async def control_request(call: ServiceCall, key, authenticate=False): + async def control_request(call: ServiceCall, key, installer_setting=False): """Helper for system control calls""" entry = _get_entry_from_service_data(hass, call.data) value = call.data.get(CONF_VALUE) + device = call.data.get(CONF_DEVICE) coordinator: SalerydLokeDataUpdateCoordinator = entry.runtime_data - if authenticate: - maintenance_password = entry.data.get(CONF_MAINTENANCE_PASSWORD) - LOGGER.debug("Unlock maintenance settings control request") - await coordinator.client.send_command("IP", maintenance_password) + if installer_setting: + installer_settings_enabled = entry.data.get(CONF_ENABLE_INSTALLER_SETTINGS) + if not installer_settings_enabled: + raise HomeAssistantError( + "Installer settings not enabled for device %s", device + ) + installer_password = entry.data.get(CONF_INSTALLER_PASSWORD) + LOGGER.debug("Sending unlock installer settings control request") + await coordinator.client.send_command("IP", installer_password) LOGGER.debug("Sending control request %s with payload %s", key, value) await coordinator.client.send_command(key, value) @@ -155,7 +178,7 @@ async def set_target_temperature_economy(call: ServiceCall): SERVICE_SET_TEMPERATURE_MODE: set_temperature_mode, } - maintenance_services = { + installer_services = { SERVICE_SET_SYSTEM_ACTIVE_MODE: set_system_active_mode, SERVICE_SET_TARGET_TEMPERATURE_COOL: set_target_temperature_cool, SERVICE_SET_TARGET_TEMPERATURE_ECONOMY: set_target_temperature_economy, @@ -163,13 +186,7 @@ async def set_target_temperature_economy(call: ServiceCall): } # register services - for key, fn in services.items(): - if hass.services.has_service(DOMAIN, key): - continue - hass.services.async_register(DOMAIN, key, fn) - - # register maintenance services - for key, fn in maintenance_services.items(): + for key, fn in (services | installer_services).items(): if hass.services.has_service(DOMAIN, key): continue hass.services.async_register(DOMAIN, key, fn) diff --git a/custom_components/saleryd_hrv/config_flow.py b/custom_components/saleryd_hrv/config_flow.py index e68f33a..666fdbe 100644 --- a/custom_components/saleryd_hrv/config_flow.py +++ b/custom_components/saleryd_hrv/config_flow.py @@ -12,8 +12,8 @@ import voluptuous as vol from .const import ( - CONF_ENABLE_MAINTENANCE_SETTINGS, - CONF_MAINTENANCE_PASSWORD, + CONF_ENABLE_INSTALLER_SETTINGS, + CONF_INSTALLER_PASSWORD, CONF_WEBSOCKET_IP, CONF_WEBSOCKET_PORT, CONFIG_VERSION, @@ -25,8 +25,8 @@ RECONFIG_DATA = { vol.Required(CONF_WEBSOCKET_IP): str, vol.Required(CONF_WEBSOCKET_PORT): int, - vol.Optional(CONF_ENABLE_MAINTENANCE_SETTINGS): vol.Coerce(bool), - vol.Optional(CONF_MAINTENANCE_PASSWORD): str, + vol.Optional(CONF_ENABLE_INSTALLER_SETTINGS): vol.Coerce(bool), + vol.Optional(CONF_INSTALLER_PASSWORD): str, } CONFIG_DATA = { @@ -81,8 +81,8 @@ async def async_step_user(self, user_input=None): CONF_NAME: DEFAULT_NAME, CONF_WEBSOCKET_IP: "192.168.1.151", CONF_WEBSOCKET_PORT: 3001, - CONF_ENABLE_MAINTENANCE_SETTINGS: False, - CONF_MAINTENANCE_PASSWORD: "", + CONF_ENABLE_INSTALLER_SETTINGS: False, + CONF_INSTALLER_PASSWORD: "", } return self.async_show_form( diff --git a/custom_components/saleryd_hrv/const.py b/custom_components/saleryd_hrv/const.py index c4d7650..e30739f 100644 --- a/custom_components/saleryd_hrv/const.py +++ b/custom_components/saleryd_hrv/const.py @@ -10,7 +10,7 @@ ISSUE_URL = "https://github.com/bj00rn/ha-saleryd-ftx/issues" SUPPORTED_FIRMWARES = ["4.1.5"] UNSUPPORTED_FIRMWARES = ["4.1.1"] -CONFIG_VERSION = 3 +CONFIG_VERSION = 4 # Icons ICON = "mdi:format-quote-close" @@ -26,8 +26,8 @@ CONF_ENABLED = "enabled" CONF_WEBSOCKET_IP = "websocket_ip" CONF_WEBSOCKET_PORT = "websocket_port" -CONF_MAINTENANCE_PASSWORD = "maintenance_password" -CONF_ENABLE_MAINTENANCE_SETTINGS = "enable_maintenance_settings" +CONF_INSTALLER_PASSWORD = "installer_password" +CONF_ENABLE_INSTALLER_SETTINGS = "enable_installer_settings" CONF_VALUE = "value" # Defaults @@ -71,10 +71,13 @@ SERVICE_SET_COOLING_MODE = "set_cooling_mode" SERVICE_SET_VENTILATION_MODE = "set_ventilation_mode" SERVICE_SET_TEMPERATURE_MODE = "set_temperature_mode" -SERVICE_UNLOCK_MAINTENANCE_SETTINGS = "unlock_maintenance_settings" SERVICE_SET_SYSTEM_ACTIVE_MODE = "set_system_active_mode" SERVICE_SET_TARGET_TEMPERATURE_COOL = "set_target_temperature_cool" SERVICE_SET_TARGET_TEMPERATURE_NORMAL = "set_target_temperature_normal" SERVICE_SET_TARGET_TEMPERATURE_ECONOMY = "set_target_temperature_economy" LOGGER: Logger = getLogger(__package__) + +# Deprecated constants kept for migrations +DEPRECATED_CONF_MAINTENANCE_PASSWORD = "maintenance_password" +DEPRECATED_CONF_ENABLE_MAINTENANCE_SETTINGS = "enable_maintenance_settings" diff --git a/custom_components/saleryd_hrv/services.yaml b/custom_components/saleryd_hrv/services.yaml index 37f0c8f..06faaed 100644 --- a/custom_components/saleryd_hrv/services.yaml +++ b/custom_components/saleryd_hrv/services.yaml @@ -103,25 +103,6 @@ set_system_active_mode: min: 0 max: 2 mode: slider -unlock_maintenance_settings: - name: Unlock maintenance settings - description: Unlock maintenance settings - fields: - device: - name: Device - description: Target device - required: True - selector: - device: - integration: saleryd_hrv - value: - name: Value - description: Maintenance password - example: "6666" - required: true - selector: - text: - type: password set_target_temperature_normal: name: Set normal target temperature description: Set target temperature for normal temperature mode diff --git a/custom_components/saleryd_hrv/strings.json b/custom_components/saleryd_hrv/strings.json index 74721f7..18204a5 100644 --- a/custom_components/saleryd_hrv/strings.json +++ b/custom_components/saleryd_hrv/strings.json @@ -2,35 +2,35 @@ "config": { "step": { "user": { - "description": "Follow instructions in manual to connect the HRV unit to local network and enter connection details below.", + "description": "Follow instructions in manual to connect the HRV unit to local network and enter connection details below", "data": { "name": "Name", "websocket_ip": "IP adress", "websocket_port": "Port", - "enable_maintenance_settings": "Enable maintenance settings?", - "maintenance_password": "Maintenance password" + "enable_installer_settings": "Enable installer settings?", + "installer_password": "Installer password" }, "data_description": { "websocket_ip": "IP adress of the HRV system on the local network", "websocket_port": "Port. Default is 3001", - "enable_maintenance_settings": "Enable altering HRV system configuration from Home Assistant. Don't alter maintenance settings unless you know what you are doing", - "maintenance_password": "Required for maintenance settings" + "enable_installer_settings": "Enable installer settings?", + "installer_password": "Installer password" } }, "reconfigure": { - "description": "Follow instructions in manual to connect the HRV unit to local network and enter connection details below.", + "description": "Follow instructions in manual to connect the HRV unit to local network and enter connection details below", "data": { "name": "Name", "websocket_ip": "IP adress", "websocket_port": "Port", - "enable_maintenance_settings": "Enable maintenance settings?", - "maintenance_password": "Maintenance password" + "enable_installer_settings": "Enable installer settings?", + "installer_password": "Installer password" }, "data_description": { "websocket_ip": "IP adress of the HRV system on the local network", "websocket_port": "Port. Default is 3001", - "enable_maintenance_settings": "Enable altering HRV system configuration from Home Assistant. Don't alter maintenance settings unless you know what you are doing", - "maintenance_password": "Required for maintenance settings" + "enable_installer_settings": "Alter installer settings from Home Assistant. Don't alter installer settings unless you know what you are doing", + "installer_password": "Required for installer settings" } } }, diff --git a/custom_components/saleryd_hrv/translations/en.json b/custom_components/saleryd_hrv/translations/en.json index 81eca83..18204a5 100644 --- a/custom_components/saleryd_hrv/translations/en.json +++ b/custom_components/saleryd_hrv/translations/en.json @@ -7,30 +7,30 @@ "name": "Name", "websocket_ip": "IP adress", "websocket_port": "Port", - "enable_maintenance_settings": "Enable maintenance settings?", - "maintenance_password": "Maintenance password" + "enable_installer_settings": "Enable installer settings?", + "installer_password": "Installer password" }, "data_description": { "websocket_ip": "IP adress of the HRV system on the local network", "websocket_port": "Port. Default is 3001", - "enable_maintenance_settings": "Enable altering HRV system configuration from Home Assistant. Don't alter maintenance settings unless you know what you are doing", - "maintenance_password": "Required for maintenance settings" + "enable_installer_settings": "Enable installer settings?", + "installer_password": "Installer password" } }, "reconfigure": { - "description": "Follow instructions in manual to connect the HRV unit to local network and enter connection details below.", + "description": "Follow instructions in manual to connect the HRV unit to local network and enter connection details below", "data": { "name": "Name", "websocket_ip": "IP adress", "websocket_port": "Port", - "enable_maintenance_settings": "Enable maintenance settings?", - "maintenance_password": "Maintenance password" + "enable_installer_settings": "Enable installer settings?", + "installer_password": "Installer password" }, "data_description": { "websocket_ip": "IP adress of the HRV system on the local network", "websocket_port": "Port. Default is 3001", - "enable_maintenance_settings": "Enable altering HRV system configuration from Home Assistant. Don't alter maintenance settings unless you know what you are doing", - "maintenance_password": "Required for maintenance settings" + "enable_installer_settings": "Alter installer settings from Home Assistant. Don't alter installer settings unless you know what you are doing", + "installer_password": "Required for installer settings" } } },