| if 'dingdang' in attributes.keys(): |
| dingdang = attributes["dingdang"] |
| if isinstance(dingdang, list): |
| if text in dingdang: |
| try: |
| measurement = attributes["unit_of_measurement"] |
| except Exception as e: |
| pass |
| if 'measurement' in locals().keys(): |
| text = text + "状态是" + state + measurement |
| mic.say(text, cache=True) |
| else: |
| text = text + "状态是" + state |
| mic.say(text, cache=True) |
| break |
| elif isinstance(dingdang, dict): |
| if text in dingdang.keys(): |
| if isinstance(text, bytes): |
| text = text.decode('utf8') |
| try: |
| act = dingdang[text] |
| p = json.dumps({"entity_id": device["entity_id"]}) |
| s = "/api/services/" + domain + "/" |
| url_s = url + ":" + port + s + act |
| request = requests.post(url_s, headers=headers, data=p) |
| if format(request.status_code) == "200" or \ |
| format(request.status_code) == "201": |
| mic.say(u"执行成功", cache=True) |
| else: |
| mic.say(u"对不起,执行失败", cache=True) |
| print(format(request.status_code)) |
| except Exception as e: |
| pass |
| break |
| else: |
| mic.say(u"对不起,指令不存在", cache=True) |
| |
| |
| def isValid(text): |
| return any(word in text for word in [u"开启家庭助手", |
| u"开启助手", u"打开家庭助手", u"打开助手", |
| u"家庭助手", u"帮我"]) |