cnk700i / havcs

Home Assistant Voice Control Skill
https://ljr.im/articles/plugins-havcs-edible-instructions/
Apache License 2.0
311 stars 97 forks source link

控制设备报错:UnboundLocalError: local variable 'entity_id' referenced before assignment #19

Closed killadm closed 4 years ago

killadm commented 4 years ago

<发现设备>命令提示无法找到设备,但是app中可以看到设备。 语音或通过app控制设备时插件报错。

设备:小度在家 ha版本:0.104.2 平台配置: 平台配置

configuration.yaml

havcs:
  platform:
    - dueros
    - jdwhale
  http:
    ha_url: https://xxx.xxxxx.com
    expire_in_hours: 24000

havcs.yaml

light.kitchen:
  havcs_device_name: 厨房灯
  havcs_zone: 厨房
  havcs_device_type: light
  havcs_actions: ['turn_on', 'turn_off', 'timing_turn_on', 'timing_turn_off']

havcs.reload

2020-01-22 11:07:51 INFO (MainThread) [custom_components.havcs] [service] ------------dueros 平台加载设备信息------------,
[{'entity_id': 'light.kitchen', 'device_type': 'LIGHT', 'device_name': '厨房灯', 'zone': '厨房', 'properties': [{'entity_id': 'light.kitchen', 'attribute': 'power_state'}], 'actions': ['turn_on', 'turn_off', 'timing_turn_on', 'timing_turn_off']}]

<发现设备>

2020-01-22 10:47:44 DEBUG (MainThread) [custom_components.havcs] [http] raw message: {"header":{"payloadVersion":"1","name":"DiscoverAppliancesRequest","namespace":"DuerOS.ConnectedHome.Discovery","messageId":"13742062af2741cfbf55c0f4375a16a8_DCS-10-201-43-32-8260-0122104742-2919622_0#1_0_Smarthome_5e27b7cfcd4285.79138016"},"payload":{"accessToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWFjZDQyZDY4MGY0ZTc2YWYzOTJkN2ZjY2NjNzg3MSIsImlhdCI6MTU3OTYxMjQxNiwiZXhwIjoxNTc5Njk4ODE2fQ.FJmy2S3dj537hAopgaDEWkYUlPp72Z0N3TchA1MaF_Y","openUid":"f0736c30e4d9ad9cacde4211323d80cc"}},
2020-01-22 10:47:44 DEBUG (MainThread) [custom_components.havcs] [http] -------- start handle task from http at 2020-01-22 10:47:44 --------,
2020-01-22 10:47:44 DEBUG (MainThread) [custom_components.havcs] [http] get access_token >>> eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWFjZDQyZDY4MGY0ZTc2YWYzOTJkN2ZjY2NjNzg3MSIsImlhdCI6MTU3OTYxMjQxNiwiZXhwIjoxNTc5Njk4ODE2fQ.FJmy2S3dj537hAopgaDEWkYUlPp72Z0N3TchA1MaF_Y <<<,
{'header': {'payloadVersion': '1', 'name': 'DiscoverAppliancesRequest', 'namespace': 'DuerOS.ConnectedHome.Discovery', 'messageId': '13742062af2741cfbf55c0f4375a16a8_DCS-10-201-43-32-8260-0122104742-2919622_0#1_0_Smarthome_5e27b7cfcd4285.79138016'}, 'payload': {'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWFjZDQyZDY4MGY0ZTc2YWYzOTJkN2ZjY2NjNzg3MSIsImlhdCI6MTU3OTYxMjQxNiwiZXhwIjoxNTc5Njk4ODE2fQ.FJmy2S3dj537hAopgaDEWkYUlPp72Z0N3TchA1MaF_Y', 'openUid': 'f0736c30e4d9ad9cacde4211323d80cc'}},
2020-01-22 10:47:44 DEBUG (MainThread) [custom_components.havcs] [http] validate access_token, get refresh_token(id = 0aacd42d680f4e76af392d7fcccc7871),
2020-01-22 10:47:44 INFO (MainThread) [custom_components.havcs.dueros] [dueros] Handle Request:,
2020-01-22 10:47:44 INFO (MainThread) [custom_components.havcs.dueros] [dueros] Respnose:,
{'header': {'payloadVersion': '1', 'name': 'DiscoverAppliancesResponse', 'namespace': 'DuerOS.ConnectedHome.Discovery', 'messageId': '13742062af2741cfbf55c0f4375a16a8_DCS-10-201-43-32-8260-0122104742-2919622_0#1_0_Smarthome_5e27b7cfcd4285.79138016'}, 'payload': {'discoveredAppliances': [{'applianceId': 'light.kitchen', 'friendlyName': '厨房灯', 'friendlyDescription': '厨房灯', 'additionalApplianceDetails': [], 'applianceTypes': ['LIGHT'], 'isReachable': True, 'manufacturerName': 'HomeAssistant', 'modelName': 'HomeAssistant', 'version': '1.0', 'actions': ['turnOff', 'turnOn', 'timingTurnOff', 'timingTurnOn'], 'attributes': [{'name': 'turnOnState', 'value': 'OFF', 'scale': '', 'timestampOfSample': 1579661264, 'uncertaintyInMilliseconds': 1000, 'legalValue': '(ON, OFF)'}]}]}},
2020-01-22 10:47:44 DEBUG (MainThread) [custom_components.havcs] [http] -------- http task finish at 2020-01-22 10:47:44, running time: 0.014139s --------

<打开客厅灯>

2020-01-22 10:53:34 DEBUG (MainThread) [custom_components.havcs] [http] -------- start handle task from http at 2020-01-22 10:53:34 --------,
2020-01-22 10:53:34 DEBUG (MainThread) [custom_components.havcs] [http] raw message: {"header":{"payloadVersion":"1","messageId":"7cecfdc7128141c4976ee90f41bd95df_DCS-10-201-42-32-8230-0122105333-3060678_0#1_0_Smarthome_5e27b92e918925.76802714","name":"TurnOnRequest","namespace":"DuerOS.ConnectedHome.Control"},"payload":{"accessToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWFjZDQyZDY4MGY0ZTc2YWYzOTJkN2ZjY2NjNzg3MSIsImlhdCI6MTU3OTYxMjQxNiwiZXhwIjoxNTc5Njk4ODE2fQ.FJmy2S3dj537hAopgaDEWkYUlPp72Z0N3TchA1MaF_Y","appliance":{"additionalApplianceDetails":{},"applianceId":"light.kitchen"}}},
2020-01-22 10:53:34 DEBUG (MainThread) [custom_components.havcs] [http] get access_token >>> eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWFjZDQyZDY4MGY0ZTc2YWYzOTJkN2ZjY2NjNzg3MSIsImlhdCI6MTU3OTYxMjQxNiwiZXhwIjoxNTc5Njk4ODE2fQ.FJmy2S3dj537hAopgaDEWkYUlPp72Z0N3TchA1MaF_Y <<<,
2020-01-22 10:53:34 DEBUG (MainThread) [custom_components.havcs] [http] validate access_token, get refresh_token(id = 0aacd42d680f4e76af392d7fcccc7871),
2020-01-22 10:53:34 INFO (MainThread) [custom_components.havcs.dueros] [dueros] Handle Request:,
{'header': {'payloadVersion': '1', 'messageId': '7cecfdc7128141c4976ee90f41bd95df_DCS-10-201-42-32-8230-0122105333-3060678_0#1_0_Smarthome_5e27b92e918925.76802714', 'name': 'TurnOnRequest', 'namespace': 'DuerOS.ConnectedHome.Control'}, 'payload': {'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWFjZDQyZDY4MGY0ZTc2YWYzOTJkN2ZjY2NjNzg3MSIsImlhdCI6MTU3OTYxMjQxNiwiZXhwIjoxNTc5Njk4ODE2fQ.FJmy2S3dj537hAopgaDEWkYUlPp72Z0N3TchA1MaF_Y', 'appliance': {'additionalApplianceDetails': {}, 'applianceId': 'light.kitchen'}}},
2020-01-22 10:53:34 ERROR (MainThread) [custom_components.havcs] [http] handle fail: Traceback (most recent call last):,
  File "/config/custom_components/havcs/__init__.py", line 657, in post,
    response = await HANDLER[platform].handleRequest(json.loads(data), refresh_token),
  File "/config/custom_components/havcs/dueros.py", line 196, in handleRequest,
    err_result, properties = await self.process_control_command(data),
  File "/config/custom_components/havcs/helper.py", line 67, in process_control_command,
    entity_id = self._decrypt_device_id(device_id),
  File "/config/custom_components/havcs/dueros.py", line 327, in _decrypt_device_id,
    return decrypt_device_id(device_id),
  File "/config/custom_components/havcs/util.py", line 64, in decrypt_device_id,
    return entity_id,
UnboundLocalError: local variable 'entity_id' referenced before assignment,
,
2020-01-22 10:53:34 DEBUG (MainThread) [custom_components.havcs] [http] -------- http task finish at 2020-01-22 10:53:34, running time: 0.0263s --------

平台模拟测试请求和响应 平台模拟测试请求和响应-发现设备.txt 平台模拟测试请求和响应-控制设备.txt