Merge pull request #3545 from xinnan-tech/py-ha-state
Some checks failed
Tests / Java (manager-api) (push) Failing after 2m31s
Tests / Vue (manager-web) (push) Successful in 3m34s
Tests / Python (xiaozhi-server) (push) Successful in 30m21s

Py ha state
This commit is contained in:
wengzh 2026-11-09 14:43:00 +08:00 committed by GitHub
commit 4b1a54a41c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -121,13 +121,10 @@ async def handle_hass_get_state(conn: "ConnectionHandler", entity_id):
+ str(response.json()["attributes"]["media_title"]) + str(response.json()["attributes"]["media_title"])
+ " " + " "
) )
if "volume_level" in response.json()["attributes"]: volume_level = response.json()["attributes"].get("volume_level")
responsetext = ( if isinstance(volume_level, (int, float)):
responsetext # volume_level 量程 0~1,换算成百分比(同 volume_set 的 1~100)
+ "音量是:" responsetext = responsetext + "音量是:" + f"{round(volume_level * 100)}%" + " "
+ str(response.json()["attributes"]["volume_level"])
+ " "
)
if "color_temp_kelvin" in response.json()["attributes"]: if "color_temp_kelvin" in response.json()["attributes"]:
responsetext = ( responsetext = (
responsetext responsetext
@ -142,13 +139,11 @@ async def handle_hass_get_state(conn: "ConnectionHandler", entity_id):
+ str(response.json()["attributes"]["rgb_color"]) + str(response.json()["attributes"]["rgb_color"])
+ " " + " "
) )
if "brightness" in response.json()["attributes"]: brightness = response.json()["attributes"].get("brightness")
responsetext = ( if isinstance(brightness, (int, float)):
responsetext # brightness 量程 0~255,换算成百分比(同 brightness_pct 的 1~100),开灯最低报 1%
+ "亮度是:" percent = max(1, round(brightness * 100 / 255)) if brightness > 0 else 0
+ str(response.json()["attributes"]["brightness"]) responsetext = responsetext + "亮度是:" + f"{percent}%" + " "
+ " "
)
logger.bind(tag=TAG).info(f"查询返回内容: {responsetext}") logger.bind(tag=TAG).info(f"查询返回内容: {responsetext}")
return responsetext return responsetext
else: else: