def find_entity(self, entity, types):
if self.ssl:
req = get("%s/api/states" %
self.url, headers=self.headers, verify=self.verify)
else:
req = get("%s/api/states" % self.url, headers=self.headers)
if req.status_code == 200:
best_score = 0
best_entity = None
for state in req.json():
try:
if state['entity_id'].split(".")[0] in types:
score = fuzz.ratio(
entity,
state['attributes']['friendly_name'].lower())
if score > best_score:
best_score = score
best_entity = {
"id": state['entity_id'],
"dev_name": state['attributes']
['friendly_name'],
"state": state['state']}
except KeyError:
pass
return best_entity
#
# checking the entity attributes to be used in the response dialog.
#
评论列表
文章目录