python-ember-mug 1.3.0b3__tar.gz → 1.3.0b5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/PKG-INFO +4 -5
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/README.md +1 -3
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/__init__.py +1 -1
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/cli/commands.py +2 -2
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/cli/helpers.py +4 -4
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/consts.py +0 -1
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/data.py +14 -4
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/formatting.py +5 -4
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/mug.py +31 -17
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/pyproject.toml +5 -3
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/.gitignore +0 -0
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/LICENSE +0 -0
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/__main__.py +0 -0
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/cli/__init__.py +0 -0
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/scanner.py +0 -0
- {python_ember_mug-1.3.0b3 → python_ember_mug-1.3.0b5}/ember_mug/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-ember-mug
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.0b5
|
|
4
4
|
Summary: Python Library for Ember Mugs.
|
|
5
5
|
Project-URL: Changelog, https://sopelj.github.io/python-ember-mug/changelog/
|
|
6
6
|
Project-URL: Documentation, https://sopelj.github.io/python-ember-mug/
|
|
@@ -16,9 +16,10 @@ Classifier: Programming Language :: Python :: 3
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
20
|
Requires-Python: >=3.11
|
|
20
21
|
Requires-Dist: bleak-retry-connector>=4.0.2
|
|
21
|
-
Requires-Dist: bleak
|
|
22
|
+
Requires-Dist: bleak<2.2.0,>=1.0.1
|
|
22
23
|
Provides-Extra: dev
|
|
23
24
|
Requires-Dist: ipython; extra == 'dev'
|
|
24
25
|
Provides-Extra: docs
|
|
@@ -44,7 +45,7 @@ Description-Content-Type: text/markdown
|
|
|
44
45
|
[](https://pypi.org/project/python-ember-mug/)
|
|
45
46
|
[](https://github.com/sopelj/python-ember-mug/actions/workflows/tests.yml)
|
|
46
47
|
[](https://codecov.io/gh/sopelj/python-ember-mug)
|
|
47
|
-

|
|
48
49
|
[](https://github.com/sopelj)
|
|
49
50
|
[](https://github.com/sopelj/python-ember-mug/blob/main/LICENSE)
|
|
50
51
|
[](https://github.com/pre-commit/pre-commit)
|
|
@@ -177,8 +178,6 @@ Device Data
|
|
|
177
178
|
+--------------+----------------------+
|
|
178
179
|
| Target Temp | 55.00°C |
|
|
179
180
|
+--------------+----------------------+
|
|
180
|
-
| Use Metric | True |
|
|
181
|
-
+--------------+----------------------+
|
|
182
181
|
|
|
183
182
|
Watching for changes
|
|
184
183
|
Current Temp changed from "24.50°C" to "25.50°"
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://pypi.org/project/python-ember-mug/)
|
|
5
5
|
[](https://github.com/sopelj/python-ember-mug/actions/workflows/tests.yml)
|
|
6
6
|
[](https://codecov.io/gh/sopelj/python-ember-mug)
|
|
7
|
-

|
|
8
8
|
[](https://github.com/sopelj)
|
|
9
9
|
[](https://github.com/sopelj/python-ember-mug/blob/main/LICENSE)
|
|
10
10
|
[](https://github.com/pre-commit/pre-commit)
|
|
@@ -137,8 +137,6 @@ Device Data
|
|
|
137
137
|
+--------------+----------------------+
|
|
138
138
|
| Target Temp | 55.00°C |
|
|
139
139
|
+--------------+----------------------+
|
|
140
|
-
| Use Metric | True |
|
|
141
|
-
+--------------+----------------------+
|
|
142
140
|
|
|
143
141
|
Watching for changes
|
|
144
142
|
Current Temp changed from "24.50°C" to "25.50°"
|
|
@@ -112,9 +112,9 @@ async def poll_device_cmd(args: Namespace) -> None:
|
|
|
112
112
|
for _ in CommandLoop():
|
|
113
113
|
for _ in range(60):
|
|
114
114
|
await asyncio.sleep(1)
|
|
115
|
-
print_changes(await mug.update_queued_attributes(), mug.data.
|
|
115
|
+
print_changes(await mug.update_queued_attributes(), mug.data.user_unit)
|
|
116
116
|
# Every minute do a full update
|
|
117
|
-
print_changes(await mug.update_all(), mug.data.
|
|
117
|
+
print_changes(await mug.update_all(), mug.data.user_unit)
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
async def get_device_value_cmd(args: Namespace) -> None:
|
|
@@ -8,7 +8,7 @@ from collections import defaultdict
|
|
|
8
8
|
from functools import partial
|
|
9
9
|
from typing import TYPE_CHECKING
|
|
10
10
|
|
|
11
|
-
from ember_mug.consts import MAC_ADDRESS_REGEX
|
|
11
|
+
from ember_mug.consts import MAC_ADDRESS_REGEX, TemperatureUnit
|
|
12
12
|
from ember_mug.data import Change
|
|
13
13
|
from ember_mug.formatting import format_led_colour, format_liquid_level, format_temp
|
|
14
14
|
|
|
@@ -62,11 +62,11 @@ def print_info(mug: EmberMug) -> None:
|
|
|
62
62
|
print_table(list(mug.data.formatted.items()))
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
def print_changes(changes: list[Change],
|
|
65
|
+
def print_changes(changes: list[Change], unit: TemperatureUnit | None) -> None:
|
|
66
66
|
"""Print changes."""
|
|
67
67
|
formatters: dict[str, Callable] = {
|
|
68
|
-
"current_temp": partial(format_temp,
|
|
69
|
-
"target_temp": partial(format_temp,
|
|
68
|
+
"current_temp": partial(format_temp, unit=unit),
|
|
69
|
+
"target_temp": partial(format_temp, unit=unit),
|
|
70
70
|
**base_formatters,
|
|
71
71
|
}
|
|
72
72
|
for attr, old_value, new_value in changes:
|
|
@@ -211,7 +211,7 @@ class MugData(AsDict):
|
|
|
211
211
|
|
|
212
212
|
# Options
|
|
213
213
|
model_info: ModelInfo
|
|
214
|
-
use_metric: bool =
|
|
214
|
+
use_metric: bool | None = None
|
|
215
215
|
debug: bool = False
|
|
216
216
|
|
|
217
217
|
# Attributes
|
|
@@ -231,6 +231,15 @@ class MugData(AsDict):
|
|
|
231
231
|
date_time_zone: datetime | None = None
|
|
232
232
|
battery_voltage: int | None = None
|
|
233
233
|
|
|
234
|
+
@property
|
|
235
|
+
def user_unit(self) -> TemperatureUnit | None:
|
|
236
|
+
"""Get the correct unit for the user."""
|
|
237
|
+
if self.use_metric is False:
|
|
238
|
+
return TemperatureUnit.FAHRENHEIT
|
|
239
|
+
if self.use_metric is True:
|
|
240
|
+
return TemperatureUnit.CELSIUS
|
|
241
|
+
return None
|
|
242
|
+
|
|
234
243
|
@property
|
|
235
244
|
def meta_display(self) -> str:
|
|
236
245
|
"""Return Meta infor based on preference."""
|
|
@@ -263,12 +272,12 @@ class MugData(AsDict):
|
|
|
263
272
|
@property
|
|
264
273
|
def current_temp_display(self) -> str:
|
|
265
274
|
"""Human-readable current temp with unit."""
|
|
266
|
-
return format_temp(self.current_temp, self.
|
|
275
|
+
return format_temp(self.current_temp, self.user_unit)
|
|
267
276
|
|
|
268
277
|
@property
|
|
269
278
|
def target_temp_display(self) -> str:
|
|
270
279
|
"""Human-readable target temp with unit."""
|
|
271
|
-
return format_temp(self.target_temp, self.
|
|
280
|
+
return format_temp(self.target_temp, self.user_unit)
|
|
272
281
|
|
|
273
282
|
def update_info(self, **kwargs: Any) -> list[Change]:
|
|
274
283
|
"""Update attributes of the mug if they haven't changed."""
|
|
@@ -288,7 +297,7 @@ class MugData(AsDict):
|
|
|
288
297
|
@property
|
|
289
298
|
def formatted(self) -> dict[str, Any]:
|
|
290
299
|
"""Return human-readable names and values for all attributes for display."""
|
|
291
|
-
all_attrs = self.model_info.device_attributes
|
|
300
|
+
all_attrs = set(self.model_info.device_attributes)
|
|
292
301
|
if not self.debug:
|
|
293
302
|
all_attrs -= EXTRA_ATTRS
|
|
294
303
|
return {label: self.get_formatted_attr(attr) for attr, label in ATTR_LABELS.items() if attr in all_attrs}
|
|
@@ -296,6 +305,7 @@ class MugData(AsDict):
|
|
|
296
305
|
def as_dict(self) -> dict[str, Any]:
|
|
297
306
|
"""Dump all attributes as dict for info/debugging."""
|
|
298
307
|
data = asdict(self)
|
|
308
|
+
del data["use_metric"]
|
|
299
309
|
all_attrs = self.model_info.device_attributes
|
|
300
310
|
if not self.debug:
|
|
301
311
|
all_attrs -= EXTRA_ATTRS
|
|
@@ -5,16 +5,17 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
7
|
if TYPE_CHECKING:
|
|
8
|
+
from .consts import TemperatureUnit
|
|
8
9
|
from .data import Colour
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
def format_temp(temp: float,
|
|
12
|
+
def format_temp(temp: float, unit: TemperatureUnit | None = None) -> str:
|
|
12
13
|
"""Format temperature with the correct unit."""
|
|
13
|
-
|
|
14
|
-
return f"{
|
|
14
|
+
value = f"{temp:.2f}"
|
|
15
|
+
return f"{value}{unit.value}" if unit else value
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
def format_capacity(capacity: int | None, metric: bool =
|
|
18
|
+
def format_capacity(capacity: int | None, metric: bool | None = None) -> str:
|
|
18
19
|
"""Format capacity for display."""
|
|
19
20
|
if capacity is None:
|
|
20
21
|
return "Unknown"
|
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import contextlib
|
|
7
7
|
import logging
|
|
8
|
+
import os
|
|
8
9
|
from datetime import UTC, datetime
|
|
9
10
|
from enum import Enum
|
|
10
11
|
from functools import cached_property
|
|
@@ -67,7 +68,7 @@ def require_attribute(
|
|
|
67
68
|
"""Inner decorator."""
|
|
68
69
|
|
|
69
70
|
async def wrapper(self: EmberMug, *args: P.args, **kwargs: P.kwargs) -> T:
|
|
70
|
-
if self.has_attribute(attr_name)
|
|
71
|
+
if not self.has_attribute(attr_name):
|
|
71
72
|
device_type = self.data.model_info.device_type.value
|
|
72
73
|
raise NotImplementedError(
|
|
73
74
|
f"The {device_type} does not have the {attr_name} attribute",
|
|
@@ -86,7 +87,7 @@ class EmberMug:
|
|
|
86
87
|
self,
|
|
87
88
|
ble_device: BLEDevice,
|
|
88
89
|
model_info: ModelInfo,
|
|
89
|
-
use_metric: bool =
|
|
90
|
+
use_metric: bool | None = None,
|
|
90
91
|
debug: bool = False,
|
|
91
92
|
**kwargs: Any,
|
|
92
93
|
) -> None:
|
|
@@ -135,17 +136,17 @@ class EmberMug:
|
|
|
135
136
|
|
|
136
137
|
def _convert_to_device_unit(self, value: float) -> float:
|
|
137
138
|
"""Convert user value to the unit the device expects."""
|
|
138
|
-
if self.data.
|
|
139
|
+
if self.data.user_unit == TemperatureUnit.CELSIUS and self.data.temperature_unit == TemperatureUnit.FAHRENHEIT:
|
|
139
140
|
return convert_temp_to_fahrenheit(value)
|
|
140
|
-
if
|
|
141
|
+
if self.data.user_unit == TemperatureUnit.FAHRENHEIT and self.data.temperature_unit == TemperatureUnit.CELSIUS:
|
|
141
142
|
return convert_temp_to_celsius(value)
|
|
142
143
|
return value
|
|
143
144
|
|
|
144
145
|
def _convert_to_user_unit(self, value: float) -> float:
|
|
145
146
|
"""Convert device value to the unit the user expects."""
|
|
146
|
-
if self.data.
|
|
147
|
+
if self.data.user_unit == TemperatureUnit.CELSIUS and self.data.temperature_unit == TemperatureUnit.FAHRENHEIT:
|
|
147
148
|
return convert_temp_to_celsius(value)
|
|
148
|
-
if
|
|
149
|
+
if self.data.user_unit == TemperatureUnit.FAHRENHEIT and self.data.temperature_unit == TemperatureUnit.CELSIUS:
|
|
149
150
|
return convert_temp_to_fahrenheit(value)
|
|
150
151
|
return value
|
|
151
152
|
|
|
@@ -275,6 +276,25 @@ class EmberMug:
|
|
|
275
276
|
"""Get Battery percent from mug gatt."""
|
|
276
277
|
return BatteryInfo.from_bytes(await self._read(MugCharacteristic.BATTERY))
|
|
277
278
|
|
|
279
|
+
async def make_writable(self) -> bool:
|
|
280
|
+
"""Try to make device writable if need be."""
|
|
281
|
+
if self.can_write:
|
|
282
|
+
return True
|
|
283
|
+
try:
|
|
284
|
+
await self._ensure_connection()
|
|
285
|
+
# Attempt to write a random string
|
|
286
|
+
await self.set_udsk(os.urandom(14).hex())
|
|
287
|
+
return True
|
|
288
|
+
except BleakError as e:
|
|
289
|
+
logger.debug("Failed to make device writable: %s", e)
|
|
290
|
+
return False
|
|
291
|
+
|
|
292
|
+
async def pair(self) -> None:
|
|
293
|
+
"""Attempt to pair."""
|
|
294
|
+
with contextlib.suppress(BleakError, EOFError):
|
|
295
|
+
await self._ensure_connection()
|
|
296
|
+
await self._client.pair()
|
|
297
|
+
|
|
278
298
|
@require_attribute("led_colour")
|
|
279
299
|
async def get_led_colour(self) -> Colour:
|
|
280
300
|
"""Get RGBA colours from mug gatt."""
|
|
@@ -294,11 +314,11 @@ class EmberMug:
|
|
|
294
314
|
|
|
295
315
|
async def set_target_temp(self, target_temp: float) -> None:
|
|
296
316
|
"""Set new target temp for mug."""
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
317
|
+
if self.data.use_metric is not None:
|
|
318
|
+
unit = TemperatureUnit.FAHRENHEIT if self.data.use_metric is False else TemperatureUnit.CELSIUS
|
|
319
|
+
min_temp, max_temp = MIN_MAX_TEMPS[unit]
|
|
320
|
+
if target_temp != 0 and not (min_temp <= target_temp <= max_temp):
|
|
321
|
+
raise ValueError(f"Temperature should be between {min_temp} and {max_temp} or 0.")
|
|
302
322
|
target_temp = self._convert_to_device_unit(target_temp)
|
|
303
323
|
target = bytearray(round(target_temp / 0.01).to_bytes(2, "little"))
|
|
304
324
|
await self._write(MugCharacteristic.TARGET_TEMPERATURE, target)
|
|
@@ -390,12 +410,6 @@ class EmberMug:
|
|
|
390
410
|
await self._write(MugCharacteristic.TEMPERATURE_UNIT, unit_bytes)
|
|
391
411
|
self.data.temperature_unit = TemperatureUnit(unit)
|
|
392
412
|
|
|
393
|
-
async def ensure_correct_unit(self) -> None:
|
|
394
|
-
"""Set mug unit if it's not what we want."""
|
|
395
|
-
desired = TemperatureUnit.CELSIUS if self.data.use_metric else TemperatureUnit.FAHRENHEIT
|
|
396
|
-
if self.data.temperature_unit != desired:
|
|
397
|
-
await self.set_temperature_unit(desired)
|
|
398
|
-
|
|
399
413
|
async def get_battery_voltage(self) -> int:
|
|
400
414
|
"""Get voltage and charge time."""
|
|
401
415
|
battery_voltage_bytes = await self._read(MugCharacteristic.CONTROL_REGISTER_DATA)
|
|
@@ -14,10 +14,11 @@ classifiers = [
|
|
|
14
14
|
'Programming Language :: Python :: 3.11',
|
|
15
15
|
'Programming Language :: Python :: 3.12',
|
|
16
16
|
'Programming Language :: Python :: 3.13',
|
|
17
|
+
'Programming Language :: Python :: 3.14',
|
|
17
18
|
]
|
|
18
19
|
dependencies = [
|
|
19
20
|
"bleak-retry-connector>=4.0.2",
|
|
20
|
-
"bleak>=1.0.1",
|
|
21
|
+
"bleak>=1.0.1,<2.2.0",
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
[project.optional-dependencies]
|
|
@@ -72,7 +73,8 @@ python = "3.13"
|
|
|
72
73
|
features = ["test"]
|
|
73
74
|
|
|
74
75
|
[[tool.hatch.envs.test.matrix]]
|
|
75
|
-
python = ["3.11", "3.12", "3.13"]
|
|
76
|
+
python = ["3.11", "3.12", "3.13", "3.14"]
|
|
77
|
+
bleak = ["1.0.1", "2.0.0"]
|
|
76
78
|
|
|
77
79
|
[tool.hatch.envs.test.scripts]
|
|
78
80
|
cov = "pytest -vvv --asyncio-mode=auto --cov=ember_mug --cov-branch --cov-report=xml --cov-report=term-missing tests"
|
|
@@ -89,7 +91,7 @@ serve = "mkdocs serve --dev-addr localhost:8000"
|
|
|
89
91
|
[tool.black]
|
|
90
92
|
line-length = 120
|
|
91
93
|
skip-string-normalization = true
|
|
92
|
-
target-version = ["py311", "py312", "py313"]
|
|
94
|
+
target-version = ["py311", "py312", "py313", "py314"]
|
|
93
95
|
include = '\.pyi?$'
|
|
94
96
|
exclude = '''
|
|
95
97
|
/(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|