Skip to content

Commit

Permalink
add method to derive model name
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Nov 11, 2024
1 parent 8a81428 commit a081f12
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion aioacaia/acaiascale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions aioacaia/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a081f12

Please sign in to comment.