Add Media Player Stop command + Kodi support for it (#1960)
* Started adding Stop command to Kodi media player * minor * minor * minor * abstract-method fixed
This commit is contained in:
parent
e5d1ed9439
commit
393bd88091
5 changed files with 42 additions and 4 deletions
|
@ -19,7 +19,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF, STATE_UNKNOWN, STATE_PLAYING, STATE_IDLE,
|
STATE_OFF, STATE_UNKNOWN, STATE_PLAYING, STATE_IDLE,
|
||||||
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
||||||
SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_SET,
|
SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_SET,
|
||||||
SERVICE_VOLUME_MUTE, SERVICE_TOGGLE,
|
SERVICE_VOLUME_MUTE, SERVICE_TOGGLE, SERVICE_MEDIA_STOP,
|
||||||
SERVICE_MEDIA_PLAY_PAUSE, SERVICE_MEDIA_PLAY, SERVICE_MEDIA_PAUSE,
|
SERVICE_MEDIA_PLAY_PAUSE, SERVICE_MEDIA_PLAY, SERVICE_MEDIA_PAUSE,
|
||||||
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK)
|
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK)
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ SUPPORT_TURN_OFF = 256
|
||||||
SUPPORT_PLAY_MEDIA = 512
|
SUPPORT_PLAY_MEDIA = 512
|
||||||
SUPPORT_VOLUME_STEP = 1024
|
SUPPORT_VOLUME_STEP = 1024
|
||||||
SUPPORT_SELECT_SOURCE = 2048
|
SUPPORT_SELECT_SOURCE = 2048
|
||||||
|
SUPPORT_STOP = 4096
|
||||||
|
|
||||||
# simple services that only take entity_id(s) as optional argument
|
# simple services that only take entity_id(s) as optional argument
|
||||||
SERVICE_TO_METHOD = {
|
SERVICE_TO_METHOD = {
|
||||||
|
@ -93,6 +94,7 @@ SERVICE_TO_METHOD = {
|
||||||
SERVICE_MEDIA_PLAY_PAUSE: 'media_play_pause',
|
SERVICE_MEDIA_PLAY_PAUSE: 'media_play_pause',
|
||||||
SERVICE_MEDIA_PLAY: 'media_play',
|
SERVICE_MEDIA_PLAY: 'media_play',
|
||||||
SERVICE_MEDIA_PAUSE: 'media_pause',
|
SERVICE_MEDIA_PAUSE: 'media_pause',
|
||||||
|
SERVICE_MEDIA_STOP: 'media_stop',
|
||||||
SERVICE_MEDIA_NEXT_TRACK: 'media_next_track',
|
SERVICE_MEDIA_NEXT_TRACK: 'media_next_track',
|
||||||
SERVICE_MEDIA_PREVIOUS_TRACK: 'media_previous_track',
|
SERVICE_MEDIA_PREVIOUS_TRACK: 'media_previous_track',
|
||||||
SERVICE_SELECT_SOURCE: 'select_source'
|
SERVICE_SELECT_SOURCE: 'select_source'
|
||||||
|
@ -228,6 +230,12 @@ def media_pause(hass, entity_id=None):
|
||||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PAUSE, data)
|
hass.services.call(DOMAIN, SERVICE_MEDIA_PAUSE, data)
|
||||||
|
|
||||||
|
|
||||||
|
def media_stop(hass, entity_id=None):
|
||||||
|
"""Send the media player the stop command."""
|
||||||
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
hass.services.call(DOMAIN, SERVICE_MEDIA_STOP, data)
|
||||||
|
|
||||||
|
|
||||||
def media_next_track(hass, entity_id=None):
|
def media_next_track(hass, entity_id=None):
|
||||||
"""Send the media player the command for next track."""
|
"""Send the media player the command for next track."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
@ -510,6 +518,10 @@ class MediaPlayerDevice(Entity):
|
||||||
"""Send pause command."""
|
"""Send pause command."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def media_stop(self):
|
||||||
|
"""Send stop command."""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def media_previous_track(self):
|
def media_previous_track(self):
|
||||||
"""Send previous track command."""
|
"""Send previous track command."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -536,6 +548,11 @@ class MediaPlayerDevice(Entity):
|
||||||
"""Boolean if pause is supported."""
|
"""Boolean if pause is supported."""
|
||||||
return bool(self.supported_media_commands & SUPPORT_PAUSE)
|
return bool(self.supported_media_commands & SUPPORT_PAUSE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def support_stop(self):
|
||||||
|
"""Boolean if stop is supported."""
|
||||||
|
return bool(self.supported_media_commands & SUPPORT_STOP)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def support_seek(self):
|
def support_seek(self):
|
||||||
"""Boolean if seek is supported."""
|
"""Boolean if seek is supported."""
|
||||||
|
|
|
@ -9,7 +9,7 @@ import urllib
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK, SUPPORT_SEEK,
|
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK, SUPPORT_SEEK,
|
||||||
SUPPORT_PLAY_MEDIA, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
SUPPORT_PLAY_MEDIA, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_STOP,
|
||||||
MediaPlayerDevice)
|
MediaPlayerDevice)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING)
|
STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING)
|
||||||
|
@ -19,7 +19,7 @@ REQUIREMENTS = ['jsonrpc-requests==0.2']
|
||||||
|
|
||||||
SUPPORT_KODI = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
SUPPORT_KODI = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||||
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK | \
|
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK | \
|
||||||
SUPPORT_PLAY_MEDIA
|
SUPPORT_PLAY_MEDIA | SUPPORT_STOP
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
@ -229,6 +229,13 @@ class KodiDevice(MediaPlayerDevice):
|
||||||
"""Pause the media player."""
|
"""Pause the media player."""
|
||||||
self._set_play_state(False)
|
self._set_play_state(False)
|
||||||
|
|
||||||
|
def media_stop(self):
|
||||||
|
"""Stop the media player."""
|
||||||
|
players = self._get_players()
|
||||||
|
|
||||||
|
if len(players) != 0:
|
||||||
|
self._server.Player.Stop(players[0]['playerid'])
|
||||||
|
|
||||||
def _goto(self, direction):
|
def _goto(self, direction):
|
||||||
"""Helper method used for previous/next track."""
|
"""Helper method used for previous/next track."""
|
||||||
players = self._get_players()
|
players = self._get_players()
|
||||||
|
|
|
@ -86,6 +86,14 @@ media_pause:
|
||||||
description: Name(s) of entities to pause on
|
description: Name(s) of entities to pause on
|
||||||
example: 'media_player.living_room_sonos'
|
example: 'media_player.living_room_sonos'
|
||||||
|
|
||||||
|
media_stop:
|
||||||
|
description: Send the media player the stop command.
|
||||||
|
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Name(s) of entities to stop on
|
||||||
|
example: 'media_player.living_room_sonos'
|
||||||
|
|
||||||
media_next_track:
|
media_next_track:
|
||||||
description: Send the media player the command for next track.
|
description: Send the media player the command for next track.
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,8 @@ from homeassistant.const import (
|
||||||
SERVICE_MEDIA_PAUSE, SERVICE_MEDIA_PLAY, SERVICE_MEDIA_PLAY_PAUSE,
|
SERVICE_MEDIA_PAUSE, SERVICE_MEDIA_PLAY, SERVICE_MEDIA_PLAY_PAUSE,
|
||||||
SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK, SERVICE_TURN_OFF,
|
SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK, SERVICE_TURN_OFF,
|
||||||
SERVICE_TURN_ON, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_MUTE,
|
SERVICE_TURN_ON, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_MUTE,
|
||||||
SERVICE_VOLUME_SET, SERVICE_VOLUME_UP, STATE_IDLE, STATE_OFF, STATE_ON)
|
SERVICE_VOLUME_SET, SERVICE_VOLUME_UP, STATE_IDLE, STATE_OFF, STATE_ON,
|
||||||
|
SERVICE_MEDIA_STOP)
|
||||||
from homeassistant.helpers.event import track_state_change
|
from homeassistant.helpers.event import track_state_change
|
||||||
from homeassistant.helpers.service import call_from_config
|
from homeassistant.helpers.service import call_from_config
|
||||||
|
|
||||||
|
@ -384,6 +385,10 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||||
"""Send pause command."""
|
"""Send pause command."""
|
||||||
self._call_service(SERVICE_MEDIA_PAUSE)
|
self._call_service(SERVICE_MEDIA_PAUSE)
|
||||||
|
|
||||||
|
def media_stop(self):
|
||||||
|
"""Send stop command."""
|
||||||
|
self._call_service(SERVICE_MEDIA_STOP)
|
||||||
|
|
||||||
def media_previous_track(self):
|
def media_previous_track(self):
|
||||||
"""Send previous track command."""
|
"""Send previous track command."""
|
||||||
self._call_service(SERVICE_MEDIA_PREVIOUS_TRACK)
|
self._call_service(SERVICE_MEDIA_PREVIOUS_TRACK)
|
||||||
|
|
|
@ -171,6 +171,7 @@ SERVICE_VOLUME_SET = "volume_set"
|
||||||
SERVICE_MEDIA_PLAY_PAUSE = "media_play_pause"
|
SERVICE_MEDIA_PLAY_PAUSE = "media_play_pause"
|
||||||
SERVICE_MEDIA_PLAY = "media_play"
|
SERVICE_MEDIA_PLAY = "media_play"
|
||||||
SERVICE_MEDIA_PAUSE = "media_pause"
|
SERVICE_MEDIA_PAUSE = "media_pause"
|
||||||
|
SERVICE_MEDIA_STOP = "media_stop"
|
||||||
SERVICE_MEDIA_NEXT_TRACK = "media_next_track"
|
SERVICE_MEDIA_NEXT_TRACK = "media_next_track"
|
||||||
SERVICE_MEDIA_PREVIOUS_TRACK = "media_previous_track"
|
SERVICE_MEDIA_PREVIOUS_TRACK = "media_previous_track"
|
||||||
SERVICE_MEDIA_SEEK = "media_seek"
|
SERVICE_MEDIA_SEEK = "media_seek"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue