fix: set volume failed

This commit is contained in:
涵曦 2024-01-30 08:21:31 +08:00
parent 32fb0e9548
commit 2acb668101
2 changed files with 6 additions and 3 deletions

View File

@ -31,7 +31,7 @@ HARDWARE_COMMAND_DICT = {
# add more here # add more here
} }
DEFAULT_COMMAND = ("5-1", "5-5") DEFAULT_COMMAND = ("5-1", "5-5", "2-1")
KEY_WORD_DICT = { KEY_WORD_DICT = {
"播放歌曲": "play", "播放歌曲": "play",
@ -79,7 +79,7 @@ class Config:
mi_did: str = os.getenv("MI_DID", "") mi_did: str = os.getenv("MI_DID", "")
mute_xiaoai: bool = True mute_xiaoai: bool = True
cookie: str = "" cookie: str = ""
use_command: bool = True use_command: bool = False
verbose: bool = False verbose: bool = False
music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music") music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music")
hostname: str = os.getenv("XIAOMUSIC_HOSTNAME", "192.168.2.5") hostname: str = os.getenv("XIAOMUSIC_HOSTNAME", "192.168.2.5")

View File

@ -237,16 +237,19 @@ class XiaoMusic:
await self.wait_for_tts_finish() await self.wait_for_tts_finish()
async def do_set_volume(self, value): async def do_set_volume(self, value):
value = int(value)
if not self.config.use_command: if not self.config.use_command:
try: try:
self.log.debug("do_set_volume not use_command value:%d", value)
await self.mina_service.player_set_volume(self.device_id, value) await self.mina_service.player_set_volume(self.device_id, value)
except Exception: except Exception:
pass pass
else: else:
self.log.debug("do_set_volume use_command value:%d", value)
await miio_command( await miio_command(
self.miio_service, self.miio_service,
self.config.mi_did, self.config.mi_did,
f"{self.config.volume_command} {value}", f"{self.config.volume_command}=#{value}",
) )
async def wait_for_tts_finish(self): async def wait_for_tts_finish(self):