Bluetooth-Devices / bthome-ble

Parser for BTHome BLE devices
https://bthome.io/
MIT License
64 stars 11 forks source link

Request for RAW data type #89

Closed Patrick010 closed 9 months ago

Patrick010 commented 10 months ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

There is no data type available for the relaying of raw BLE data. All data types convert or alter the payload in some way or another. For my use case I need access to the hex payload as sent by the beacon. https://community.home-assistant.io/t/bthome-discussion-topic/504361/35 lead to the conclusion that a raw data type will solve this.

Describe the solution you'd like A clear and concise description of what you want to happen.

Add a RAW data type for the relaying of raw BLE data with a length of, say, 24 characters (BLE payloads can become very long, very easy)

Additional context Add any other context or screenshots about the feature request here.

Ernst79 commented 10 months ago

I propose we use the same variable length as for text sensors, not a fixed 24 char length. by using the first byte to indicate how long the byte string is.

Patrick010 commented 9 months ago

@Ernst79, any idea when the PR will be merged?

Ernst79 commented 9 months ago

I was waiting for a review of bdraco, but I think he missed the request. I’ll ask on discord

Patrick010 commented 9 months ago

Thanks

Patrick010 commented 9 months ago

I see it's merged, but docs need to be updated. Can I use 0x54 followed by a length byte, same as the text data type?

Ernst79 commented 9 months ago

Yep, but it isn't added to Home Assistant yet. This won't be before the November release of HA, as the October release is already in beta (no new features can be added now).

Patrick010 commented 9 months ago

That's unfortunate, I'll have to be patient then. But great that it has been implemented. Thanks once more :)

Ernst79 commented 9 months ago

Docs have been updated now, btw.

Patrick010 commented 9 months ago

Can I manually install this in HA? I tried pip install, but type 0x54 isnt recognised.

Ernst79 commented 9 months ago

Normally, you can copy the homeassistant/components/bthome folder to /config/custom_components/bthome, and than modify manifest.json. A custom component with the same name overrules the built in one. After a restart, it should update the requirements from the manifest.json. But it has been a while since I did this.

Patrick010 commented 9 months ago

Tried this, but doesnt work. I've modified the .json and set "requirements": ["bthome-ble==3.2.0"] I also had to set a version since this is mandatory for custom components, so I added "version": "3.2.0", No idea if this correct or if anything else must be done. Even though it is a highly educational exercise for me, I can imagine that you dont feel like solving this. So I'll have to wait for the next HA update ;)

Ernst79 commented 9 months ago

Ah, sorry, you have to add it to sensor.py as well. Add the following to the SEnSOR_DESCRIPTIONS.

    # Raw (-)
    (BTHomeExtendedSensorDeviceClass.RAW, None): SensorEntityDescription(
        key=str(BTHomeExtendedSensorDeviceClass.RAW),
    ),

I have the PR ready locally, but my development environment is a bit messed up. Have to fix that first

adding the version is ok, that is mandatory, yes. The number doesn’t matter, can be anything

Patrick010 commented 9 months ago

That would explain the Unexpected error updating FF:FF:FF:FF:00:01 data: (<ExtendedSensorDeviceClass.RAW: 'raw'>, None) Added it to sensor.py and yes! it works 👍

image

Ernst79 commented 9 months ago

The PR to add bthome 3.2.0 for Home Assistant has been merged into development. So, it should be available in HA 2023.11. I'm closing this issue here.