Skip to content

Commit

Permalink
Support receive LAN key for lumi.gateway.v3
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jan 16, 2021
1 parent 6d133ca commit c7b194a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/xiaomi_gateway3/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ async def async_step_cloud(self, user_input=None):
f"MAC: {device['mac']}\n"
f"Token: {device['token']}"
)
if device['model'] == 'lumi.gateway.v3':
device_info += "\nLAN key: " + gateway3.get_lan_key(device)

elif not self.hass.data[DOMAIN].get('devices'):
device_info = "No devices in account"
else:
Expand Down
17 changes: 17 additions & 0 deletions custom_components/xiaomi_gateway3/core/gateway3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import logging
import random
import re
import socket
import string
import time
from threading import Thread
from typing import Optional
Expand Down Expand Up @@ -1117,3 +1119,18 @@ def is_gw3(host: str, token: str) -> Optional[str]:
return 'wrong_model'

return None


def get_lan_key(device: dict):
device = SyncmiIO(device['localip'], device['token'])
resp = device.send('get_lumi_dpf_aes_key')
if resp is None:
return "Can't connect to gateway"
if len(resp[0]) == 16:
return resp[0]
key = ''.join(random.choice(string.ascii_lowercase + string.digits)
for _ in range(16))
resp = device.send('set_lumi_dpf_aes_key', [key])
if resp[0] == 'ok':
return key
return "Can't update gateway key"

0 comments on commit c7b194a

Please sign in to comment.