From a081f1236a64a280c553b57f27ebe6bb0e83d466 Mon Sep 17 00:00:00 2001 From: Josef Zweck <24647999+zweckj@users.noreply.github.com> Date: Mon, 11 Nov 2024 08:55:32 +0100 Subject: [PATCH] add method to derive model name --- aioacaia/acaiascale.py | 5 ++++- aioacaia/helpers.py | 19 +++++++++++++++++++ setup.py | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/aioacaia/acaiascale.py b/aioacaia/acaiascale.py index edb7b19..994b52b 100644 --- a/aioacaia/acaiascale.py +++ b/aioacaia/acaiascale.py @@ -22,7 +22,7 @@ from .exceptions import AcaiaDeviceNotFound, AcaiaError from .const import UnitMass from .decode import Message, Settings, decode -from .helpers import encode, encode_id, encode_notification_request +from .helpers import encode, encode_id, encode_notification_request, derive_model_name _LOGGER = logging.getLogger(__name__) @@ -54,6 +54,7 @@ class AcaiaScale: def __init__( self, address_or_ble_device: str | BLEDevice, + name: str | None = None, is_new_style_scale: bool = True, notify_callback: Callable[[], None] | None = None, ) -> None: @@ -63,6 +64,8 @@ def __init__( self._client: BleakClient | None = None self.address_or_ble_device = address_or_ble_device + self.model = derive_model_name(name) + self.name = name # tasks self.heartbeat_task: asyncio.Task | None = None diff --git a/aioacaia/helpers.py b/aioacaia/helpers.py index 7f5c31e..9a659c1 100644 --- a/aioacaia/helpers.py +++ b/aioacaia/helpers.py @@ -150,3 +150,22 @@ def encode_notification_request() -> bytearray: byte_msg[i + 1] = p_byte & 0xFF return encode(12, byte_msg) + + +def derive_model_name(name: str | None) -> str | None: + """Try Derive the model name from the title.""" + if name is None: + return None + + if name == "PROCHBT001": + return "Pearl" + + if "-" not in name: + return None + + prefix = name.split("-")[0] + if prefix in ("PEARL", "LUNAR", "PYXIS"): + return prefix.capitalize() + if prefix == "ACAIAL": + return "Lunar" + return None diff --git a/setup.py b/setup.py index 3c5f7e0..5b794f1 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="aioacaia", - version="0.1.2", + version="0.1.3", description="An async implementation of PyAcaia", long_description=readme, long_description_content_type="text/markdown",