Skip to content

Commit

Permalink
feat: Add more readable value for model names than the number
Browse files Browse the repository at this point in the history
  • Loading branch information
sopelj committed Dec 26, 2023
1 parent 70e6618 commit b9ea381
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion ember_mug/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions ember_mug/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions ember_mug/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .consts import (
ATTR_LABELS,
DEVICE_MODEL_NAMES,
EXTRA_ATTRS,
INITIAL_ATTRS,
UPDATE_ATTRS,
Expand Down Expand Up @@ -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)

Expand All @@ -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."""
Expand Down
6 changes: 5 additions & 1 deletion tests/cli/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions tests/test_mug_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b9ea381

Please sign in to comment.