From c609b103b744833202648625a7e34f8a1c74feb4 Mon Sep 17 00:00:00 2001 From: c1pher Date: Tue, 8 Apr 2025 21:45:29 +0800 Subject: [PATCH] Update hass_get_state.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持查询色温、颜色 --- .../plugins_func/functions/hass_get_state.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 415f35c6a..5ad9b0305 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": { @@ -51,6 +51,14 @@ 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'] + '' + 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']+' ' + return responsetext + #return response.json()['attributes'] + #response.attributes + else: return f"切换失败,错误码: {response.status_code}"