Update hass_get_state.py

支持查询色温、颜色
This commit is contained in:
c1pher 2025-04-08 21:45:29 +08:00 committed by GitHub
parent 6fd63870f0
commit c609b103b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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}"