mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
支持灯光色温颜色调整、查询
This commit is contained in:
parent
0c386c30c0
commit
ab2f996c7b
2 changed files with 29 additions and 8 deletions
|
|
@ -11,7 +11,7 @@ hass_get_state_function_desc = {
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "hass_get_state",
|
"name": "hass_get_state",
|
||||||
"description": "获取homeassistant里设备的状态,包括灯光亮度、颜色、色温,媒体播放器的音量,设备的暂停、继续操作",
|
"description": "获取homeassistant里设备的状态,包括查询灯光亮度、颜色、色温,媒体播放器的音量,设备的暂停、继续操作",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
@ -35,7 +35,7 @@ def hass_get_state(conn, entity_id=''):
|
||||||
conn.loop
|
conn.loop
|
||||||
)
|
)
|
||||||
ha_response = future.result()
|
ha_response = future.result()
|
||||||
return ActionResponse(action=Action.REQLLM, result="执行成功", response=ha_response)
|
return ActionResponse( Action.REQLLM, ha_response , None )
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.bind(tag=TAG).error(f"处理设置属性意图错误: {e}")
|
logger.bind(tag=TAG).error(f"处理设置属性意图错误: {e}")
|
||||||
|
|
||||||
|
|
@ -52,10 +52,19 @@ async def handle_hass_get_state(conn, entity_id):
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
responsetext = '设备状态:' + response.json()['state'] + ' '
|
responsetext = '设备状态:' + response.json()['state'] + ' '
|
||||||
if 'kelvin' in response.json()['attributes']:
|
logger.bind(tag=TAG).info(f"api返回内容: {response.json()}")
|
||||||
responsetext = responsetext+ '色温是:'+response.json()['attributes']['kelvin']+' '
|
|
||||||
if 'rgb_clolr' in response.json()['attributes']:
|
if 'media_title' in response.json()['attributes']:
|
||||||
responsetext = responsetext+ 'rgb颜色是:'+response.json()['attributes']['rgb_color']+' '
|
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 responsetext
|
||||||
#return response.json()['attributes']
|
#return response.json()['attributes']
|
||||||
#response.attributes
|
#response.attributes
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,16 @@ async def handle_hass_set_state(conn, entity_id, state):
|
||||||
action = 'turn_on'
|
action = 'turn_on'
|
||||||
arg = 'brightness_pct'
|
arg = 'brightness_pct'
|
||||||
value = state['input']
|
value = state['input']
|
||||||
|
elif state['type'] == 'set_color':
|
||||||
|
description = f"颜色已调整到{state['rgb_color']}"
|
||||||
|
action = 'turn_on'
|
||||||
|
arg = 'rgb_color'
|
||||||
|
value = state['rgb_color']
|
||||||
|
elif state['type'] == 'set_kelvin':
|
||||||
|
description = f"色温已调整到{state['input']}K"
|
||||||
|
action = 'turn_on'
|
||||||
|
arg = 'kelvin'
|
||||||
|
value = state['input']
|
||||||
elif state['type'] == 'volume_up':
|
elif state['type'] == 'volume_up':
|
||||||
description = "音量已调大"
|
description = "音量已调大"
|
||||||
action = state['type']
|
action = state['type']
|
||||||
|
|
@ -118,6 +128,8 @@ async def handle_hass_set_state(conn, entity_id, state):
|
||||||
action = state['type']
|
action = state['type']
|
||||||
arg = 'volume_level'
|
arg = 'volume_level'
|
||||||
value = state['input']
|
value = state['input']
|
||||||
|
if state['input'] >= 1:
|
||||||
|
value = state['input']/100
|
||||||
elif state['type'] == 'volume_mute':
|
elif state['type'] == 'volume_mute':
|
||||||
description = f"设备已静音"
|
description = f"设备已静音"
|
||||||
action = state['type']
|
action = state['type']
|
||||||
|
|
@ -156,7 +168,7 @@ async def handle_hass_set_state(conn, entity_id, state):
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
response = requests.post(url, headers=headers, json=data)
|
response = requests.post(url, headers=headers, json=data)
|
||||||
logger.bind(tag=TAG).info(f"设置状态:url:{url},return_code:{response.status_code}")
|
logger.bind(tag=TAG).info(f"设置状态:{description},url:{url},return_code:{response.status_code}")
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return description
|
return description
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue