#Thread datastore add via service call
1 messages · Page 1 of 1 (latest)
Starting another thread about Thread because we all are big fans of Thread threads
Would the service call not go through async_add_dataset instead of direct to async_add? https://github.com/home-assistant/core/blob/dev/homeassistant/components/thread/dataset_store.py#L156
Oh I can literally just reference the websocket API, duh
yeah, if this was a service call you should totally just call the wrapper
Any preference on whether I hardcode the "source" to "service_call" or similar, or make it user-changeable?
hard code it, i think if this ends up upstream its probs going to be turned into a WS API and added to the thread panel
at which point it will probably be "user"
I mean all I'm really doing is adding services.yaml and an async_register_admin_service call. The WS API call already exists
Oh so this doesn’t even require a PR? It’s just some fun yaml stuff? That’s awesome
no no, there is code, just not much
So is there a way to directly async_register_admin_service to call dataset_store.async_add_dataset without making basically a shim that takes in a ServiceCall object, extracts the parameters from it, and calls that function?
The register service call says it accepts an awaitable function if I'm reading the type annotation correctly. Still not used to that feature of py3k
Yeah I can't grok that right now for some reason, so shim it is
slick! happy to test if you have some code to send over
do you have to enter the TLV? still not sure how to generate that from the base info
You do have to enter the TLV. Another guy also just asked for a script I made to pack Thread info into TLV (which I also only lightly tested lol) so lemme find that too
You'll need to modify the python files for the thread component, which is going to vary based on how you have HA running
Another guy also just asked for a script I made to pack
I think that ws me haha
Oh it was
🙈
thanks! is the channel not necessary?
Shouldn't be. Thread spec says it'll search across channels, at least during the commissioning. I don't think it'll find a new channel after it has already joined, though. I ran into that issue. It seems to just start up the Thread network on the channel it previously knew.
hm so maybe worth adding the channel to be safe?
Meh, KISS. If it works as it then all the better
You'll be the first one to try all this together
So if it doesn't we'll go from there
I'm grabbing a bulb to test with myself
nice - im gonna just do a custom integraiton instead of messing with the actual python code
hm having issues applying the patch - did you base off of dev / 2023.3.b1 ?
You know we could just make a script that calls the web socket api outside of HA then you don’t need to patch HA
just manually applied the patch and uploaded as a custom-component
I was considering that but I had already started this lol
And it'd be nice to get it upstream
my PAN was only 3-digits so I think I need to pad it with a 0?
Yup
extpanid should be 8
I mean yeah just look at the sample data
I also updated that gist to add a delete service since I'm playing around
there might be something missing in your gist?
the new one includes stuff for deleting in services.yaml, but the old one didn’t include anything for adding
yeah i see that in the init.py but no corresponding line in services.yaml
oh huh it got cut off
yeah no wories haha was confused why it wasn’t showing in my services, but your delete stuff gave me the hint 🙂
fixd
Although the channel /shouldn't/ be required, I think HA is expecting either it or some other data:
AttributeError: 'NoneType' object has no attribute 'to_bytes'
Oh yep decoded.channel.to_bytes(1, byteorder="little")),
Now to find the Thread whitepaper that had the TLV format...
I think the parser code is here: https://github.com/home-assistant-libs/python-otbr-api/blob/main/python_otbr_api/tlv_parser.py
channel seems to be 0
hm. that parser allows for arbitrary length of each field. i feel like that wasn't the case with OTBR/reference Thread
hm this spec shows _SIZE constants for everything except channel: https://openthread.io/reference/group/api-operational-dataset#otdatasetgetactive
but they’re also not lining up with your python script?
(but maybe its a bytes vs hex difference?)
Are they not? ExtPanID is 8, Key is 0x10 = 16
Network name is calculated
typedef uint32_t otChannelMask
oh i think i was just doing the conversion wrong, sorry!
Updated gist should work
My actual OTBR is giving me 00000b for channel 11 though. Wat
I think it might be working now, because my OTBR topology page is having a stroke
Which is what it usually does when a new device is joining
It worked!
Aw no reaction gifs
hahaha sorry was grabbing lunch!
this is awesome
smart blinds are provisioned on thread now, awesome!
Woo!
I’ll ping the guys working on the thread panel about this and see if we can get something added to there
Feels like you could roll in the python tlv script too - maybe as a separate service with multiple params
What blinds btw?
smartwings nano - got in on the indigogo earlier
And using homekit controller?
yup
And smart things br?
First time hkc used with those blinds and that BR, so trying to keep track
yup
I paired the blinds with HA via Bluetooth first as a homekit device, plugged in my old SmartThings Hub v3 and got it updated to the latest matter-compatible firmware (which includes a Thread BR), used @distant seal ’s cool stuff to import my smartthings thread credentials into HA, and then provisioned the blinds onto the thread network!
not sure how this all will shake out long-term if i get other thread border routers, but working for now 🙂
Think it's worth me trying to get that PR in, or is the UI gonna be preferred?
Depends!
If they think it’s too advanced they might not want it in Ui
I think it’s a good fit tho
Raw TLV in the UI is probably a no-go, but a simple "Enter your Network/Key/etc." would be pretty friendly
Yeah
just need to make it more user-friendly with things like padding the PAN if it isn’t 4-digits, doublechecking lengths, etc
He thinks it already exists isn’t the Ui but I can’t find it
And here I spent all that time writing 5 lines of code! :p
thank you for your service!