Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use little endian in float conversion #197

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/bthome_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
"""Convert bytes (as float) and factor to float."""
decimal_places = -int(f"{factor:e}".split("e")[-1])
if len(data_obj) == 2:
[val] = struct.unpack("e", data_obj)
[val] = struct.unpack("<e", data_obj)
elif len(data_obj) == 4:
[val] = struct.unpack("f", data_obj)
[val] = struct.unpack("<f", data_obj)

Check warning on line 71 in src/bthome_ble/parser.py

View check run for this annotation

Codecov / codecov/patch

src/bthome_ble/parser.py#L71

Added line #L71 was not covered by tests
elif len(data_obj) == 8:
[val] = struct.unpack("d", data_obj)
[val] = struct.unpack("<d", data_obj)

Check warning on line 73 in src/bthome_ble/parser.py

View check run for this annotation

Codecov / codecov/patch

src/bthome_ble/parser.py#L73

Added line #L73 was not covered by tests
else:
_LOGGER.error("only 2, 4 or 8 byte long floats are supported in BTHome BLE")
return None
Expand Down
Loading