aiohomekit icon indicating copy to clipboard operation
aiohomekit copied to clipboard

Simplify TLV parsing

Open Jc2k opened this issue 4 years ago • 1 comments

The TLV parsing we have adopted from upstream returns a list of tuples. This means you can't do:

result[TLV.kTLVType_State]

You have to instead order the results and do:

if result[0] == TLV.kTLVType_State and....

This is working, so I have been reluctant to change it. But it has hard for new users (and me) to follow.

Upstream has now factored TLV handling out into a seperate library here. However it did introduce a few regressions. It is an improvement because you can declare the types and structure of the expected data a bit better, but the result returned is still not very ergonomic.

Ultimately i'd like to parse a TLV into a structure that can be checked with a linter, rather that returning a list or a dict.

Jc2k avatar Aug 03 '20 07:08 Jc2k

Release 0.2.51 contains a TLVStruct helper that can help with translating to and from a python 3.7 dataclass. It's intended for use with characterings like .streaming-status or .supported-rtp-configuration. It needs work to extend it for nested structs like .supported-audio-configuration.

For pairing related TLV parsing it would ideally do something a bit like a rust enum as the returned records are very different between M1 and M2 etc.

Jc2k avatar Aug 26 '20 15:08 Jc2k