Skip to content

Commit

Permalink
fix is_new_scale
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Nov 29, 2024
1 parent 6f6aacd commit 8a6abe7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions aioacaia/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,22 @@ async def scan(scanner: BleakScanner, timeout) -> list:

async def is_new_scale(address_or_ble_device: str | BLEDevice) -> bool:
"""Check if the scale is a new style scale."""
async with BleakClient(address_or_ble_device) as client:
try:
await client.connect()
except BleakDeviceNotFoundError as ex:
raise AcaiaDeviceNotFound("Device not found") from ex
except (BleakError, Exception) as ex:
raise AcaiaError from ex

characteristics = []
for char in client.services.characteristics.values():
characteristics.append(char.uuid)

if OLD_STYLE_CHAR_ID in characteristics:
return False
if DEFAULT_CHAR_ID in characteristics:
return True
raise AcaiaUnknownDevice

try:
async with BleakClient(address_or_ble_device) as client:
characteristics = []
for char in client.services.characteristics.values():
characteristics.append(char.uuid)
except BleakDeviceNotFoundError as ex:
raise AcaiaDeviceNotFound("Device not found") from ex
except (BleakError, Exception) as ex:
raise AcaiaError(ex) from ex

if OLD_STYLE_CHAR_ID in characteristics:
return False
if DEFAULT_CHAR_ID in characteristics:
return True
raise AcaiaUnknownDevice


def encode(msg_type: int, payload: bytearray | list[int]) -> bytearray:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "aioacaia"
version = "0.1.9"
version = "0.1.10"
license = { text = "MIT License" }
description = "An async implementation of PyAcaia"
readme = "README.md"
Expand Down

0 comments on commit 8a6abe7

Please sign in to comment.