Skip to content

Commit

Permalink
🔉 improve playback status for xiaoai (#1585)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjq19940331 authored Mar 26, 2024
1 parent 6f6374b commit 9f0d7dc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions custom_components/xiaomi_miot/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,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()

Expand Down Expand Up @@ -443,6 +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
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:
Expand Down

0 comments on commit 9f0d7dc

Please sign in to comment.