Skip to content

Fix Unpack in DL Mode - #48

Closed
dereisele wants to merge 31 commits into
PyBLNET:masterfrom
dereisele:master
Closed

dereisele wants to merge 31 commits into
PyBLNET:masterfrom
dereisele:master

Conversation

@dereisele

Copy link
Copy Markdown
Collaborator

Fix unpack in DL_MODE

Hi, I found a small bug when using the DL_MODE, since my UVR1611 has the CAN-Bus disabled.

Anyway, thanks a lot for this library

@nielstron

Copy link
Copy Markdown
Member

Thanks for your contribution! Looks good to me.

dereisele and others added 15 commits February 23, 2026 23:46
The heat meter register uses bit 0 for meter 1 and bit 1 for meter 2,
but the parser tested `active & position`, so meter 1 was never reported
and meter 2 showed garbage whenever meter 1 was active.

Inputs of type 000 are unused according to TA's interface spec and are
now returned as None instead of their raw value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- get_value() raised KeyError because values fetched only via
  blnet_direct have no name; match on the id key instead
- get_latest() stored the string "timeout" as a frame, which crashed
  fetch(), and also did so when the last retry succeeded; timed out
  frames are now listed in info["timeout"] and fetch() raises
  ConnectionError if no data arrived
- BLNETDirect set the process-wide default socket timeout, and only
  after the first connection; the timeout is now set on its own sockets

Adds a fake TCP BL-NET replaying responses recorded from a real device
in DL mode, so BLNETDirect is covered by tests for the first time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The haus-terra link to TA's interface spec returns 404, point to the
archived copy instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Build with uv_build instead of flit_core, publish with uv build and
  uv publish instead of the flit action
- Replace Pipfile and the test extra with a uv dev dependency group,
  commit uv.lock and use uv in CI
- Set requires-python to >=3.8 to match CI; >=3 made uv resolve
  dependencies for Python 3.0 and up
- Use a PEP 639 license expression so LICENSE.txt ends up in the
  packages, drop invalid keys readme-content-type and homepage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Python 3.10 reached end of life on 2026-10-01, so 3.11 is the oldest
supported version. Test on 3.11 to 3.15 in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Enable ruff's UP rules on top of the defaults and apply their fixes:
f-strings instead of format(), no coding headers, no object base class,
OSError instead of its alias EnvironmentError, and no Python 2
builtins imports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a copyright line for my contributions below the original notice,
which stays unchanged as the MIT license requires, and list me as
author in the package metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- actions/checkout v4 -> v7, v4 still targets the deprecated Node.js 20
- Run the coveralls finish job with uvx instead of pip in a python
  container

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The PyBLNET package on PyPI belongs to upstream, this fork has no
access to it.

- Release workflow builds first, then creates the GitHub release with
  wheel and sdist attached instead of publishing to PyPI
- README: drop PyPI badges, point build and coverage badges to this
  fork, document installing from GitHub, describe the current state of
  BLNet-Direct testing
- Point the homepage URL to this fork and list upstream separately

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When connecting to one of the resolved addresses failed, the socket was
dropped without closing it, which Python 3.14+ reports as
ResourceWarning. Only catch OSError instead of everything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BLNETDirect always used its default of 60 seconds, so a BL-NET that
stopped answering blocked fetch() for a minute regardless of the
timeout given to BLNET.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@socket-security

socket-security Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedpypi/​pytest@​9.2.0 ⏵ 9.0.28799 -1100100100
Addedpypi/​coverage@​7.16.295100100100100
Updatedpypi/​requests@​2.34.2 ⏵ 2.32.59999 -1100100100
Addedpypi/​ruff@​0.17.0100100100100100

View full report

dereisele and others added 12 commits October 11, 2026 20:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A timeout or other error while reading left the socket open, and since
_connect() only connects without a socket, every later call reused the
dead connection. A BLNET object, as kept by Home Assistant, never
recovered until it was recreated.

- Close the socket and reset the read state on any error in get_latest,
  get_count, _get_data and the mode check in the constructor, which also
  leaked its socket on timeout
- Raise ConnectionError when the BL-Net closes the connection or sends a
  malformed reply instead of IndexError or struct.error
- Use sendall instead of send
- _get_data no longer swallows errors with a return in finally

Errors from the direct connection are now always OSError subclasses:
ConnectionError or TimeoutError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A real BL-Net answers GET_LATEST with a single 0xAB byte ("no data
available", see TA's interface spec) for up to about 5 seconds after a
read. The retries ran without any pause, so every read shortly after
the previous one failed with ConnectionError. Wait 2 seconds after such
a reply before the next try.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
htmldom is unmaintained and mangles parts of the BL-NET pages (button
text "<=" ends up as tag fragments in the extracted text). A small
html.parser based helper extracts the text of matching elements the
way the value regexes expect: entities like &nbsp; kept as written and
<br> as newline, including nested matching elements.

Adds tests on the saved device pages for cases the mock server tests
didn't cover (negative values, access denied page, blnet_test). They
pass with both implementations, and both give identical results on all
saved pages. requests is now the only runtime dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Home Assistant showed every analog input in °C and speed in rpm. The
parser already read the input type bits but dropped them.

- BLNETParser exposes analog_types: temperature, volume_flow, radiation,
  digital or None for unused and undocumented types
- BLNET.fetch() adds type and unit_of_measurement to analog entries from
  the direct connection, and type (derived from the shown unit) to
  entries from the web interface
- speed, energy and power entries carry unit_of_measurement: None (speed
  is a level 0-30, not rpm), kWh and kW

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A temperature input without sensor or with a broken wire reads all
value bits set, 409.5 °C, which no real sensor reaches. Return None for
it like for unused inputs, so fetch() leaves it out instead of
reporting 409.5 °C. Confirmed with the hydraulics chart of the recorded
BL-NET: inputs 1-5 and 15 have no sensor connected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BL-NETs sometimes send the first byte of a GET_LATEST reply in a TCP
segment of its own. _query() stopped after that byte, so the rest of
the reply was read as the start of the next one and all following
replies were shifted by one byte. The sum checksum accepts about one in
128 of those shifted datasets, which showed up as occasional garbage
values like -3807 °C or jumps of the energy meter.

Derive the reply length from its first byte and read it completely,
and reconnect after a reply with a bad checksum so that stray bytes
can't end up in the next reply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KJJTUv5YaVyYB197zeuqBp
…nus-1000-suw6ku

Read GET_LATEST replies completely
@socket-security

socket-security Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Priority Alert  (click "▶" to expand/collapse) Action
Critical priority
Critical CVE: pypi certifi bundles emSign root CAs with compromised intermediate CA keys

CVE: GHSA-6q48-6c7w-9gw2 certifi bundles emSign root CAs with compromised intermediate CA keys (CRITICAL)

Affected versions: >= 2019.03.09 < 2026.10.18

Patched version: 2026.10.18

From: uv.lock → pypi/requests@2.32.5 → pypi/certifi@2026.1.4

ℹ Read more on: This package | This alert | What is a critical CVE?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Remove or replace dependencies that include known critical CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore pypi/certifi@2026.1.4. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn

View full report

claude and others added 2 commits November 15, 2026 16:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KJJTUv5YaVyYB197zeuqBp
@nielstron

Copy link
Copy Markdown
Member

@dereisele it appears you are now maintaining your own fork of this. Are you interested in taking over maintenaince of this package? I don't have a BLNET to debug changes on my own and it seems you have one available and potent coding support :)

@dereisele

Copy link
Copy Markdown
Collaborator Author

I do have a BLNET, but I never got the CAN Bus working... Maybe you could create a GitHub Orga and ask @volkerfrank73 to join. He ported this library to async https://github.com/volkerfrank73/pyblnet-async

@nielstron

Copy link
Copy Markdown
Member

Done! I would strongly advise to merge the repos together ultimately to prevent diverging implementations. But please feel free to maintain them now in a consistent organization.

@nielstron nielstron closed this Nov 16, 2026
@volkerfrank73

Copy link
Copy Markdown
Member

Thanks @nielstron for setting up the organization, and @dereisele for suggesting it! I'm happy to join.

A bit about me: I run a UVR1611 with a BL-NET on the CAN bus and read it through the web interface and the TA port in Home Assistant, using pyblnet-async. I agree that the two implementations should be merged eventually.

@nielstron, how do you imagine the collaboration going forward? And would you like to keep supporting the project, for example with reviews or PyPI releases, or would you rather hand it over completely? Right now I only have read access to the repo. If you'd like me to help maintain it, could you give me write or maintain rights?

@dereisele, would you like to join as well? Your setup runs in DL mode and mine on CAN, so between us we could test both modes on real hardware, and most of the recent fixes came from you.

Best regards,
Volker

@nielstron

Copy link
Copy Markdown
Member

I am happy to hand over the project to both of you. I think I invited you both to be maintainers of this project, let me know if that's not the case. I can also add you to the pypi package as owners if needed but the current setup should work fine by you pushing new release tags.

@volkerfrank73

Copy link
Copy Markdown
Member

Thanks, @nielstron! I've accepted the invitation and will keep maintaining the project. Thanks for all your work on pyblnet!

Best regards,
Volker

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.

4 participants