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

Remove pygatt and use bluepy.btle #47

Merged
merged 4 commits into from
Mar 16, 2021
Merged

Remove pygatt and use bluepy.btle #47

merged 4 commits into from
Mar 16, 2021

Conversation

sverrham
Copy link
Collaborator

So I have not tested this update in HA, but tested standalone to work on a rpi4.

If you want you can try it out, review it. I don't know if I have time to test it in HA until next weekend.
Hope it should improve stability by removing pygatt, don't know if it will.

…sted this file main function on rpi4 and that works.
@mindtripper
Copy link

mindtripper commented Mar 15, 2021

I think this is the right move for this component. Moving away from PYGATT. As it seems to be deprecated.
Testing this change now. Will give feedback as soon as I have any.

Please note: I had to execute the following command in the docker container to install bluepy successfully;
pip install --find-links $WHEELS_LINKS bluepy==1.3.0
Ref: home-assistant/core#24441 (comment)

I have been logging connection errors on the original component for about 6 months. The counter was at;
image
Hoping it will stay at that number :)

@MartyTremblay
Copy link
Member

@sverrham , I'm very excited to try this out!

@MartyTremblay
Copy link
Member

Please note: I had to execute the following command in the docker container to install bluepy successfully;
pip install --find-links $WHEELS_LINKS bluepy==1.3.0

I think all we have to do is add the dependency to the https://github.com/custom-components/sensor.airthings_wave/blob/master/custom_components/airthings_wave/manifest.json file and remove the reference to the old pygatt requirement for good measure.

"requirements": ["bluepy==1.3.0"]

@lymanbuttler
Copy link

lymanbuttler commented Mar 15, 2021 via email

@MartyTremblay
Copy link
Member

Does Home Assistant OS support bluepy? If not can we request that they do?

Pretty sure it does. There are a few built-in components that require it.

@sverrham
Copy link
Collaborator Author

I was looking for a little bit what library to use, what would be maintained, did not realy land on anything as the best candidate so I just used what Airthings has used in their examples.

Don't think bluepy actually is maintained so maybe we need to change down the road, but the hope is that it is more stable then current solution.

@MartyTremblay
Copy link
Member

Just tried this out. Works great @sverrham !

I did notice that it did incremented the name of the entities. for example, where I had sensor.98_xx_xx_xx_xx_xx_radon_1day_avg has now become sensor.98_xx_xx_xx_xx_xx_radon_1day_avg_2. Just a heads-up in case anyone else has the same byproduct which will affect the history of each related entity.

@mindtripper , let us know how your testing goes. If all looks well, I'll merge the PR and up the version to v3.0

@mindtripper
Copy link

mindtripper commented Mar 15, 2021

@MartyTremblay I experience the same as you did.
I solved it by;

  1. Removed the integration. (Comment out the YAML)
  2. Restart HA.
  3. Delete all the "lingering" sensors.
  4. Re-add integration.(Uncomment the YAML)
  5. Restart HA.

I also experienced an issue with capital letters in the mac: part of the sensor configuration. Changed it to lowercase and it solved the issue.

So far today, I have had no issues with connectivity. Will keep you and @sverrham posted on the stability.

@sverrham
Copy link
Collaborator Author

sverrham commented Mar 15, 2021

I did notice that it did incremented the name of the entities. for example, where I had sensor.98_xx_xx_xx_xx_xx_radon_1day_avg has now become sensor.98_xx_xx_xx_xx_xx_radon_1day_avg_2. Just a heads-up in case anyone else has the same byproduct which will affect the history of each related entity.

Strange the uniqe id should be the same, I did not check, but for me the old code seems to have capital letters for the mac, if the new code does not I guess that might be the reason, lets fix that.

I also experienced an issue with capital letters in the mac: part of the sensor configuration. Changed it to lowercase and it solved the issue.

Should fix this also.

Fix bug with mac entered, always use lowercase mac to connect, so entered mac case does not matter.
Fix bug changed entity, force to use uppercase mac for unique id.
@sverrham sverrham linked an issue Mar 15, 2021 that may be closed by this pull request
@sverrham
Copy link
Collaborator Author

sverrham commented Mar 15, 2021

So this latest commit should fix the mac issues and duplicate entities, now upper case is enforced for the unique name so it should be the same no matter what is found or entered.
Also lower case is always used for connection so that should always work no matter what is configured.

Sorry @mindtripper @MartyTremblay this should break your sensor ids again, but should be consistent going forward, I hope.

@mindtripper
Copy link

No worries @sverrham. I'm impressed with your effort!
I have no problems testing, re-testing, breaking and fixing my setup with your PR's.

With the latest PR's, I can use upper and lower case without issues. All tested, No problems.
(Except that I initially had to clean up the sensors. As you expected).

@MartyTremblay
Copy link
Member

I'm done my testing as well. This works wonderfully. Amazing work @sverrham !

resolves #26 #33 #42 #46

@MartyTremblay MartyTremblay reopened this Mar 16, 2021
@MartyTremblay MartyTremblay merged commit cb9ff2f into custom-components:master Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants