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

Fixed a bug where specifying a MAC Address does not work #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MaxAnderson95
Copy link

When instantiating the Aranet4 client class, there is the option to specify a mac_address in the constructor. This means the class will connect to this address rather than running auto-disovery to find the aranet4 device.

This currently doesn't work, because the _client property is never instantiated when specifying the address manually. You simply receive an error that says _client of None type does not have a method read_gatt_char().

Digging into this, it looks like a simple fix. In the _read_value() method, simply always call self._discover() regardless of if self.address is specified or not. The _discover() method already has logic to check for the presence of self.address and will skip auto discovery accordingly. It then properly instantiates the BleakClient and calls connect().

I've tested this and it works perfect for me.

@MaxAnderson95 MaxAnderson95 marked this pull request as draft December 28, 2023 01:47
…to _read_value, we check for _client or for if _client.is_connected is false. If so we call connect (this logic was moved to its own method)
@MaxAnderson95
Copy link
Author

My first attempt at this worked but was a naive approach. It will cause a re-connection on every call to _read_value(). I moved the connection logic to its own method, and then we call that method in _discover() or if _client is none, or if _client.is_connected is False.

I also threw in some additional error messaging into the logging call.

@MaxAnderson95 MaxAnderson95 marked this pull request as ready for review December 28, 2023 02:36
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.

None yet

1 participant