python-ember-mug 1.3.0b2__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.0b2
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.0b2"
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
@@ -174,8 +175,6 @@ class EmberMug:
174
175
  disconnected_callback=self._disconnect_callback,
175
176
  ble_device_callback=lambda: self.device,
176
177
  )
177
- if self.debug:
178
- await discover_services(client)
179
178
  self._expected_disconnect = False
180
179
  except (TimeoutError, BleakError) as error:
181
180
  logger.debug("%s: Failed to connect to the mug: %s", self.device, error)
@@ -277,6 +276,25 @@ class EmberMug:
277
276
  """Get Battery percent from mug gatt."""
278
277
  return BatteryInfo.from_bytes(await self._read(MugCharacteristic.BATTERY))
279
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
+
280
298
  @require_attribute("led_colour")
281
299
  async def get_led_colour(self) -> Colour:
282
300
  """Get RGBA colours from mug gatt."""