Bluetooth-Devices / bthome-ble

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

fix: move cipher to decryption function #82

Closed Ernst79 closed 1 year ago

Ernst79 commented 1 year ago

HA was failing in the config flow tests with 2.13.0 on this part of the code when using encryption

assert self.cipher is not None  # nosec

I move the cipher part down to the decryption function. Not sure is this is the best way to solve it, but the HA tests do work with this change.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.10 :warning:

Comparison is base (e6c192c) 77.66% compared to head (93c8baa) 77.56%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #82 +/- ## ========================================== - Coverage 77.66% 77.56% -0.10% ========================================== Files 6 6 Lines 479 477 -2 Branches 72 71 -1 ========================================== - Hits 372 370 -2 Misses 83 83 Partials 24 24 ``` | [Impacted Files](https://app.codecov.io/gh/Bluetooth-Devices/bthome-ble/pull/82?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Bluetooth-Devices) | Coverage Δ | | |---|---|---| | [src/bthome\_ble/\_\_init\_\_.py](https://app.codecov.io/gh/Bluetooth-Devices/bthome-ble/pull/82?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Bluetooth-Devices#diff-c3JjL2J0aG9tZV9ibGUvX19pbml0X18ucHk=) | `100.00% <100.00%> (ø)` | | | [src/bthome\_ble/parser.py](https://app.codecov.io/gh/Bluetooth-Devices/bthome-ble/pull/82?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Bluetooth-Devices#diff-c3JjL2J0aG9tZV9ibGUvcGFyc2VyLnB5) | `83.49% <100.00%> (-0.11%)` | :arrow_down: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

bdraco commented 1 year ago

Is the bindkey getting set outside of init ?

bdraco commented 1 year ago

Ideally we don't want to recreate the object every time we decrypt a packet as it will likely be MUCH slower

bdraco commented 1 year ago

I fixed it in https://github.com/Bluetooth-Devices/bthome-ble/pull/83

Ernst79 commented 1 year ago

Ideally we don't want to recreate the object every time we decrypt a packet as it will likely be MUCH slower

Yes, that what I also thought, but couldn't think of a better solution. Thanks!