move get_type_by_bt_name into lib

This commit is contained in:
Patrick762 committed 2024-02-18 14:35:16 +01:00
1 parent caac9330b4
commit 564a971d7c
4 files changed
+10 -24

No files matched your search

-22
View File
@@ -84,25 +84,3 @@ def get_unique_id(name: str, sensor_type: str | None = None):
if sensor_type is not None: if sensor_type is not None:
return f"{sensor_type}.{res}" return f"{sensor_type}.{res}"
return 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
@@ -1,6 +1,5 @@
"""Field attributes for device fields.""" """Field attributes for device fields."""
from dataclasses import dataclass
from enum import Enum, auto, unique from enum import Enum, auto, unique
from .field_enums import ( from .field_enums import (
@@ -37,3 +37,10 @@ def build_device(address: str, name: str):
return EP600(address, match[2]) return EP600(address, match[2])
if match[1] == "EP760": if match[1] == "EP760":
return EP760(address, match[2]) 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"
+3 -1
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import re import re
import logging import logging
from typing import Any
import voluptuous as vol 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.data_entry_flow import FlowResult
from homeassistant.helpers import selector 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 ( from .const import (
CONF_MAX_RETRIES, CONF_MAX_RETRIES,
CONF_PERSISTENT_CONN, CONF_PERSISTENT_CONN,