diff --git a/main/xiaozhi-server/plugins_func/functions/hass_get_state.py b/main/xiaozhi-server/plugins_func/functions/hass_get_state.py index 5ad9b0305..5ce511eb2 100644 --- a/main/xiaozhi-server/plugins_func/functions/hass_get_state.py +++ b/main/xiaozhi-server/plugins_func/functions/hass_get_state.py @@ -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,11 +51,20 @@ async def handle_hass_get_state(conn, entity_id): } response = requests.get(url, headers=headers) if response.status_code == 200: - responsetext = '设备状态:' + response.json()['state'] + '' - if 'kelvin' in response.json()['attributes']: - responsetext = responsetext+ '色温是:'+response.json()['attributes']['kelvin']+' ' - if 'rgb_clolr' in response.json()['attributes']: - responsetext = responsetext+ 'rgb颜色是:'+response.json()['attributes']['rgb_color']+' ' + 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 diff --git a/main/xiaozhi-server/plugins_func/functions/hass_set_state.py b/main/xiaozhi-server/plugins_func/functions/hass_set_state.py index 3e380144a..5856efc8a 100644 --- a/main/xiaozhi-server/plugins_func/functions/hass_set_state.py +++ b/main/xiaozhi-server/plugins_func/functions/hass_set_state.py @@ -107,6 +107,16 @@ async def handle_hass_set_state(conn, entity_id, state): action = 'turn_on' arg = 'brightness_pct' 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': description = "音量已调大" action = state['type'] @@ -118,6 +128,8 @@ async def handle_hass_set_state(conn, entity_id, state): action = state['type'] arg = 'volume_level' value = state['input'] + if state['input'] >= 1: + value = state['input']/100 elif state['type'] == 'volume_mute': description = f"设备已静音" action = state['type'] @@ -156,7 +168,7 @@ async def handle_hass_set_state(conn, entity_id, state): "Content-Type": "application/json" } 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: return description else: