diff --git a/custom_components/bluetti_bt/__init__.py b/custom_components/bluetti_bt/__init__.py index 46be53c..ea7e4aa 100644 --- a/custom_components/bluetti_bt/__init__.py +++ b/custom_components/bluetti_bt/__init__.py @@ -84,25 +84,3 @@ def get_unique_id(name: str, sensor_type: str | None = None): if sensor_type is not None: return f"{sensor_type}.{res}" return res - - -def get_type_by_bt_name(bt_name: str): - """Get the device type.""" - dev_type = "Unknown" - if bt_name.startswith("AC200M"): - dev_type = "AC200M" - elif bt_name.startswith("AC300"): - dev_type = "AC300" - elif bt_name.startswith("AC500"): - dev_type = "AC500" - elif bt_name.startswith("AC60"): - dev_type = "AC60" - elif bt_name.startswith("EB3A"): - dev_type = "EB3A" - elif bt_name.startswith("EP500"): - dev_type = "EP500" - elif bt_name.startswith("EP600"): - dev_type = "EP600" - elif bt_name.startswith("EP760"): - dev_type = "EP760" - return dev_type diff --git a/custom_components/bluetti_bt/bluetti_bt_lib/field_attributes.py b/custom_components/bluetti_bt/bluetti_bt_lib/field_attributes.py index 1cb046e..5cec159 100644 --- a/custom_components/bluetti_bt/bluetti_bt_lib/field_attributes.py +++ b/custom_components/bluetti_bt/bluetti_bt_lib/field_attributes.py @@ -1,6 +1,5 @@ """Field attributes for device fields.""" -from dataclasses import dataclass from enum import Enum, auto, unique from .field_enums import ( diff --git a/custom_components/bluetti_bt/bluetti_bt_lib/utils/device_builder.py b/custom_components/bluetti_bt/bluetti_bt_lib/utils/device_builder.py index 3fb036e..177610d 100644 --- a/custom_components/bluetti_bt/bluetti_bt_lib/utils/device_builder.py +++ b/custom_components/bluetti_bt/bluetti_bt_lib/utils/device_builder.py @@ -37,3 +37,10 @@ def build_device(address: str, name: str): return EP600(address, match[2]) if match[1] == "EP760": return EP760(address, match[2]) + + +def get_type_by_bt_name(bt_name: str): + match = DEVICE_NAME_RE.match(bt_name) + if len(match) > 0: + return match[1] + return "Unknown" diff --git a/custom_components/bluetti_bt/config_flow.py b/custom_components/bluetti_bt/config_flow.py index 9ebd5b8..6b2899e 100644 --- a/custom_components/bluetti_bt/config_flow.py +++ b/custom_components/bluetti_bt/config_flow.py @@ -4,6 +4,7 @@ from __future__ import annotations import re import logging +from typing import Any import voluptuous as vol @@ -16,7 +17,8 @@ from homeassistant.const import CONF_ADDRESS, CONF_TYPE, CONF_NAME from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import selector -from . import get_type_by_bt_name +from .bluetti_bt_lib.utils.device_builder import get_type_by_bt_name + from .const import ( CONF_MAX_RETRIES, CONF_PERSISTENT_CONN,