mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
Compare commits
5 commits
ff02defbdc
...
ac9390054e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac9390054e | ||
|
|
4b1a54a41c | ||
|
|
dd367c9e43 | ||
|
|
b4e144afef | ||
|
|
98c314a485 |
3 changed files with 18 additions and 20 deletions
|
|
@ -31,6 +31,8 @@ class AudioPlugin(Plugin):
|
|||
self.source.stop()
|
||||
|
||||
def shutdown(self) -> None:
|
||||
if self.source is not None:
|
||||
self.source.stop()
|
||||
if self.app is not None:
|
||||
self.app.audio_source = None
|
||||
self.source = None
|
||||
|
|
|
|||
|
|
@ -51,13 +51,14 @@ class TestRuntimeApplication:
|
|||
logger.info("test runtime application started")
|
||||
|
||||
def stop(self) -> None:
|
||||
if not self._is_running:
|
||||
return
|
||||
|
||||
self.event_bridge.publish_service_stopping()
|
||||
self.plugins.stop_all()
|
||||
was_running = self._is_running
|
||||
self._is_running = False
|
||||
logger.info("test runtime application stopped")
|
||||
if was_running:
|
||||
self.event_bridge.publish_service_stopping()
|
||||
logger.info("test runtime application stopped")
|
||||
# 启动中途失败时 _is_running 还是 False,但插件可能已经开过采集流,
|
||||
# 这里不提前返回,保证采集流一定被关掉
|
||||
self.plugins.stop_all()
|
||||
|
||||
def shutdown(self) -> None:
|
||||
self.stop()
|
||||
|
|
|
|||
|
|
@ -121,13 +121,10 @@ async def handle_hass_get_state(conn: "ConnectionHandler", entity_id):
|
|||
+ str(response.json()["attributes"]["media_title"])
|
||||
+ " "
|
||||
)
|
||||
if "volume_level" in response.json()["attributes"]:
|
||||
responsetext = (
|
||||
responsetext
|
||||
+ "音量是:"
|
||||
+ str(response.json()["attributes"]["volume_level"])
|
||||
+ " "
|
||||
)
|
||||
volume_level = response.json()["attributes"].get("volume_level")
|
||||
if isinstance(volume_level, (int, float)):
|
||||
# volume_level 量程 0~1,换算成百分比(同 volume_set 的 1~100)
|
||||
responsetext = responsetext + "音量是:" + f"{round(volume_level * 100)}%" + " "
|
||||
if "color_temp_kelvin" in response.json()["attributes"]:
|
||||
responsetext = (
|
||||
responsetext
|
||||
|
|
@ -142,13 +139,11 @@ async def handle_hass_get_state(conn: "ConnectionHandler", entity_id):
|
|||
+ str(response.json()["attributes"]["rgb_color"])
|
||||
+ " "
|
||||
)
|
||||
if "brightness" in response.json()["attributes"]:
|
||||
responsetext = (
|
||||
responsetext
|
||||
+ "亮度是:"
|
||||
+ str(response.json()["attributes"]["brightness"])
|
||||
+ " "
|
||||
)
|
||||
brightness = response.json()["attributes"].get("brightness")
|
||||
if isinstance(brightness, (int, float)):
|
||||
# brightness 量程 0~255,换算成百分比(同 brightness_pct 的 1~100),开灯最低报 1%
|
||||
percent = max(1, round(brightness * 100 / 255)) if brightness > 0 else 0
|
||||
responsetext = responsetext + "亮度是:" + f"{percent}%" + " "
|
||||
logger.bind(tag=TAG).info(f"查询返回内容: {responsetext}")
|
||||
return responsetext
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue