-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conflicting bleak library version with HomeAssistant 2022.8 #93
Comments
Just upgraded HA to |
HA 2022.8 added native bluetooth support using the bleak library - https://www.home-assistant.io/blog/2022/08/03/release-20228/#first-class-bluetooth-support I modified the manifest.json file to reference bleak 0.15.0, but it's still not working. Here's what the log shows.
|
Just a question: As the this integration is unsupported for the time being, will devs focus on the new BT integration, if even possible? |
bleak v0.15 is considered a potentially breaking release based on semserv versioning of a 0.x pre-release (aka unstable). I'm not a python dev, but it looks like poor debugging output as we don't actually know what the exception is here: https://github.com/custom-components/sensor.airthings_wave/blob/master/custom_components/airthings_wave/airthings.py#L245 |
I added logging of the exception details: This might be the root cause of the issue:
|
I've been debugging on a fork (https://github.com/lone-cloud/sensor.airthings_wave) and I'm getting the exact same error. I would definitely agree that it's the root cause of the issue here. The eception implies that there are multiple threads running and python doesn't seem to like when variables set in one thread get re-assigned in another. I have not been able to figure it out yet. |
In my opinion we should adapt this component to the new bluetooth integration. However i'm quite busy at the moment and also lacking the experience here. |
Tons of hints on how to update to bleak 0.15.0 here home-assistant/core@80a9659 |
While I have not done much digging yet, I wonder if this is potentially related to the issue addressed by flecmart's PR. I wonder that because I have tried the dev branches of my own related scripts (here and here) against Bleak 0.15.1 and they work without issue, but I did implement flecmart's changes to ensure that disconnect is always called. It may be worth looking into that angle. |
@mjmccans I don't understand how anything works for you because using bleak 0.15.1 will result in the same bleak version mismatch that we started out with. edit: I noticed that a new HA patch just came out (for me) which is on bleak 0.15.1. This custom component really needs to migrate to using the new bluetooth integration instead of calling bleak directly, as was suggested, otherwise we'll keep running into this issue. flecmart's PR didn't solve the issue, but I noticed that it broke exception handling because he was raising exceptions that didn't originate from the base Exception class. You'll see a very unhelpful "exceptions must derive from BaseException" errors in the log without fixing the new I did look over home-assistant/core@80a9659 but I couldn't find anything relevant to the issue here. Saying that, I'm a (mostly) typescript dev and this is my first time playing with python and with HA custom integration dev in general. I'm now at my wit's end about this |
@lone-cloud I will start with a disclaimer that I am not expert in this area, so please keep that in mind when reviewing anything I say here. I did the initial conversion from Bluepy to Bleak, but I definitely made mistakes along the way (some of which may not have been found yet). In terms of my scripts, one is a script that is meant to run on a machine separate from Home Assistant and it would have its own version of Bleak. The use case for me was to have the script running on a Raspberry Pi closer to the Airthings device which would in turn send the sensor values to Home Assistant using MQTT. The other is that same script packaged as a Home Assistant add-on, which I made when I transitioned to Home Assistant OS. The add-on runs in its own container and also has its own version of Bleak, and Home Assistant exposes the DBUS socket to the container for communications with the bluetooth adapter. What I find is interesting is that these scripts appear to have no issue running with their own copies of Bleak 0.15.1. The reason I thought flecmart's PR could be in play was the remark about this looking like a potential threading issue, and that was also the only difference between my version of airthings.py and the one in this repository. I wonder if the issue is that the new bluetooth integration is not playing nice with this custom integration and that is causing the issue. Ultimately @B1ob is likely correct that the right answer is to move to the new bluetooth integration, but it would be interesting to see if the issue goes away if you uninstall or disable the new Home Assistant bluetooth integration. That could help debug this issue, or show that I am completely out to lunch. |
I just re-tested on the latest HA with bleak 0.15.1 and the new bluetooth integration removed. It appears that the issue is indeed because of the new bluetooth integration. Unfortunately, when it's disabled this component still fails to connect due to |
Well, I guess that is progress. Probably obvious, but this link has some details and best practices for using the new bluetooth integration. It is not urgent for me to dig into at the moment because my scripts are still working, but I am interested in the topic and will try to dive in in the future. From the documentation it actually looks like it would be pretty easy to get auto-discovery working, which would be pretty useful. |
I was trying to find some documentation about how to use the new bluetooh integration as a developer. Do we even need a custom component after integrating the airthing devices with the new integration? |
Yes, as i understand it the integrations rely on the new bluetooth integration as a kind of middleware. As stated on the bluetooth integration page under "Integrations that require exclusive use of the Bluetooth Adapter" this does not work in parallel with legacy integrations. I also thought it could be possible to introduce "async" to the sensor.py. However i still think adapting to the new integration is the best approach. |
I've played around a with this I think we need to wait for home-assistant/core#76342 to be merged as it adds polling possibilities to the new system. Anyways, here's some of my progress 🎉 first time working on home assistant integrations 👶 |
API changes coming in 2022.9 - https://developers.home-assistant.io/blog/2022/08/08/bluetooth-api-changes/ |
Like the others I have the same issue. Actually updated from Feb update. |
I downgraded back to 20.22.7 for now. Thank |
Back to 2022.7.7 for me also (HA 2022.8.3 is using bleak 0.15.1) HA 2022.8.3 breaks more than just this component and it probably doesnt help i'm using python 3.9x as well. Funny coincidence bleak 0.15.1 development was sponsered by nabucasa.com |
https://github.com/mjmccans/hassio-addon-airthings, this is working with Airthings wave with current Home Assistant release. |
Thanks for the info @BladeBear, However, the project link you provided is an add-on and not an HA component which means that it doesn't depend on the same bleak instance as the one built into HA. None the less, this MQTT approach clearly works and could be a viable solution until we get our component working again. |
I've gotten hard stuck on the new way to connect to BLE devices: |
HA integrations in core have to push some of their logic for talking to a device to a library on pypi. So what you'll probably find is stuff like this where the bledevice is passed to an external library and that is where the BleakClient lives. There will also be logic in there to handle if the BLEDevice changes (via What does the output from async_ble_device_from_address look like for you? I don't know if it will help but make sure that your custom component depends on the |
I started working on a draft to try and get this into core. That's inspired from the Bluetooth devices repos, but since there are no advertisements, it's closer to PySwitchbot. Got some minor help from bdraco where to find the docs and how to think around this. It works and the core component is kind of done. But haven't been able to commit it to my fork due to pre-commit errors for an unrelated file. Anyways, that's irrelevant for this issue though :) |
Very clean! |
Thanks! |
Hi @vincegio nice work :) i had a first look at your integration. My feedback is the following:
|
Thank you 👍 The entity part makes sense, thought it'd just add |
Tried the instruction above: Logger: custom_components.airthings_ble.config_flow |
Was it added to 2022.9 ? Is there a HACS module ? |
It looks like it didn't make it into 2022.9. |
No it didn't. It was very close, but some of the HA developers wanted to wait until we had better UX for the case where there are 2 integrations for the same devices. We pushed for an approach that shouldn't cause @vincegio too much extra hassle, so I hope this is only a minor blip and we can get it in next month. RE HACS - Personally, I would try and get code review done before publishing anything standalone, in case we do end up needing to make breaking changes to the unique identifiers or the config entry data. When those things go wrong it can make a bit of a mess (i've had to hand edit JSON to repair this sort of thing before). If people want to take that risk for themselves, they can grab the code from the branch. Its still fairly easy, but they will be more aware that if it breaks they get to keep the pieces. |
bummer. I decided to wait for it to get 2022.9 but now I am seriously considering grabbing the code. Thanks for the update |
I am currently getting this error after updating to 2022.9 Logger: homeassistant.util.package Unable to install package airthings-ble==0.5.0: ERROR: Cannot install airthings-ble==0.5.0 because these package versions have conflicting dependencies. ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts |
Just updated HA to @vincegio any idea on what this could be? I see that airthings-ble module is available from pypi.
|
It might be bleak again, new ha version seems to use 0.16 |
Sort of.
The @vincegio could swap the |
I'll try to do some updates asap. As well with getting the PR reviews completed. I'll think about making a hacs component, but could also include some kind of warning about it. |
I have temporarily solved it, by merging the airthings-ble files from https://github.com/vincegio/airthings-ble into the custom_components/airthings_ble folder and removed the dependency on airthings-ble in the manifest.json file. |
For those who have copied the component manually, head on over to the manifest and update:
|
Thanks @vincegio! Just of curiosity, why did you extract |
It's a hard HA rule. I had to do it for one of my integrations where I made like one HTTP get and decode JSON to a dict. Although tedious in more extreme cases, the point is that integrations are meant to be about data mapping/translation, and your library is meant to do all the hard stuff talking to the device. |
Alright, that makes sense! |
Is there any progress with this? I'm still getting same error in Home Assistant 2022.9.6 |
@vincegio's PR was merged. It looks like it just missed the beta cut off. I'd ask for a backport but there are a few more tweaks requested on it. So as it stands it'll be in 2022.11. |
I just updated HA to 2022.10.3, and I can't get HA to start with airthings_wave. If I change airthings_wave/manifest.txt to make bleak that version, it reports an error:
I think it is an API change in bleak, and HA has the new call, while airthings_wave is using an old call. What can one do now? |
@kbahey a "new"/ported airthings integration is on path of getting released as part of 2022.11. until that happens you need to roll back to a HA version that supports this component. |
Thanks for the reply. In the meantime, for others who can't wait ... I found a standalone solution that works provided that you have MQTT running (which I do). It is airthings-mqtt-ha. Install paho-mqtt and bleak using pip3, run the above Python script once to generate a configuration file, edit the file to your liking, then run it again as a daemon. Add MQTT sensors for each item that is returned by the AirThings Wave Plus, and you are done. |
The new built-in integration is working great in 2022.11! Thanks for all the hard work! |
I have moved from my addon to the new integration and it is working well. The auto-discovery is also fantastic from a user experience perspective. Thank you for all the work getting this into Core. The only minor gripe that I have is rounding (or lack thereof) of the sensor values. Given the sensors in the device my personal preference from a significant digits perspective (and what my addon did) is to round all of the values to not include any decimals except for the temperature that I would round to one decimal point. I am not sure if anyone else agrees, but for now I have just added some template sensors that do the rounding in my configuration file. |
Thanks for new improved integration. However, I still have some issues... The new Airthing BLE intergrations finds my Airthings wave plus immediately and starts showing values from the device. After a few minutes, Home Assistant stops showing any values and and connection is lost. "Entity is unavailable" placeholder remains until I reboot the server os reinstall the integration. I checked from the terminal using bluetootctl scan that device is broadcasting information all the time. For some reason (unknown to me) it just does not work. Log entry: Unable to fetch data: [MAC address]. Failed to connect, device was not found, It may have been removed from BlueZ when scanning stopped. Error fetching airthings_ble data: Unable to fetch data: 'NoneType' object has no attribute 'address' Any ideas whats going wrong here? |
The right place to get help with integrations in HA Core is the HA GitHub. But that error suggests to me that it's actually outside the range of your bluetooth. Range in bluetooth is asymmetric - you can have enough signal to see some advertisements, but it be too weak for 2-way communication, which makes using bluetoothctl to debug this challenging. What sort of RSSI can you see in the bluetoothctl output you mention? |
I need to investigate more thoroughly when I get home and check the RSSI levels. The direct distance is very short between RPI and Airthings wave but they are located in different floors. I have ESP32s scattered around the building also, maybe I can use one of them to communicate with AirThings? |
It looks like 2022.8 has updated to bleak 0.15.0 home-assistant/core#75941
When trying to use 4.0.0 of sensor.airthings_wave I get the following error in the logs:
The text was updated successfully, but these errors were encountered: