From c67d33c9f52157fe86feb7e10e1a90f46cf237d4 Mon Sep 17 00:00:00 2001 From: tjq19940331 <61875111+tjq19940331@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:17:04 +0800 Subject: [PATCH 1/2] Update media_player.py --- custom_components/xiaomi_miot/media_player.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/custom_components/xiaomi_miot/media_player.py b/custom_components/xiaomi_miot/media_player.py index c26688a03..ae59d4cc0 100644 --- a/custom_components/xiaomi_miot/media_player.py +++ b/custom_components/xiaomi_miot/media_player.py @@ -185,6 +185,12 @@ def state(self): if self._prop_state: sta = self._prop_state.from_dict(self._state_attrs) if sta is not None: + if self._state_attrs['speaker.mute'] == False : + new_state = {'playing_state': 1} + self._state_attrs.update(new_state) + else: + new_state = {'playing_state': 2} + self._state_attrs.update(new_state) if sta in self._prop_state.list_search('Playing', 'Play'): return MediaPlayerState.PLAYING if sta == self._prop_state.list_value('Pause'): @@ -443,6 +449,7 @@ async def async_update_play_status(self, now=None): self._attr_media_image_remotely_accessible = False self._attr_media_duration = int(song['duration'] / 1000) if 'duration' in song else None self._attr_media_position = int(song['position'] / 1000) if 'position' in song else None + self._attr_media_position_updated_at = utcnow() if not self._attr_state: self.logger.info('%s: Got empty media info: %s', self.name_model, result) except (TypeError, ValueError, Exception) as exc: From 8ccd55b951672fb0b088dde59f33d0738fded28e Mon Sep 17 00:00:00 2001 From: Alone Date: Tue, 26 Mar 2024 11:28:28 +0800 Subject: [PATCH 2/2] Update media_player.py --- custom_components/xiaomi_miot/media_player.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/custom_components/xiaomi_miot/media_player.py b/custom_components/xiaomi_miot/media_player.py index ae59d4cc0..d42ee2945 100644 --- a/custom_components/xiaomi_miot/media_player.py +++ b/custom_components/xiaomi_miot/media_player.py @@ -185,12 +185,6 @@ def state(self): if self._prop_state: sta = self._prop_state.from_dict(self._state_attrs) if sta is not None: - if self._state_attrs['speaker.mute'] == False : - new_state = {'playing_state': 1} - self._state_attrs.update(new_state) - else: - new_state = {'playing_state': 2} - self._state_attrs.update(new_state) if sta in self._prop_state.list_search('Playing', 'Play'): return MediaPlayerState.PLAYING if sta == self._prop_state.list_value('Pause'): @@ -361,6 +355,12 @@ async def async_update(self): return self._update_sub_entities('on', domain='switch') + if self._prop_state and not self._prop_state.readable: + if self.is_volume_muted is not False: + self._attr_state = MediaPlayerState.PLAYING + else: + self._attr_state = MediaPlayerState.IDLE + if self.xiaoai_device is None: await self.async_update_xiaoai_device() @@ -449,7 +449,8 @@ async def async_update_play_status(self, now=None): self._attr_media_image_remotely_accessible = False self._attr_media_duration = int(song['duration'] / 1000) if 'duration' in song else None self._attr_media_position = int(song['position'] / 1000) if 'position' in song else None - self._attr_media_position_updated_at = utcnow() + if self._attr_state == MediaPlayerState.PLAYING: + self._attr_media_position_updated_at = utcnow() if not self._attr_state: self.logger.info('%s: Got empty media info: %s', self.name_model, result) except (TypeError, ValueError, Exception) as exc: