python-ember-mug 1.3.0b3__tar.gz → 1.3.0b4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-ember-mug
3
- Version: 1.3.0b3
3
+ Version: 1.3.0b4
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/
@@ -6,4 +6,4 @@ __all__ = ("EmberMug",)
6
6
 
7
7
  __author__ = """Jesse Sopel"""
8
8
  __email__ = "jesse.sopel@gmail.com"
9
- __version__ = "1.3.0b3"
9
+ __version__ = "1.3.0b4"
@@ -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
@@ -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."""