From 3e4b8601e88a88f590029322923ad548918328c1 Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Sat, 10 Feb 2024 13:19:16 +0100 Subject: [PATCH] added dropdown to select device model --- custom_components/bluetti_bt/config_flow.py | 17 +++++++++++++++-- custom_components/bluetti_bt/const.py | 11 +++++++++++ custom_components/bluetti_bt/manifest.json | 5 +++-- .../bluetti_bt/translations/de.json | 10 ++++++++++ .../bluetti_bt/translations/en.json | 10 ++++++++++ 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/custom_components/bluetti_bt/config_flow.py b/custom_components/bluetti_bt/config_flow.py index 61d78c9..cc300e4 100644 --- a/custom_components/bluetti_bt/config_flow.py +++ b/custom_components/bluetti_bt/config_flow.py @@ -24,6 +24,7 @@ from .const import ( CONF_POLLING_TIMEOUT, CONF_USE_CONTROLS, DOMAIN, + SUPPORTED_MODELS, ) _LOGGER = logging.getLogger(__name__) @@ -58,12 +59,18 @@ class BluettiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): await self.async_set_unique_id(address, raise_on_progress=False) self._abort_if_unique_id_configured() dev_type = get_type_by_bt_name(discovery_info.name) + name = re.sub("[^A-Z0-9]+", "", discovery_info.name) + + if dev_type == "Unknown": + dev_type = user_input[CONF_TYPE] + name = re.sub("[^A-Z0-9]+", "", discovery_info.name).replace("PBOX", dev_type) + return self.async_create_entry( - title=discovery_info.name, + title=name, data={ CONF_ADDRESS: discovery_info.address, CONF_TYPE: dev_type, - CONF_NAME: re.sub("[^A-Z0-9]+", "", discovery_info.name), + CONF_NAME: name, }, ) @@ -88,6 +95,12 @@ class BluettiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): for service_info in self._discovered_devices.values() } ), + vol.Optional(CONF_TYPE): vol.In( + { + model: model + for model in SUPPORTED_MODELS + } + ), } ) return self.async_show_form( diff --git a/custom_components/bluetti_bt/const.py b/custom_components/bluetti_bt/const.py index 545e80f..7015358 100644 --- a/custom_components/bluetti_bt/const.py +++ b/custom_components/bluetti_bt/const.py @@ -17,6 +17,17 @@ CONF_MAX_RETRIES = "max_retries" DATA_COORDINATOR = "coordinator" DATA_POLLING_RUNNING = "polling_running" +SUPPORTED_MODELS = [ + "AC60", + "AC200M", + "AC300", + "AC500", + "EB3A", + "EP500", + "EP500P", + "EP600", + "EP760", +] DEVICE_NAME_RE = re.compile(r'^(AC200M|AC300|AC500|AC60|EP500P|EP500|EP600|EP760|EB3A)(\d+)$') CONTROL_FIELDS = [ diff --git a/custom_components/bluetti_bt/manifest.json b/custom_components/bluetti_bt/manifest.json index 4c32ba3..56fe455 100644 --- a/custom_components/bluetti_bt/manifest.json +++ b/custom_components/bluetti_bt/manifest.json @@ -9,7 +9,8 @@ { "local_name": "EB3A*" }, { "local_name": "EP500*" }, { "local_name": "EP600*" }, - { "local_name": "EP760*" } + { "local_name": "EP760*" }, + { "local_name": "PBOX*" } ], "codeowners": ["@Patrick762"], "config_flow": true, @@ -19,5 +20,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/Patrick762/hassio-bluetti-bt/issues", "requirements": ["bluetti_mqtt==0.15.0"], - "version": "0.0.14" + "version": "0.0.15" } diff --git a/custom_components/bluetti_bt/translations/de.json b/custom_components/bluetti_bt/translations/de.json index 7093834..9451cab 100644 --- a/custom_components/bluetti_bt/translations/de.json +++ b/custom_components/bluetti_bt/translations/de.json @@ -1,4 +1,14 @@ { + "config": { + "step": { + "user": { + "data": { + "address": "Gerät", + "type": "Modell (erforderlich bei PBOX Geräten)" + } + } + } + }, "options": { "step": { "init": { diff --git a/custom_components/bluetti_bt/translations/en.json b/custom_components/bluetti_bt/translations/en.json index 1229863..c5b4610 100644 --- a/custom_components/bluetti_bt/translations/en.json +++ b/custom_components/bluetti_bt/translations/en.json @@ -1,4 +1,14 @@ { + "config": { + "step": { + "user": { + "data": { + "address": "Device", + "type": "Model (required for PBOX devices)" + } + } + } + }, "options": { "step": { "init": {