|
设备是通过易微联加进homeassistant 产生 switch.10000890的实体
1.由于版本更新快 这样的语句是否还有效2.易微联加进去的设备 是不是操作指令不一样
if self.execute_service(entity_id, url, port, headers, act):
if not has_execute:
self.say("设备执行成功", cache=True)
has_execute = True
else:
if not has_execute:
self.say("对不起,设备执行失败", cache=True)
has_execute = True
def execute_service(self, entity_id, url, port, headers, act):
p = json.dumps({"entity_id": entity_id})
domain = entity_id.split(".")[0]
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":
return True
else:
logger.error(format(request.status_code))
return False
|
|