[function]homeassistant操作能力增强 (#714)

* Update hass_get_state.py

支持查询色温、颜色

* Update hass_set_state.py

设置灯光颜色,色温

* 支持灯光色温颜色调整、查询

* 设置状态返回内容修正
This commit is contained in:
c1pher
2025-04-09 10:39:42 +08:00
committed by GitHub
parent 498542f8be
commit f4bd80b5f9
2 changed files with 40 additions and 7 deletions
@@ -11,7 +11,7 @@ hass_get_state_function_desc = {
"type": "function",
"function": {
"name": "hass_get_state",
"description": "获取homeassistant里设备的状态,包括灯光亮度,媒体播放器的音量,设备的暂停、继续操作",
"description": "获取homeassistant里设备的状态,包括查询灯光亮度、颜色、色温,媒体播放器的音量,设备的暂停、继续操作",
"parameters": {
"type": "object",
"properties": {
@@ -35,7 +35,7 @@ def hass_get_state(conn, entity_id=''):
conn.loop
)
ha_response = future.result()
return ActionResponse(action=Action.REQLLM, result="执行成功", response=ha_response)
return ActionResponse( Action.REQLLM, ha_response , None )
except Exception as e:
logger.bind(tag=TAG).error(f"处理设置属性意图错误: {e}")
@@ -51,6 +51,23 @@ async def handle_hass_get_state(conn, entity_id):
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()['state']
responsetext = '设备状态:' + response.json()['state'] + ' '
logger.bind(tag=TAG).info(f"api返回内容: {response.json()}")
if 'media_title' in response.json()['attributes']:
responsetext = responsetext+ '正在播放的是:'+str(response.json()['attributes']['media_title'])+' '
if 'volume_level' in response.json()['attributes']:
responsetext = responsetext+ '音量是:'+str(response.json()['attributes']['volume_level'])+' '
if 'color_temp_kelvin' in response.json()['attributes']:
responsetext = responsetext+ '色温是:'+str(response.json()['attributes']['color_temp_kelvin'])+' '
if 'rgb_color' in response.json()['attributes']:
responsetext = responsetext+ 'rgb颜色是:'+str(response.json()['attributes']['rgb_color'])+' '
if 'brightness' in response.json()['attributes']:
responsetext = responsetext+ '亮度是:'+str(response.json()['attributes']['brightness'])+' '
logger.bind(tag=TAG).info(f"查询返回内容: {responsetext}")
return responsetext
#return response.json()['attributes']
#response.attributes
else:
return f"切换失败,错误码: {response.status_code}"