Skip to content

Commit

Permalink
Add MediaPlayer Capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
spagl-kobil committed Apr 5, 2024
1 parent 00eccac commit 08e8f26
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track

### Changed

- Fixed state, also displaying "playing" and "paused" values

## [0.3.2] Fix division by zero

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,15 @@ def device_name(self):

@property
def state(self) -> str:
return "on" if self.device.status.switch else "off"
if self.device.status.switch:
if self.device.status.playback_status == "playing":
return "playing"
if self.device.status.playback_status == "paused":
return "paused"
else:
return "on"
else:
return "off"

async def switch_off(self):
await self.device.switch_off(True)
Expand Down Expand Up @@ -377,6 +385,12 @@ async def media_pause(self):
async def media_stop(self):
await self.device.stop(True)

async def media_next_track(self):
await self.device.command("main", "mediaPlayback", "fastForward")

async def media_previous_track(self):
await self.device.command("main", "mediaPlayback", "rewind")

@property
def media_app_name(self):
detail_status = self.device.status.attributes.get("detailName", None)
Expand Down
8 changes: 8 additions & 0 deletions custom_components/samsung_soundbar/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.SELECT_SOUND_MODE
)
Expand Down Expand Up @@ -177,6 +179,12 @@ async def async_media_play(self):
async def async_media_pause(self):
await self.device.media_pause()

async def async_media_next_track(self):
await self.device.media_next_track()

async def async_media_previous_track(self):
await self.device.media_previous_track()

async def async_media_stop(self):
await self.device.media_stop()

Expand Down

0 comments on commit 08e8f26

Please sign in to comment.