Skip to content

Commit

Permalink
Return early if device is unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
LaStrada committed Jan 2, 2025
1 parent 366cf04 commit ea0c553
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions airthings_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class DisconnectedError(Exception):
"""Disconnected from device."""


class UnsupportedDeviceError(Exception):
"""Unsupported device."""


def _decode_base(
name: str, format_type: str, scale: float
) -> Callable[[bytearray], dict[str, Tuple[float, ...]]]:
Expand Down Expand Up @@ -574,10 +578,8 @@ async def _get_device_characteristics(

device_info.model = AirthingsDeviceType.from_raw_value(data.decode("utf-8"))
if device_info.model == AirthingsDeviceType.UNKNOWN:
self.logger.warning(
"Could not map model number to model name, "
"most likely an unsupported device: %s",
data.decode("utf-8"),
raise UnsupportedDeviceError(
f"Model {data.decode('utf-8')} is not supported"
)

characteristics = _CHARS_BY_MODELS.get(
Expand Down Expand Up @@ -871,6 +873,8 @@ async def _update_device(self, ble_device: BLEDevice) -> AirthingsDevice:
# missing from the cache
await client.clear_cache()
raise
except UnsupportedDeviceError as err:
self.logger.warning("Unsupported device: %s", err)
finally:
await client.disconnect()

Expand Down

0 comments on commit ea0c553

Please sign in to comment.