From cc321ff584164996c6fa15005434f17d7426b486 Mon Sep 17 00:00:00 2001 From: Benjamin <78026082+benjamin-dcs@users.noreply.github.com> Date: Sat, 8 Feb 2025 20:49:23 +0100 Subject: [PATCH] Customizable entry config --- custom_components/ithodaalderop/__init__.py | 17 ++- .../ithodaalderop/config_flow.py | 101 +++++++++++++++--- custom_components/ithodaalderop/const.py | 6 +- .../ithodaalderop/definitions/base.py | 1 + custom_components/ithodaalderop/manifest.json | 2 +- .../ithodaalderop/sensors/autotemp.py | 22 ++-- .../ithodaalderop/sensors/base.py | 85 ++++++++++++--- .../ithodaalderop/sensors/co2_remote.py | 6 +- .../ithodaalderop/sensors/fan.py | 22 ++-- .../ithodaalderop/sensors/last_command.py | 6 +- .../ithodaalderop/sensors/wpu.py | 10 +- .../ithodaalderop/translations/en.json | 12 ++- .../ithodaalderop/translations/nl.json | 12 ++- 13 files changed, 238 insertions(+), 64 deletions(-) diff --git a/custom_components/ithodaalderop/__init__.py b/custom_components/ithodaalderop/__init__.py index ed3f035..96c8e5c 100644 --- a/custom_components/ithodaalderop/__init__.py +++ b/custom_components/ithodaalderop/__init__.py @@ -4,7 +4,12 @@ from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from .const import CONF_ADDON_TYPE, CONF_ENTITIES_CREATION_MODE, CONF_NONCVE_MODEL +from .const import ( + CONF_ADDON_TYPE, + CONF_ADVANCED_CONFIG, + CONF_ENTITIES_CREATION_MODE, + CONF_NONCVE_MODEL, +) PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR] @@ -12,7 +17,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the Itho Wifi add-on integration.""" - # Migrate noncve config < v2.2.0 to 2.2.0+ + # Migrate noncve config from < v2.2.0 # < 2.2.0 Only 1 HRU was supported. This was the HRU ECO 350 # So, if no hru_device is setup, this has to be the hru_eco_350 if ( @@ -23,12 +28,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: new_data[CONF_NONCVE_MODEL] = "hru_eco_350" hass.config_entries.async_update_entry(entry, data=new_data) - # Migrate entities_creation_mode config < v2.2.0 to 2.2.0+ + # Migrate entities_creation_mode config from < v2.2.0 if entry.data.get(CONF_ENTITIES_CREATION_MODE) is None: new_data = {**entry.data} new_data[CONF_ENTITIES_CREATION_MODE] = "only_selected" hass.config_entries.async_update_entry(entry, data=new_data) + # Migrate advanced_config config from < 2.5.0 + if entry.data.get(CONF_ADVANCED_CONFIG) is None: + new_data = {**entry.data} + new_data[CONF_ADVANCED_CONFIG] = False + hass.config_entries.async_update_entry(entry, data=new_data) + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True diff --git a/custom_components/ithodaalderop/config_flow.py b/custom_components/ithodaalderop/config_flow.py index c22532f..4c9b02d 100644 --- a/custom_components/ithodaalderop/config_flow.py +++ b/custom_components/ithodaalderop/config_flow.py @@ -15,6 +15,7 @@ from .const import ( ADDON_TYPES, CONF_ADDON_TYPE, + CONF_ADVANCED_CONFIG, CONF_AUTOTEMP_ROOM1, CONF_AUTOTEMP_ROOM2, CONF_AUTOTEMP_ROOM3, @@ -23,6 +24,9 @@ CONF_AUTOTEMP_ROOM6, CONF_AUTOTEMP_ROOM7, CONF_AUTOTEMP_ROOM8, + CONF_CUSTOM_BASETOPIC, + CONF_CUSTOM_DEVICE_NAME, + CONF_CUSTOM_ENTITY_PREFIX, CONF_ENTITIES_CREATION_MODE, CONF_NONCVE_MODEL, CONF_REMOTE_1, @@ -34,6 +38,12 @@ ENTITIES_CREATION_MODES, NONCVE_DEVICES, ) +from .sensors.base import ( + get_default_entity_prefix, + get_default_mqtt_base_topic, + get_device_model, + get_entity_prefix, +) class IthoConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @@ -52,6 +62,33 @@ def _get_reconfigure_value(self, param, default): return self.config[param] return default + async def _set_unique_id(self): + unique_id = f"itho_wifi_addon_{get_entity_prefix(self.config)}" + await self.async_set_unique_id(unique_id) + + def get_entry_title(self): + """Generete title for the entry.""" + + addon_type = self.config[CONF_ADDON_TYPE] + advanced_config = self.config[CONF_ADVANCED_CONFIG] + + title = "Itho WiFi Add-on for " + if addon_type == "noncve": + title = title + ADDON_TYPES[addon_type] + " - " + + if advanced_config: + title = title + self.config[CONF_CUSTOM_DEVICE_NAME] + else: + title = title + NONCVE_DEVICES[self.config[CONF_NONCVE_MODEL]] + + elif advanced_config: + title = title + self.config[CONF_CUSTOM_DEVICE_NAME] + + else: + title = title + ADDON_TYPES[addon_type] + + return title + async def async_step_user(self, user_input: Mapping[str, Any] | None = None): """Configure main step.""" if user_input is not None: @@ -62,10 +99,10 @@ async def async_step_user(self, user_input: Mapping[str, Any] | None = None): return await self.async_step_remotes() if user_input[CONF_ADDON_TYPE] == "noncve": return await self.async_step_noncve_model() + if user_input.get(CONF_ADVANCED_CONFIG, False): + return await self.async_step_advanced_config() - await self.async_set_unique_id( - f"itho_wifi_addon_{self.config[CONF_ADDON_TYPE]}" - ) + await self._set_unique_id() self._abort_if_unique_id_configured() return self.async_create_entry( title=f"Itho WiFi Add-on for {ADDON_TYPES[self.config[CONF_ADDON_TYPE]]}", @@ -92,6 +129,7 @@ async def async_step_user(self, user_input: Mapping[str, Any] | None = None): } } ), + vol.Required(CONF_ADVANCED_CONFIG): selector({"boolean": {}}), } ) @@ -101,12 +139,14 @@ async def async_step_rooms(self, user_input: Mapping[str, Any] | None = None): """Configure rooms for autotemp.""" if user_input is not None: self.config.update(user_input) - await self.async_set_unique_id( - f"itho_wifi_addon_{self.config[CONF_ADDON_TYPE]}" - ) + if self.config[CONF_ADVANCED_CONFIG]: + return await self.async_step_advanced_config() + + await self._set_unique_id() self._abort_if_unique_id_configured() + return self.async_create_entry( - title=f"Itho WiFi Add-on for {ADDON_TYPES[self.config[CONF_ADDON_TYPE]]}", + title=self.get_entry_title(), data=self.config, ) @@ -154,17 +194,14 @@ async def async_step_remotes(self, user_input: Mapping[str, Any] | None = None): """Configure up to 5 remotes.""" if user_input is not None: self.config.update(user_input) - await self.async_set_unique_id( - f"itho_wifi_addon_{self.config[CONF_ADDON_TYPE]}" - ) - self._abort_if_unique_id_configured() + if self.config[CONF_ADVANCED_CONFIG]: + return await self.async_step_advanced_config() - title = "Itho WiFi Add-on for " + ADDON_TYPES[self.config[CONF_ADDON_TYPE]] - if self.config[CONF_ADDON_TYPE] == "noncve": - title = title + " - " + NONCVE_DEVICES[self.config[CONF_NONCVE_MODEL]] + await self._set_unique_id() + self._abort_if_unique_id_configured() return self.async_create_entry( - title=title, + title=self.get_entry_title(), data=self.config, ) @@ -181,6 +218,40 @@ async def async_step_remotes(self, user_input: Mapping[str, Any] | None = None): step_id="remotes", data_schema=itho_schema, last_step=True ) + async def async_step_advanced_config( + self, user_input: Mapping[str, Any] | None = None + ): + """Advanced configuration for multiple devices that would use the same MQTT basetopic.""" + if user_input is not None: + self.config.update(user_input) + await self._set_unique_id() + self._abort_if_unique_id_configured() + + return self.async_create_entry( + title=self.get_entry_title(), + data=self.config, + ) + + itho_schema = vol.Schema( + { + vol.Required( + CONF_CUSTOM_BASETOPIC, + default=get_default_mqtt_base_topic(self.config), + ): str, + vol.Required( + CONF_CUSTOM_ENTITY_PREFIX, + default=get_default_entity_prefix(self.config), + ): str, + vol.Required( + CONF_CUSTOM_DEVICE_NAME, + default=get_device_model(self.config), + ): str, + } + ) + return self.async_show_form( + step_id="advanced_config", data_schema=itho_schema, last_step=True + ) + async def async_step_reconfigure(self, user_input: Mapping[str, Any] | None = None): """Reconfigure config flow.""" entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) diff --git a/custom_components/ithodaalderop/const.py b/custom_components/ithodaalderop/const.py index 35441c1..78c8e6c 100644 --- a/custom_components/ithodaalderop/const.py +++ b/custom_components/ithodaalderop/const.py @@ -31,7 +31,7 @@ "rpm": "mdi:speedometer", } -MQTT_BASETOPIC = { +MQTT_DEFAULT_BASETOPIC = { "autotemp": "ithotemp", "cve": "ithocve", "noncve": "ithohru", @@ -49,6 +49,10 @@ CONF_ADDON_TYPE = "addontype" CONF_ENTITIES_CREATION_MODE = "entities_creation_mode" +CONF_ADVANCED_CONFIG = "advanced_config" +CONF_CUSTOM_BASETOPIC = "custom_basetopic" +CONF_CUSTOM_DEVICE_NAME = "custom_device_name" +CONF_CUSTOM_ENTITY_PREFIX = "custom_entity_prefix" CONF_NONCVE_MODEL = "noncve_model" CONF_AUTOTEMP_ROOM1 = "room1" diff --git a/custom_components/ithodaalderop/definitions/base.py b/custom_components/ithodaalderop/definitions/base.py index 19faf9f..8df3089 100644 --- a/custom_components/ithodaalderop/definitions/base.py +++ b/custom_components/ithodaalderop/definitions/base.py @@ -49,6 +49,7 @@ class IthoSensorEntityDescription(SensorEntityDescription): json_field: str | None = None topic: str | None = None icon: str | None = None + room: str | None = None unique_id_template: str | None = None unique_id: str | None = None entity_category: EntityCategory | None = None diff --git a/custom_components/ithodaalderop/manifest.json b/custom_components/ithodaalderop/manifest.json index 8cd6a53..62c7cb3 100644 --- a/custom_components/ithodaalderop/manifest.json +++ b/custom_components/ithodaalderop/manifest.json @@ -14,5 +14,5 @@ "mqtt": ["ithohru/#"], "requirements": [ ], - "version": "2.4.0" + "version": "2.5.0-b1" } diff --git a/custom_components/ithodaalderop/sensors/autotemp.py b/custom_components/ithodaalderop/sensors/autotemp.py index cb54048..1cc41fd 100644 --- a/custom_components/ithodaalderop/sensors/autotemp.py +++ b/custom_components/ithodaalderop/sensors/autotemp.py @@ -13,9 +13,10 @@ AUTOTEMP_ERROR, AUTOTEMP_MODE, CONF_ADDON_TYPE, + CONF_ADVANCED_CONFIG, + CONF_CUSTOM_DEVICE_NAME, DOMAIN, MANUFACTURER, - MQTT_BASETOPIC, MQTT_STATETOPIC, ) from ..definitions.autotemp import ( @@ -28,13 +29,18 @@ AUTOTEMP_VALVE_SENSOR_TEMPLATE, ) from ..definitions.base import IthoSensorEntityDescription -from ..sensors.base import IthoBaseSensor, IthoBinarySensor +from .base import ( + IthoBaseSensor, + IthoBinarySensor, + get_entity_prefix, + get_mqtt_base_topic, +) def get_autotemp_binary_sensors(config_entry: ConfigEntry): """Create binary sensors for Autotemp.""" sensors = [] - topic = f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}" + topic = f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["autotemp"]}" for description in AUTOTEMP_BINARYSENSORS: description.topic = topic sensors.append(IthoBinarySensor(description, config_entry)) @@ -44,7 +50,7 @@ def get_autotemp_binary_sensors(config_entry: ConfigEntry): def get_autotemp_sensors(config_entry: ConfigEntry): """Create sensors for Autotemp.""" sensors = [] - topic = f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}" + topic = f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["autotemp"]}" for i in range(1, 13): letter = chr(i + 64) description = copy.deepcopy(AUTOTEMP_COMM_SPACE_SENSOR_TEMPLATE) @@ -162,16 +168,20 @@ def __init__( ) -> None: """Construct sensor for Autotemp.""" + name = f"Spider {description.room.capitalize()}" + if config_entry.data[CONF_ADVANCED_CONFIG]: + name = config_entry.data[CONF_CUSTOM_DEVICE_NAME] + " - " + name + self._attr_device_info = DeviceInfo( identifiers={ ( DOMAIN, - f"{config_entry.data[CONF_ADDON_TYPE]}_room_{description.room.lower()}", + f"itho_wifi_addon_{get_entity_prefix(config_entry.data)}_room_{description.room.lower()}", ) }, manufacturer=MANUFACTURER, model=f"{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]} Spider", - name=f"Spider {description.room.capitalize()}", + name=name, via_device=(DOMAIN, config_entry.data[CONF_ADDON_TYPE]), ) diff --git a/custom_components/ithodaalderop/sensors/base.py b/custom_components/ithodaalderop/sensors/base.py index 347a418..d3342a9 100644 --- a/custom_components/ithodaalderop/sensors/base.py +++ b/custom_components/ithodaalderop/sensors/base.py @@ -1,6 +1,7 @@ """Sensor base class.""" import json +from typing import Any from homeassistant.components import mqtt from homeassistant.components.binary_sensor import BinarySensorEntity @@ -12,9 +13,14 @@ from ..const import ( ADDON_TYPES, CONF_ADDON_TYPE, + CONF_ADVANCED_CONFIG, + CONF_CUSTOM_BASETOPIC, + CONF_CUSTOM_DEVICE_NAME, + CONF_CUSTOM_ENTITY_PREFIX, CONF_NONCVE_MODEL, DOMAIN, MANUFACTURER, + MQTT_DEFAULT_BASETOPIC, NONCVE_DEVICES, UNITTYPE_ICONS, ) @@ -24,6 +30,48 @@ ) +def get_default_mqtt_base_topic(config: dict[str, Any]) -> str: + """Get the default MQTT base topic.""" + return MQTT_DEFAULT_BASETOPIC[config[CONF_ADDON_TYPE]] + + +def get_mqtt_base_topic(config: dict[str, Any]) -> str: + """Get the MQTT base topic.""" + if config[CONF_ADVANCED_CONFIG]: + return config[CONF_CUSTOM_BASETOPIC] + + return get_default_mqtt_base_topic(config) + + +def get_device_model(config: dict[str, Any]) -> str: + """Get the device model.""" + if config[CONF_ADDON_TYPE] == "noncve": + return NONCVE_DEVICES[config[CONF_NONCVE_MODEL]] + + return ADDON_TYPES[config[CONF_ADDON_TYPE]] + + +def get_device_name(config: dict[str, Any]) -> str: + """Get the device name.""" + if config[CONF_ADVANCED_CONFIG]: + return config[CONF_CUSTOM_DEVICE_NAME] + + return get_device_model(config) + + +def get_default_entity_prefix(config: dict[str, Any]) -> str: + """Get the default entity prefix.""" + return f"itho_{ADDON_TYPES[config[CONF_ADDON_TYPE]].lower()}" + + +def get_entity_prefix(config: dict[str, Any]) -> str: + """Get the entity prefix.""" + if config[CONF_ADVANCED_CONFIG]: + return config[CONF_CUSTOM_ENTITY_PREFIX] + + return get_default_entity_prefix(config) + + class IthoBaseSensor(SensorEntity): """Base class sharing foundation for WPU, remotes and Fans.""" @@ -48,22 +96,21 @@ def __init__( self.entity_description.translation_key = self.entity_description.key if use_base_sensor_device: - if config_entry.data[CONF_ADDON_TYPE] == "noncve": - model = NONCVE_DEVICES[config_entry.data[CONF_NONCVE_MODEL]] - else: - model = ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]] - self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, config_entry.data[CONF_ADDON_TYPE])}, + identifiers={ + (DOMAIN, f"itho_wifi_addon_{get_entity_prefix(config_entry.data)}"), + }, manufacturer=MANUFACTURER, - model=model, - name=model, + model=get_device_model(config_entry.data), + name=get_device_name(config_entry.data), ) if description.unique_id is not None: - self._attr_unique_id = f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.unique_id.lower()}" + self._attr_unique_id = f"{get_entity_prefix(config_entry.data)}_{description.unique_id.lower()}" else: - self._attr_unique_id = f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.key}" + self._attr_unique_id = ( + f"{get_entity_prefix(config_entry.data)}_{description.key}" + ) self.entity_id = f"sensor.{self._attr_unique_id}" @@ -98,15 +145,21 @@ def __init__( model = f"{model} - {NONCVE_DEVICES[config_entry.data[CONF_NONCVE_MODEL]]}" self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, config_entry.data[CONF_ADDON_TYPE])}, + identifiers={ + (DOMAIN, f"itho_wifi_addon_{get_entity_prefix(config_entry.data)}"), + }, manufacturer=MANUFACTURER, - model=model, - name=f"Itho Daalderop {ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}", + model=get_device_model(config_entry.data), + name=get_device_name(config_entry.data), ) - self._attr_unique_id = ( - f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.key}" - ) + if description.unique_id is not None: + self._attr_unique_id = f"{get_entity_prefix(config_entry.data)}_{description.unique_id.lower()}" + else: + self._attr_unique_id = ( + f"{get_entity_prefix(config_entry.data)}_{description.key}" + ) + self.entity_id = f"binary_sensor.{self._attr_unique_id}" @property diff --git a/custom_components/ithodaalderop/sensors/co2_remote.py b/custom_components/ithodaalderop/sensors/co2_remote.py index ddae7c1..171d026 100644 --- a/custom_components/ithodaalderop/sensors/co2_remote.py +++ b/custom_components/ithodaalderop/sensors/co2_remote.py @@ -7,15 +7,15 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import callback -from ..const import CONF_ADDON_TYPE, MQTT_BASETOPIC, MQTT_STATETOPIC +from ..const import MQTT_STATETOPIC from ..definitions.co2_remote import REMOTE_SENSOR_TEMPLATE -from .base import IthoBaseSensor +from .base import IthoBaseSensor, get_mqtt_base_topic def get_co2_remote_sensors(config_entry: ConfigEntry): """Create remotes for CO2 monitoring.""" sensors = [] - topic = f"{MQTT_BASETOPIC[config_entry.data[CONF_ADDON_TYPE]]}/{MQTT_STATETOPIC["remote"]}" + topic = f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["remote"]}" for x in range(1, 5): remote = config_entry.data["remote" + str(x)] if remote not in ("", "Remote " + str(x)): diff --git a/custom_components/ithodaalderop/sensors/fan.py b/custom_components/ithodaalderop/sensors/fan.py index 0e95a0d..ac15e7f 100644 --- a/custom_components/ithodaalderop/sensors/fan.py +++ b/custom_components/ithodaalderop/sensors/fan.py @@ -14,7 +14,6 @@ HRU_ECO_350_GLOBAL_FAULT_CODE, HRU_ECO_350_RH_ERROR_CODE, HRU_ECO_STATUS, - MQTT_BASETOPIC, MQTT_STATETOPIC, ) from ..definitions.cve import CVE_BINARY_SENSORS, CVE_SENSORS @@ -23,14 +22,16 @@ from ..definitions.hru250_300 import HRU_ECO_250_300_SENSORS from ..definitions.hru350 import HRU_ECO_350_BINARY_SENSORS, HRU_ECO_350_SENSORS from ..definitions.hrueco import HRU_ECO_BINARY_SENSORS, HRU_ECO_SENSORS -from .base import IthoBaseSensor, IthoBinarySensor +from .base import IthoBaseSensor, IthoBinarySensor, get_mqtt_base_topic def get_cve_binary_sensors(config_entry: ConfigEntry): """Create binary sensors for CVE.""" sensors = [] for description in CVE_BINARY_SENSORS: - description.topic = f"{MQTT_BASETOPIC["cve"]}/{MQTT_STATETOPIC["cve"]}" + description.topic = ( + f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["cve"]}" + ) sensors.append(IthoBinarySensor(description, config_entry)) return sensors @@ -39,10 +40,11 @@ def get_cve_binary_sensors(config_entry: ConfigEntry): def get_cve_sensors(config_entry: ConfigEntry): """Create sensors for CVE.""" sensors = [] - topic = f"{MQTT_BASETOPIC["cve"]}/{MQTT_STATETOPIC["cve"]}" for description in CVE_SENSORS: - description.topic = topic + description.topic = ( + f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["cve"]}" + ) sensors.append(IthoSensorFan(description, config_entry)) return sensors @@ -52,7 +54,6 @@ def get_noncve_binary_sensors(config_entry: ConfigEntry): """Create binary sensors for NON-CVE.""" sensors = [] - topic = f"{MQTT_BASETOPIC["noncve"]}/{MQTT_STATETOPIC["noncve"]}" if config_entry.data[CONF_NONCVE_MODEL] in ["hru_eco", "hru_eco_350"]: if config_entry.data[CONF_NONCVE_MODEL] == "hru_eco": hru_sensors = HRU_ECO_BINARY_SENSORS @@ -62,7 +63,9 @@ def get_noncve_binary_sensors(config_entry: ConfigEntry): hru_sensors = DEMAND_FLOW_BINARY_SENSORS for description in hru_sensors: - description.topic = topic + description.topic = ( + f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["noncve"]}" + ) sensors.append(IthoBinarySensor(description, config_entry)) return sensors @@ -71,7 +74,6 @@ def get_noncve_binary_sensors(config_entry: ConfigEntry): def get_noncve_sensors(config_entry: ConfigEntry): """Create sensors for NON-CVE.""" sensors = [] - topic = f"{MQTT_BASETOPIC["noncve"]}/{MQTT_STATETOPIC["noncve"]}" if config_entry.data[CONF_NONCVE_MODEL] == "hru_eco": hru_sensors = HRU_ECO_SENSORS @@ -85,7 +87,9 @@ def get_noncve_sensors(config_entry: ConfigEntry): hru_sensors = DEMAND_FLOW_SENSORS for description in hru_sensors: - description.topic = topic + description.topic = ( + f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["noncve"]}" + ) sensors.append(IthoSensorFan(description, config_entry)) return sensors diff --git a/custom_components/ithodaalderop/sensors/last_command.py b/custom_components/ithodaalderop/sensors/last_command.py index e8d4a13..7dfb95f 100644 --- a/custom_components/ithodaalderop/sensors/last_command.py +++ b/custom_components/ithodaalderop/sensors/last_command.py @@ -6,15 +6,15 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import callback -from ..const import CONF_ADDON_TYPE, MQTT_BASETOPIC, MQTT_STATETOPIC +from ..const import MQTT_STATETOPIC from ..definitions.last_command import LAST_CMD_SENSORS -from .base import IthoBaseSensor +from .base import IthoBaseSensor, get_mqtt_base_topic def get_last_command_sensors(config_entry: ConfigEntry): """Create sensors for Last Command.""" sensors = [] - topic = f"{MQTT_BASETOPIC[config_entry.data[CONF_ADDON_TYPE]]}/{MQTT_STATETOPIC["last_cmd"]}" + topic = f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["last_cmd"]}" for description in LAST_CMD_SENSORS: description.topic = topic sensors.append(IthoSensorLastCommand(description, config_entry)) diff --git a/custom_components/ithodaalderop/sensors/wpu.py b/custom_components/ithodaalderop/sensors/wpu.py index ef0dd4d..1da6224 100644 --- a/custom_components/ithodaalderop/sensors/wpu.py +++ b/custom_components/ithodaalderop/sensors/wpu.py @@ -7,20 +7,20 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import callback -from ..const import MQTT_BASETOPIC, MQTT_STATETOPIC, WPU_STATUS +from ..const import MQTT_STATETOPIC, WPU_STATUS from ..definitions.wpu import ( WPU_BINARY_SENSORS, WPU_ERROR_CODE_BYTE_TEMPLATE, WPU_SENSORS, WPU_THERMOSTAT, ) -from .base import IthoBaseSensor, IthoBinarySensor +from .base import IthoBaseSensor, IthoBinarySensor, get_mqtt_base_topic def get_wpu_binary_sensors(config_entry: ConfigEntry): """Create binary sensors for WPU.""" sensors = [] - topic = f"{MQTT_BASETOPIC["wpu"]}/{MQTT_STATETOPIC["wpu"]}" + topic = f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["wpu"]}" for description in WPU_BINARY_SENSORS: description.topic = topic sensors.append(IthoBinarySensor(description, config_entry)) @@ -31,7 +31,7 @@ def get_wpu_binary_sensors(config_entry: ConfigEntry): def get_wpu_sensors(config_entry: ConfigEntry): """Create sensors for WPU.""" sensors = [] - topic = f"{MQTT_BASETOPIC["wpu"]}/{MQTT_STATETOPIC["wpu"]}" + topic = f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["wpu"]}" for x in range(6): x = str(x) description = copy.deepcopy(WPU_ERROR_CODE_BYTE_TEMPLATE) @@ -50,7 +50,7 @@ def get_wpu_sensors(config_entry: ConfigEntry): def get_wpu_thermostat(config_entry: ConfigEntry): """Create virtual thermostat for WPU.""" - topic = f"{MQTT_BASETOPIC["wpu"]}/{MQTT_STATETOPIC["wpu"]}" + topic = f"{get_mqtt_base_topic(config_entry.data)}/{MQTT_STATETOPIC["wpu"]}" description = WPU_THERMOSTAT description.topic = topic diff --git a/custom_components/ithodaalderop/translations/en.json b/custom_components/ithodaalderop/translations/en.json index e8dcf3d..822b507 100644 --- a/custom_components/ithodaalderop/translations/en.json +++ b/custom_components/ithodaalderop/translations/en.json @@ -5,6 +5,15 @@ "reconfigure_successful": "Re-configuration was successful" }, "step": { + "advanced_config": { + "data": { + "custom_basetopic": "Custom MQTT base topic", + "custom_entity_prefix": "Custom entity prefix", + "custom_device_name": "Custom device name" + }, + "description": "Customize the MQTT base topic, entity prefix and device name.", + "title": "Advanced integration entry configuration" + }, "noncve_model": { "data": { "noncve_model": "Model:" @@ -72,7 +81,8 @@ "user": { "data": { "addontype": "Select the type of add-on to configure:", - "entities_creation_mode": "Select mode for entity creation (this can later be re-configured):" + "entities_creation_mode": "Select mode for entity creation (this can later be re-configured):", + "advanced_config": "Advanced configuration\n:" }, "description": "Select the Itho WiFi Add-on you want to configure. Repeat the configuration for every physical add-on present. This integration creates either all or only commonly used sensors for each device.", "title": "Add new Itho devices" diff --git a/custom_components/ithodaalderop/translations/nl.json b/custom_components/ithodaalderop/translations/nl.json index 58df103..ff4a5fd 100644 --- a/custom_components/ithodaalderop/translations/nl.json +++ b/custom_components/ithodaalderop/translations/nl.json @@ -5,6 +5,15 @@ "reconfigure_successful": "Herconfiguratie was succesvol" }, "step": { + "advanced_config": { + "data": { + "custom_basetopic": "MQTT-basisonderwerp", + "custom_entity_prefix": "Entiteiten-voorvoegsel", + "custom_device_name": "Apparaatnaam" + }, + "description": "Pas het MQTT-basisonderwerp, entiteitsvoorvoegsel en apparaatnaam aan.", + "title": "Geavanceerde integratie configuratie" + }, "noncve_model": { "data": { "noncve_model": "Model:" @@ -72,7 +81,8 @@ "user": { "data": { "addontype": "Add-on type:", - "entities_creation_mode": "Kies de sensoren die aangemaakt worden (dit kan later aangepast worden):" + "entities_creation_mode": "Kies de sensoren die aangemaakt worden (dit kan later aangepast worden):", + "advanced_config": "Geavanceerde integratie configuratie:" }, "description": "Configuratie stappen voor Itho. Herhaal deze configuratie voor iedere fysieke add-on die gebruikt wordt. Deze integratie maakt automatisch alle of de meest gebruikelijke sensors aan.", "title": "Voeg nieuwe Itho apparaten toe"