Fix undesired power toggling (#37427)

This commit is contained in:
ktnrg45 2020-07-03 11:34:11 -07:00 committed by GitHub
parent 78e53e35c2
commit a445ebdf3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 3 deletions

View File

@ -3,6 +3,6 @@
"name": "Sony PlayStation 4",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/ps4",
"requirements": ["pyps4-2ndscreen==1.1.0"],
"requirements": ["pyps4-2ndscreen==1.1.1"],
"codeowners": ["@ktnrg45"]
}

View File

@ -453,6 +453,10 @@ class PS4Device(MediaPlayerEntity):
"""Turn on the media player."""
self._ps4.wakeup()
async def async_toggle(self):
"""Toggle media player."""
await self._ps4.toggle()
async def async_media_pause(self):
"""Send keypress ps to return to menu."""
await self.async_send_remote_control("ps")

View File

@ -1546,7 +1546,7 @@ pypjlink2==1.2.1
pypoint==1.1.2
# homeassistant.components.ps4
pyps4-2ndscreen==1.1.0
pyps4-2ndscreen==1.1.1
# homeassistant.components.qvr_pro
pyqvrpro==0.52

View File

@ -708,7 +708,7 @@ pyotp==2.3.0
pypoint==1.1.2
# homeassistant.components.ps4
pyps4-2ndscreen==1.1.0
pyps4-2ndscreen==1.1.1
# homeassistant.components.qwikswitch
pyqwikswitch==0.93

View File

@ -379,6 +379,22 @@ async def test_turn_off(hass):
assert len(mock_call.mock_calls) == 1
async def test_toggle(hass):
"""Test that toggle service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.toggle"
)
with patch(mock_func) as mock_call:
await hass.services.async_call(
"media_player", "toggle", {ATTR_ENTITY_ID: mock_entity_id}
)
await hass.async_block_till_done()
assert len(mock_call.mock_calls) == 1
async def test_media_pause(hass):
"""Test that media pause service calls function."""
mock_entity_id = await setup_mock_component(hass)