Skip to content

Refactor and cleanup code#13

Merged
zweckj merged 10 commits into
mainfrom
refactor
Jul 12, 2026
Merged

Refactor and cleanup code#13
zweckj merged 10 commits into
mainfrom
refactor

Conversation

@zweckj

@zweckj zweckj commented Jul 12, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the aioacaia library by splitting previously monolithic helper/decoder logic into focused modules (discovery/encoder/parser/messages), updating AcaiaScale to use typed messages, and adding a new test suite to cover the message framing/parsing behavior.

Changes:

  • Refactors BLE discovery, encoding, and notification parsing into new modules (discovery.py, encoder.py, parser.py, messages.py) and updates AcaiaScale accordingly.
  • Adds comprehensive tests and fixtures for encoder/parser/scale behaviors.
  • Bumps project version to 0.2.0 and updates project metadata (including license switch to MIT).

Reviewed changes

Copilot reviewed 16 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
uv.lock Lockfile revision/version update plus extra metadata fields.
aioacaia/scale.py Switches to typed parsed messages; refactors weight/button handling into helpers.
aioacaia/parser.py New notification decoder/parser implementation and sample handler.
aioacaia/messages.py Introduces typed message dataclasses and button enum.
aioacaia/encoder.py New encoder implementation with checksum handling.
aioacaia/discovery.py Extracted BLE discovery + model-name derivation from removed helpers.
aioacaia/init.py Updates package exports to AcaiaScale from scale.py.
aioacaia/helpers.py Removed legacy mixed helper/encoding/discovery implementation.
aioacaia/decode.py Removed legacy decoder implementation in favor of parser.py.
tests/test_scale.py New tests for scale state updates, timer behavior, and queueing commands.
tests/test_parser.py New parser coverage for all decode branches and edge cases.
tests/test_encoder.py New tests for command framing and checksums.
tests/fixtures/messages.py Adds real/crafted frames for parser tests.
tests/init.py / tests/fixtures/init.py Establishes test package structure.
pyproject.toml Version/license/description update; adds pytest/pytest-asyncio config.
README.md Updates headline but leaves usage/docs inconsistent with refactor.
run.py Updates imports to new modules but leaves a now-broken debug call.
LICENSE Replaces AGPLv3 text with MIT license text.
Comments suppressed due to low confidence (1)

README.md:7

  • The README usage snippet is currently not valid Python (missing : and indentation) and references removed/renamed APIs (aioacaia.helpers.find_acaia_devices, AcaiaScale.create, startStopTimer, resetTimer). Since this PR refactors these modules, the README should be updated to match the new public entrypoints and method names.
Python library to interact with your acaia scales.

# Usage

```python

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aioacaia/parser.py Outdated
Comment thread run.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 23 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

aioacaia/scale.py:536

  • In the AcaiaMessageTooLong recovery path, the inner probe decode(pending[next_start:]) only catches AcaiaMessageError. If that candidate header produces AcaiaMessageTooShort or AcaiaMessageTooLong, the exception will escape on_bluetooth_data_received, potentially crashing the Bleak notification callback and breaking further state updates. Treat these framing exceptions as "not a valid resync point" and continue scanning for the next header instead.

Comment thread pyproject.toml
@zweckj
zweckj merged commit 579669c into main Jul 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants