home_assistant_delonghi_primadonna icon indicating copy to clipboard operation
home_assistant_delonghi_primadonna copied to clipboard

little problem on macOS

Open bubez81 opened this issue 2 years ago • 22 comments

Hello! great I sow the bleak integration. Unfortunately there is a problem on macOS: I receive errors: [custom_components.delonghi_primadonna.device] BleakError: Device with address 00:A0:50:1D:99:27 was not found and it's related to https://bleak.readthedocs.io/en/latest/backends/macos.html

#https://github.com/hbldh/bleak/issues/252

bubez81 avatar Jul 26 '22 19:07 bubez81

Got familuar problem on Linux. Looks like this integration conflicts with the other bluetooth.

Checking.

Arbuzov avatar Jul 30 '22 20:07 Arbuzov

Could you please check? 1.1.1 I have added BLE discovery as it was recommended by the Home Assistant community.

Arbuzov avatar Jul 31 '22 16:07 Arbuzov

Sure, but I can't see difference...I use this MAC address: 8BB8F40D-4437-3E11-9FEE-97D8C0584A48 because bleak on my Mac can discover only this tipe of ids: Schermata 2022-07-31 alle 21 55 28 I can see a connection too: Schermata 2022-07-31 alle 21 55 50

But home assistant: 2022-07-31 21:56:28 WARNING (MainThread) [custom_components.delonghi_primadonna.device] BleakError: Characteristic 00002a00-0000-1000-8000-00805f9b34fb was not found!

This is what I found on the documentation: mac_addr = ( "24:71:89:cc:09:05" if platform.system() != "Darwin" else "243E23AE-4A99-406C-B317-18F1BD7B4CBE" )

bubez81 avatar Jul 31 '22 19:07 bubez81

That`s interesting. Could you please check if devices are connected? If it is plugin will not establish connection.

Arbuzov avatar Aug 02 '22 21:08 Arbuzov

what do you mean? when the plugin establishes the connection i can see that the mac connects to the machine obviously

I tried with a python script: python3 service_explorer.py INFO:__main__:Connected: True INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

this is the script: https://github.com/hbldh/bleak/blob/develop/examples/service_explorer.py

bubez81 avatar Aug 03 '22 05:08 bubez81

if I perform a scan on a different machine (raspberry 4) the characteristics are more:

INFO:__main__:Connected: True INFO:__main__:[Service] 00001801-0000-1000-8000-00805f9b34fb (Handle: 10): Generic Attribute Profile INFO:__main__: [Characteristic] 00002a05-0000-1000-8000-00805f9b34fb (Handle: 11): Service Changed (indicate), Value: None INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 13): Client Characteristic Configuration) | Value: b'\x02\x00' INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

bubez81 avatar Aug 03 '22 16:08 bubez81

Maybe it's a bleak version problem, it's possible to use the new one?

bubez81 avatar Aug 03 '22 17:08 bubez81

ok I was wrong, the problem is that on mac it is as if the device were registered twice so after the integration has been added it is no longer possible, even from the same mac, to communicate with the machine. I admit that I really don't know how to solve this problem

bubez81 avatar Aug 09 '22 18:08 bubez81

The new version of HA can partially solve it. They added kinda Bluetooth device manager. But, if you initiate bt session by the other software it will not help, cause coffee machine supports only one bt connection at once.

Arbuzov avatar Aug 12 '22 10:08 Arbuzov

yes I'll try with the new version, with the raspberry no problem at all...with the MAC it seems as if it made two connections, one when I add the integration to HA and one when I try to use it and when I try to use it it does not find it because it is already used. (obviously when I try with the mac I turn off the raspberry)

bubez81 avatar Aug 12 '22 10:08 bubez81

in fact if I try to scan without adding the integration I can see from the Mac the Characteristics : python3 service_explorer.py INFO:__main__:Connected: True INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

then if I add the integration a can't perform the scan anymore....from THE SAME MACHINE...it's very strange....

bubez81 avatar Aug 12 '22 11:08 bubez81

however I noticed that there is no discovery by HA and I have to add the machine by hand, maybe that's the problem

bubez81 avatar Aug 12 '22 12:08 bubez81

however I noticed that there is no discovery by HA and I have to add the machine by hand, maybe that's the problem

Yes, that`s a next feature in this project. Autodiscovery and status parsing.

Arbuzov avatar Aug 24 '22 21:08 Arbuzov

maybe this will solve the problem

bubez81 avatar Aug 25 '22 07:08 bubez81

nothing...it's like it makes two connections on macOS...can't understand...it's a bleak and coreBluetooth problem...on the raspberry no issues

bubez81 avatar Sep 07 '22 07:09 bubez81

On my experience bleak is a little bit raw. I got some issues then started bleak in the Docker HA. Try to exec this in your environment:

import asyncio
import binascii
import uuid
from bleak import BleakClient, BleakScanner
from bleak.exc import BleakError

MAC = "00:A0:50:82:75:CA"
NAME_CHARACTERISTIC = '00002A00-0000-1000-8000-00805F9B34FB'
GENERAL_SERVICE = '00001801-0000-1000-8000-00805f9b34fb'

async def main(ble_address: str):
    device = await BleakScanner.find_device_by_address(ble_address, timeout=20.0)
    async with BleakClient(device) as client:
        services = await client.get_services()
        print("Services:")
        for service in services:
            print(service)
        value = bytes(await client.read_gatt_char(uuid.UUID(NAME_CHARACTERISTIC))).decode('utf-8')
        print(value)

asyncio.run(main(MAC))

if got an issue submit it to the bleak project

Arbuzov avatar Sep 10 '22 11:09 Arbuzov

ok...no sense: (homeassistant) michele@perlhof  ~  python3 service_explorer.py INFO:__main__:Connected: True INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

but

(homeassistant) michele@perlhof  ~  python3 provadimamica.py Services: 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown Traceback (most recent call last): File "/Users/michele/provadimamica.py", line 21, in <module> asyncio.run(main(MAC)) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete return future.result() File "/Users/michele/provadimamica.py", line 18, in main value = bytes(await client.read_gatt_char(uuid.UUID(NAME_CHARACTERISTIC))).decode('utf-8') File "/opt/homeassistant/lib/python3.10/site-packages/bleak/backends/corebluetooth/client.py", line 262, in read_gatt_char raise BleakError("Characteristic {} was not found!".format(char_specifier)) bleak.exc.BleakError: Characteristic 00002a00-0000-1000-8000-00805f9b34fb was not found!

bubez81 avatar Sep 10 '22 17:09 bubez81

I think there is a correlation here https://github.com/hbldh/bleak/issues/1189#issuecomment-1370045978

bubez81 avatar Jan 04 '23 20:01 bubez81

Was this solved, @bubez81? I think BLE support on macOS with HA is not great generally (not specific to this plug-in).

codyc1515 avatar Oct 24 '23 19:10 codyc1515

Solved with an esp32 😂

bubez81 avatar Oct 24 '23 19:10 bubez81

Great - same here. Can you please close the ticket?

codyc1515 avatar Oct 24 '23 20:10 codyc1515

Not sure if it's right to close the thicket...I have to try whitout the esp32

bubez81 avatar Oct 25 '23 13:10 bubez81