diff --git a/custom_components/bluetti_bt/__init__.py b/custom_components/bluetti_bt/__init__.py index 68e4d30..9ef157b 100644 --- a/custom_components/bluetti_bt/__init__.py +++ b/custom_components/bluetti_bt/__init__.py @@ -12,8 +12,6 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.exceptions import ConfigEntryNotReady -from bluetti_mqtt.bluetooth import build_device as orig_build_device - from .const import ( CONF_MAX_RETRIES, CONF_PERSISTENT_CONN, @@ -22,13 +20,10 @@ from .const import ( CONF_USE_CONTROLS, DATA_COORDINATOR, DATA_POLLING_RUNNING, - DEVICE_NAME_RE, DOMAIN, MANUFACTURER, ) from .coordinator import PollingCoordinator -from .devices.ep600 import EP600 -from .devices.ep760 import EP760 PLATFORMS: [Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR] _LOGGER = logging.getLogger(__name__) @@ -110,12 +105,3 @@ def get_type_by_bt_name(bt_name: str): elif bt_name.startswith("EP760"): dev_type = "EP760" return dev_type - -def build_device(address: str, name: str): - match = DEVICE_NAME_RE.match(name) - if match[1] == 'EP760': - return EP760(address, match[2]) - elif match[1] == 'EP600': - return EP600(address, match[2]) - else: - return orig_build_device(address, name) diff --git a/custom_components/bluetti_bt/binary_sensor.py b/custom_components/bluetti_bt/binary_sensor.py index fa02c25..a0716f2 100644 --- a/custom_components/bluetti_bt/binary_sensor.py +++ b/custom_components/bluetti_bt/binary_sensor.py @@ -24,10 +24,10 @@ from bluetti_mqtt.mqtt_client import ( MqttFieldType, ) -from . import device_info as dev_info, get_unique_id, build_device +from . import device_info as dev_info, get_unique_id from .const import DATA_COORDINATOR, DOMAIN, ADDITIONAL_DEVICE_FIELDS from .coordinator import PollingCoordinator -from .utils import unique_id_loggable +from .utils import unique_id_loggable, build_device _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/bluetti_bt/coordinator.py b/custom_components/bluetti_bt/coordinator.py index 304e1e7..0b91ff3 100644 --- a/custom_components/bluetti_bt/coordinator.py +++ b/custom_components/bluetti_bt/coordinator.py @@ -25,9 +25,8 @@ from bluetti_mqtt.bluetooth import ( from bluetti_mqtt.core.devices.bluetti_device import BluettiDevice from bluetti_mqtt.core.commands import ReadHoldingRegisters -from . import build_device from .const import DATA_POLLING_RUNNING, DOMAIN -from .utils import mac_loggable +from .utils import mac_loggable, build_device _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/bluetti_bt/manifest.json b/custom_components/bluetti_bt/manifest.json index 4ad5e68..4c32ba3 100644 --- a/custom_components/bluetti_bt/manifest.json +++ b/custom_components/bluetti_bt/manifest.json @@ -19,5 +19,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/Patrick762/hassio-bluetti-bt/issues", "requirements": ["bluetti_mqtt==0.15.0"], - "version": "0.0.13" + "version": "0.0.14" } diff --git a/custom_components/bluetti_bt/sensor.py b/custom_components/bluetti_bt/sensor.py index fb2a17a..91e69c7 100644 --- a/custom_components/bluetti_bt/sensor.py +++ b/custom_components/bluetti_bt/sensor.py @@ -29,10 +29,10 @@ from bluetti_mqtt.mqtt_client import ( battery_pack_fields, ) -from . import device_info as dev_info, get_unique_id, build_device +from . import device_info as dev_info, get_unique_id from .const import DATA_COORDINATOR, DOMAIN, CONF_OPTIONS, DIAGNOSTIC_FIELDS, ADDITIONAL_DEVICE_FIELDS from .coordinator import PollingCoordinator -from .utils import unique_id_loggable +from .utils import unique_id_loggable, build_device _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/bluetti_bt/switch.py b/custom_components/bluetti_bt/switch.py index b3a8e48..cca5a60 100644 --- a/custom_components/bluetti_bt/switch.py +++ b/custom_components/bluetti_bt/switch.py @@ -31,10 +31,10 @@ from bluetti_mqtt.mqtt_client import ( MqttFieldType, ) -from . import device_info as dev_info, get_unique_id, build_device +from . import device_info as dev_info, get_unique_id from .const import CONTROL_FIELDS, DATA_COORDINATOR, DOMAIN, ADDITIONAL_DEVICE_FIELDS from .coordinator import PollingCoordinator -from .utils import mac_loggable, unique_id_loggable +from .utils import mac_loggable, unique_id_loggable, build_device _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/bluetti_bt/utils.py b/custom_components/bluetti_bt/utils.py index fce973c..a42f928 100644 --- a/custom_components/bluetti_bt/utils.py +++ b/custom_components/bluetti_bt/utils.py @@ -1,5 +1,11 @@ """Tools.""" +from bluetti_mqtt.bluetooth import build_device as orig_build_device + +from .const import DEVICE_NAME_RE +from .devices.ep600 import EP600 +from .devices.ep760 import EP760 + def mac_loggable(mac: str) -> str: """Remove parts of the mac address for logging.""" splitted = mac.split(":") @@ -10,3 +16,12 @@ def unique_id_loggable(unique_id: str) -> str: splitted = unique_id.split("_", maxsplit=1) serial = splitted[0][:6] return serial + "XXXXXXXXXX" + splitted[1] + +def build_device(address: str, name: str): + match = DEVICE_NAME_RE.match(name) + if match[1] == 'EP760': + return EP760(address, match[2]) + elif match[1] == 'EP600': + return EP600(address, match[2]) + else: + return orig_build_device(address, name)