lucavb / homebridge-esphome-ts

This plugin integrates your esphome devices into HomeKit!
GNU General Public License v3.0
49 stars 17 forks source link

Support for API encryption #506

Open runestone74 opened 1 year ago

runestone74 commented 1 year ago

Hi, the standard ESP Home config is using API encryption for Home Assistant support. Is this supported as well? I only found info for password.

# Enable Home Assistant API
api:
  encryption:
    key: "qWHsO5CS0tz2Y4ZGYMicOAyFGIrWlu3wVHm8HTEIBms="
lucavb commented 1 year ago

Uff that is the first I am hearing of this. I cannot really say whether I will be able to work on this since I am currently not having any ESP devices in use :/

samhunt commented 1 year ago

Dang, I was quite excited to try out your package once I found it, but lack of encrytion key support is a bit of a deal beaker. I think the use of an API passwors been deprecated for a while. HA has given warnings if your using ESPHome with a password since 2023.2 https://esphome.io/components/api.html#configuration-variables

samhunt commented 1 year ago

First off @lucavb , thanks heaps for this package, it was almost exactly what I was looking for, but due to the fact that Encryption wasn't quite there I started digging into how hard it would be to add (note, I am not a TS/JS dev so I have been learning all of that at the same time).

It turns out that adding encryption ended up being quite a rabbit hole. @lucavb i've created a draft PR if you wanted to improve upon it https://github.com/lucavb/esphome-ts/pull/866/ which has bare bones of adding the NoiseClient, but i've left a large amount of comments in it due to the fact that I could never complete it.

I stopped because there were far too many other inconsistencies in the way in which the implementation worked, and would require an architectural rewrite which I am unable to complete due to the fact that I am quite a novice at JS/TS. Below is the comment that I put out on the PR.

This was down to the nature of how parseListResponse would frequently drop entities (or not all entities would be received) before ListEntitiesDoneResponse was received. Once ListEntitiesDoneResponse was acknowledged no further entities would be added to the list, and therefore were never able to be added to HomeBridge. Due to this I instead switched out this implementation of the Esphome Native API esphome-native-api which already had encryption, and far more Entities implemented.

I have a working branch with Encryption using the esphome-native-api which has been working on my local HB instance, if anyone wants to take a look at it https://github.com/samhunt/homebridge-esphome-ts/pull/1

for now the following commands can make this appear in HB

git clone https://github.com/samhunt/homebridge-esphome-ts
cd homebridge-esphome-ts
npm install esphome-ts
npm install
npm link