Drakulix / googlehome

Google Home Integration for Home-Assistant
Apache License 2.0
29 stars 3 forks source link

decode.py get grouped or sorted by home. #4

Closed fmieres closed 4 years ago

fmieres commented 4 years ago

hey, your decode.py is magical. Works excellently. I would like to know how to change it in order to get the tokens sorted by home .

this scripts gets all the rooms togather, even if they are in different homes.

I would like any recomendation so i can begin debugging it to also read and add home info like nickname or id . This info is present on the protofile if you open it as utf8. Or even add the chromecast uuid if possible.

Drakulix commented 4 years ago

Hey fmieres,

the decode.py is just a ported version of rithvikvibhu's decode.js and the rawproto library, which is used by decode.js.

You can use rawproto to decode your homegraph*.proto and try to understand it's structure. You should be able to extract the room and possible also the matching home easily.

fmieres commented 4 years ago

yes, thanks. Ive changed it a bit in order to get home name. I cant get any more information. Those uuid look alike, were not uuids so , no more info available.

Ive changed just a tiny fraction to get home name :

def decode_proto(buf: io.IOBase):
    data = get_data(buf)

    def _get_obj_by_key(l, key):
        return next(filter(lambda v: key in v, l))

    result = {}
    for val in data:
        try:
            if isinstance(val['2'], list):
                home = val['2'][1]['2']
                tokens = {}
                for val2 in val['2']:
                    try:
                        if isinstance(val2['7'], list):
                            device = next(iter(_get_obj_by_key(val2['7'], '18')['18'][0].values()))
                            token = _get_obj_by_key(val2['7'], '28')['28']
                            tokens[device] = { 'token': token }
                    except Exception as e:
                        # print(e)
                        pass
                result[home] = tokens
        except Exception as e:
            #print(e)
            pass
    return json.dumps(result)

So thanks for the tips.

Also thanks for putting this up, since javascript version didnt throw any tokens for me .