本帖最后由 zhuangzi105 于 2019-4-23 11:22 编辑
授权成功之后,模拟测试时,home assistant可以收到信息。不过会报错
2019-04-23 10:14:08 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.hiwifi_router_bytes_received, old_state=<state sensor.hiwifi_router_bytes_received=2079803392; unit_of_measurement=bytes, friendly_name=HiWiFi router bytes received, icon=mdi:server-network @ 2019-04-23T10:13:37.189418+08:00>, new_state=<state sensor.hiwifi_router_bytes_received=2079885312; unit_of_measurement=bytes, friendly_name=HiWiFi router bytes received, icon=mdi:server-network @ 2019-04-23T10:14:08.162570+08:00>>
2019-04-23 10:14:08 DEBUG (SyncWorker_15) [miio.device] 10.1.1.107:54321 (ts: 1970-01-02 12:56:15, id: 254) << {'result': ['off', 100, 'off', 'on', 100, 'off', 2, 'on', 0], 'id': 254}
2019-04-23 10:14:08 DEBUG (MainThread) [homeassistant.components.xiaomi_miio.light] Got new state: <PhilipsEyecareStatus power=off, brightness=100, ambient=True, ambient_brightness=100, eyecare=False, scene=2, reminder=False, smart_night_light=True, delay_off_countdown=0>
2019-04-23 10:14:08 DEBUG (SyncWorker_1) [miio.device] 10.1.1.107:54321 (ts: 1970-01-02 12:56:15, id: 253) << {'result': ['off', 100, 'off', 'on', 100, 'off', 2, 'on', 0], 'id': 253}
2019-04-23 10:14:08 DEBUG (MainThread) [homeassistant.components.xiaomi_miio.light] Got new state: <PhilipsEyecareStatus power=off, brightness=100, ambient=True, ambient_brightness=100, eyecare=False, scene=2, reminder=False, smart_night_light=True, delay_off_countdown=0>
2019-04-23 10:14:08 DEBUG (SyncWorker_11) [xiaomi_gateway] _send_cmd resp << {'cmd': 'read_ack', 'model': 'plug', 'sid': '158d0001dc5b0a', 'short_id': 18718, 'data': '{"voltage":3600,"status":"on","inuse":"0","power_consumed":"19480","load_power":"0.00"}'}
2019-04-23 10:14:08 DEBUG (SyncWorker_11) [xiaomi_gateway] read_ack << {'cmd': 'read_ack', 'model': 'plug', 'sid': '158d0001dc5b0a', 'short_id': 18718, 'data': '{"voltage":3600,"status":"on","inuse":"0","power_consumed":"19480","load_power":"0.00"}'}
2019-04-23 10:14:08 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0001dc5b0a: on>: {'voltage': 3600, 'status': 'on', 'inuse': '0', 'power_consumed': '19480', 'load_power': '0.00'}
2019-04-23 10:14:10 DEBUG (MainThread) [homeassistant.components.http.view] Serving /dueros_gate to 10.202.112.18 (auth: False)
2019-04-23 10:14:12 ERROR (MainThread) [custom_components.dueros] Traceback (most recent call last):
File "/config/custom_components/dueros.py", line 97, in post
response = await handleRequest(data)
File "/config/custom_components/dueros.py", line 120, in handleRequest
header = data['header']
KeyError: 'header'
在对应位置输出data的内容。发现data中没有header关键字。
async def handleRequest(data):
"""Handle request"""
_LOGGER.info(json.dumps(data))
header = data['header']
payload = data['payload']
data内容:
[custom_components.dueros]{"version": "v2.0","session": {"new":true, "sessionId":"2bf27c64-3d48-4ad2-8980-dddec189cf0a"},"context": {"System":{"user": {"userId":"9009298", "accessToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI5NGVhNzhlNjMzNzA8YjZiM2ZkNTM3NjQxYWQ5ZCIsImlhdCI6MTU1NTk4NjI3MiwiZXhwIjoxNTU2NjM0MjcyfQ.Nc2_eb2cKP5PFSNbf7uHcaGAs4PNJUisoY37DOa6EY","userInfo": {"account":{}}}, "application": {"applicationId":"917baa19-c612-9a17-9f39-d48df768df061"},"device": {"deviceId":"77be6f9f9aa83634f7e08bef40a124","supportedInterfaces": {"VoiceInput":{}, "VoiceOutput": {}, "AudioPlayer":{}, "VideoPlayer": {"preferedBitrate":"", "preferedWidth":0, "preferedHeight":0}}, "TVControl":{"controlType": "DCSControl","controlStatus": 0},"originalDeviceSerialNumber": "91206/1B3F160053140"},"apiAccessToken": "+OKmo/6o7dAPXT/5IGAzhEOS/apTcnZzY+C5rVuWJNAQt+gVH+giijfT8q0MWcpXI/CSLCJnWY3D1/Cz7OWcWD1R9hFMF0hnyge8cFRqwnX6lrKixur3uYzUYr029vvnFt/bRYdXvPbf+cTAFh6gzKDlF/ZgYGXIOPWMlCQ/sxyskERNSpq9pSD2iWhBSEMYT9YgnpiEGYcoGinrFUV5YEXhT3w+eeJqcLvaXqBoZ2o74yLFKiGys+037gdyx1UGFUX1siwY0tErNl/fQSrEnQV+p+ac+2QFfONfRAzAlybPAF9l6g8/mINQywPFL6n27R0Q+HJIzlSp5Z5k6V+zGwVjmKUoS2+Fcjk+Jzag5CT1gwdX97rvoyH4/x+XQhZawGpUnWhGEVKMfkPOQ==","apiEndPoint": "https://xiaodu.baidu.com","avaliableApplicationIds": ["aries_general","audio_music", "audio_unicast","audio_live", "audio_news","speaker_hardware", "duer_weather","sysprofile_service", "ai.dueros.bot.vocal_joke","ai.dueros.bot.alarm", "ai.dueros.bot.timer","ai.dueros.bot.smarthome", "doudi_server","ai.dueros.bot.audio_museum", "ai.dueros.bot.puzzle","ai.dueros.bot.faq_didp", "audio_music_children","483c3ee4-0e37-e05a-0d95-efe1dc96dc44","audio_classic", "d4106ab2-4374-816e-322a-341fcc625e4b","fed5e9a3-32e0-a87c-9571-9c7d296b919d","ai.dueros.bot.oss", "0b082db2-fc64-6396-5744-1ffd84e83a32","409e98fd-e144-c39a-6c35-75d261683834","ai.dueros.ext.rus", "6402fc3a-7825-3147-b52e-c25911b6d03c","ca4585e2-3cc2-8605-4062-08f9931304db","ext_timer"]}, "AudioPlayer":{"token": "1","offsetInMilliSeconds": 1520773,"playActivity": "STOPPED","applicationId": "audio_live"},"SettingsState": {"childFriendlyMode":false}}, "request":{"type": "LaunchRequest","requestId": "c4349bc0-6574-18e9-b28b-d9f75472d902_DCSxukbcd8871_3#1_0","timestamp": "155508782","dialogRequestId": "45c90f3f-f9be-4937-9d20-6a6c9cbd2dc2"}}
|