Skip to content

Commit

Permalink
Added test for universal mp service routing.
Browse files Browse the repository at this point in the history
Added tests to ensure that the Universal Media Player is routing
service calls correctly.
  • Loading branch information
rmkraus committed Jan 30, 2016
1 parent 6a75b52 commit 8ac763c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/components/media_player/test_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import homeassistant.components.media_player as media_player
import homeassistant.components.media_player.universal as universal

from tests.common import mock_service


class MockMediaPlayer(media_player.MediaPlayerDevice):
""" Mock media player for testing """
Expand All @@ -28,6 +30,9 @@ def __init__(self, hass, name):
self._media_title = None
self._supported_media_commands = 0

self.turn_off_service_calls = mock_service(
hass, media_player.DOMAIN, media_player.SERVICE_TURN_OFF)

@property
def name(self):
""" name of player """
Expand Down Expand Up @@ -399,3 +404,38 @@ def test_supported_media_commands_children_and_cmds(self):
| universal.SUPPORT_VOLUME_STEP | universal.SUPPORT_VOLUME_MUTE

self.assertEqual(check_flags, ump.supported_media_commands)

def test_service_call_to_child(self):
""" test a service call that should be routed to a child """
config = self.config_children_only
universal.validate_config(config)

ump = universal.UniversalMediaPlayer(self.hass, **config)
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
ump.update()

self.mock_mp_2._state = STATE_PLAYING
self.mock_mp_2.update_ha_state()
ump.update()

ump.turn_off()
self.assertEqual(len(self.mock_mp_2.turn_off_service_calls), 1)

def test_service_call_to_command(self):
config = self.config_children_only
config['commands'] = \
{'turn_off': {'service': 'test.turn_off', 'data': {}}}
universal.validate_config(config)

service = mock_service(self.hass, 'test', 'turn_off')

ump = universal.UniversalMediaPlayer(self.hass, **config)
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
ump.update()

self.mock_mp_2._state = STATE_PLAYING
self.mock_mp_2.update_ha_state()
ump.update()

ump.turn_off()
self.assertEqual(len(service), 1)

0 comments on commit 8ac763c

Please sign in to comment.