diff --git a/CHANGELOG.md b/CHANGELOG.md index 125d8f2..3a15ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,14 @@ ### Added -* (Hopefully) detect model from advertiser data -* Colour and model numbers +* Detect model from advertiser data (Hopefully correctly) +* Colour, capacity and model numbers * Handle Tumbler ### Changed * Bumped minimum version of bleak to 0.21.0 +* Discover method changed to use advertisement information * `model` renamed to `model_info` * `include_extra` option removed. `debug` has a similar function now. diff --git a/ember_mug/cli/commands.py b/ember_mug/cli/commands.py index 0088847..641ac7f 100644 --- a/ember_mug/cli/commands.py +++ b/ember_mug/cli/commands.py @@ -74,9 +74,10 @@ async def discover(args: Namespace) -> list[tuple[BLEDevice, AdvertisementData]] print(mug.address) else: model_info = get_model_info_from_advertiser_data(advertisement) + model_number = model_info.model.value if model_info.model else "Unknown Model" print("Found mug:", mug) print("Name:", advertisement.local_name) - print("Model:", model_info.model.value if model_info.model else "Unknown") + print("Model:", f"{model_info.name} [{model_number}]") print("Colour:", model_info.colour.value if model_info.colour else "Unknown") print("Capacity:", format_capacity(model_info.capacity)) return mugs diff --git a/ember_mug/consts.py b/ember_mug/consts.py index 1ca1731..f39064e 100644 --- a/ember_mug/consts.py +++ b/ember_mug/consts.py @@ -31,11 +31,22 @@ class DeviceModel(str, Enum): CUP_6_OZ = "CM21S" MUG_1_10_OZ = "CM17" MUG_1_14_OZ = "CM17P" - MUG_2_10_OZ = "CM19" # or CM21M? - MUG_2_14_OZ = "CM19P" # or CM21L? + MUG_2_10_OZ = "CM19/CM21M" + MUG_2_14_OZ = "CM19P/CM21L" TRAVEL_MUG_12_OZ = "TM19" TUMBLER_16_OZ = "CM21XL" - UNKNOWN_DEVICE = "Unknown Mug or Tumbler" + UNKNOWN_DEVICE = "Unknown" + + +DEVICE_MODEL_NAMES: dict[DeviceModel, str] = { + DeviceModel.CUP_6_OZ: "Ember Cup", + DeviceModel.MUG_1_10_OZ: "Ember Mug (10oz)", + DeviceModel.MUG_1_14_OZ: "Ember Mug (14oz)", + DeviceModel.MUG_2_10_OZ: "Ember Mug 2 (10oz)", + DeviceModel.MUG_2_14_OZ: "Ember Mug 2 (14oz)", + DeviceModel.TRAVEL_MUG_12_OZ: "Ember Travel Mug", + DeviceModel.TUMBLER_16_OZ: "Ember Tumbler", +} class DeviceColour(str, Enum): diff --git a/ember_mug/data.py b/ember_mug/data.py index c042c5f..79bb94f 100644 --- a/ember_mug/data.py +++ b/ember_mug/data.py @@ -7,6 +7,7 @@ from .consts import ( ATTR_LABELS, + DEVICE_MODEL_NAMES, EXTRA_ATTRS, INITIAL_ATTRS, UPDATE_ATTRS, @@ -111,6 +112,7 @@ class BaseModelInfo: model: DeviceModel | None = None colour: DeviceColour | None = None + name: str = field(init=False) capacity: int | None = field(init=False) device_type: DeviceType = field(init=False) @@ -119,6 +121,14 @@ class BaseModelInfo: class ModelInfo(BaseModelInfo): """Model name and attributes based on mode.""" + @cached_property # type: ignore[misc] + def name(self) -> str: # type: ignore[override] + """Get a human-readable name from model number.""" + return DEVICE_MODEL_NAMES.get( + self.model or DeviceModel.UNKNOWN_DEVICE, + "Unknown Device", + ) + @cached_property # type: ignore[misc] def capacity(self) -> int | None: # type: ignore[override] """Determine capacity in mL based on model number.""" diff --git a/tests/cli/test_commands.py b/tests/cli/test_commands.py index dd7ed40..4f51432 100644 --- a/tests/cli/test_commands.py +++ b/tests/cli/test_commands.py @@ -117,7 +117,11 @@ async def test_discover(mock_discover_mugs: AsyncMock, capsys: CaptureFixture, b mock_discover_mugs.assert_called_once_with(mac=TEST_MAC) captured = capsys.readouterr() assert captured.out == ( - f"Found mug: {ble_device}\n" "Name: Ember Ceramic Mug\n" "Model: CM19\n" "Colour: Black\n" "Capacity: 295ml\n" + f"Found mug: {ble_device}\n" + "Name: Ember Ceramic Mug\n" + "Model: Ember Mug 2 (10oz) [CM19/CM21M]\n" + "Colour: Black\n" + "Capacity: 295ml\n" ) mock_discover_mugs.reset_mock() diff --git a/tests/test_mug_data.py b/tests/test_mug_data.py index 98bc96e..e8b29e7 100644 --- a/tests/test_mug_data.py +++ b/tests/test_mug_data.py @@ -84,10 +84,11 @@ def test_mug_dict(mug_data: MugData) -> None: mug_data.update_info(meta=MugMeta("test_id", "serial number")) assert mug_data.as_dict() == { "model_info": { - 'capacity': None, - 'colour': None, - 'device_type': DeviceType.MUG, - 'model': None, + "capacity": None, + "colour": None, + "device_type": DeviceType.MUG, + "model": None, + "name": "Unknown Device", }, "use_metric": True, "debug": False,