Bump pyps4-2ndscreen to 1.2.0 (#44273)
* Bump PS4 to 1.2.0 * Add additional media_player tests * Fix tests
This commit is contained in:
parent
5c843a1597
commit
5b14c1da73
7 changed files with 36 additions and 9 deletions
|
@ -23,6 +23,7 @@ CONF_MODE = "Config Mode"
|
||||||
CONF_AUTO = "Auto Discover"
|
CONF_AUTO = "Auto Discover"
|
||||||
CONF_MANUAL = "Manual Entry"
|
CONF_MANUAL = "Manual Entry"
|
||||||
|
|
||||||
|
LOCAL_UDP_PORT = 1988
|
||||||
UDP_PORT = 987
|
UDP_PORT = 987
|
||||||
TCP_PORT = 997
|
TCP_PORT = 997
|
||||||
PORT_MSG = {UDP_PORT: "port_987_bind_error", TCP_PORT: "port_997_bind_error"}
|
PORT_MSG = {UDP_PORT: "port_987_bind_error", TCP_PORT: "port_997_bind_error"}
|
||||||
|
@ -107,8 +108,9 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow):
|
||||||
|
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
# Search for device.
|
# Search for device.
|
||||||
|
# If LOCAL_UDP_PORT cannot be used, a random port will be selected.
|
||||||
devices = await self.hass.async_add_executor_job(
|
devices = await self.hass.async_add_executor_job(
|
||||||
self.helper.has_devices, self.m_device
|
self.helper.has_devices, self.m_device, LOCAL_UDP_PORT
|
||||||
)
|
)
|
||||||
|
|
||||||
# Abort if can't find device.
|
# Abort if can't find device.
|
||||||
|
@ -147,7 +149,12 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow):
|
||||||
self.host = user_input[CONF_IP_ADDRESS]
|
self.host = user_input[CONF_IP_ADDRESS]
|
||||||
|
|
||||||
is_ready, is_login = await self.hass.async_add_executor_job(
|
is_ready, is_login = await self.hass.async_add_executor_job(
|
||||||
self.helper.link, self.host, self.creds, self.pin, DEFAULT_ALIAS
|
self.helper.link,
|
||||||
|
self.host,
|
||||||
|
self.creds,
|
||||||
|
self.pin,
|
||||||
|
DEFAULT_ALIAS,
|
||||||
|
LOCAL_UDP_PORT,
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_ready is False:
|
if is_ready is False:
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
"name": "Sony PlayStation 4",
|
"name": "Sony PlayStation 4",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/ps4",
|
"documentation": "https://www.home-assistant.io/integrations/ps4",
|
||||||
"requirements": ["pyps4-2ndscreen==1.1.1"],
|
"requirements": ["pyps4-2ndscreen==1.2.0"],
|
||||||
"codeowners": ["@ktnrg45"]
|
"codeowners": ["@ktnrg45"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyps4_2ndscreen.errors import NotReady, PSDataIncomplete
|
from pyps4_2ndscreen.errors import NotReady, PSDataIncomplete
|
||||||
|
from pyps4_2ndscreen.media_art import TYPE_APP as PS_TYPE_APP
|
||||||
import pyps4_2ndscreen.ps4 as pyps4
|
import pyps4_2ndscreen.ps4 as pyps4
|
||||||
|
|
||||||
from homeassistant.components.media_player import MediaPlayerEntity
|
from homeassistant.components.media_player import MediaPlayerEntity
|
||||||
|
@ -262,7 +263,7 @@ class PS4Device(MediaPlayerEntity):
|
||||||
app_name = title.name
|
app_name = title.name
|
||||||
art = title.cover_art
|
art = title.cover_art
|
||||||
# Assume media type is game if not app.
|
# Assume media type is game if not app.
|
||||||
if title.game_type != "App":
|
if title.game_type != PS_TYPE_APP:
|
||||||
media_type = MEDIA_TYPE_GAME
|
media_type = MEDIA_TYPE_GAME
|
||||||
else:
|
else:
|
||||||
media_type = MEDIA_TYPE_APP
|
media_type = MEDIA_TYPE_APP
|
||||||
|
|
|
@ -1622,7 +1622,7 @@ pypoint==2.0.0
|
||||||
pyprof2calltree==1.4.5
|
pyprof2calltree==1.4.5
|
||||||
|
|
||||||
# homeassistant.components.ps4
|
# homeassistant.components.ps4
|
||||||
pyps4-2ndscreen==1.1.1
|
pyps4-2ndscreen==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.qvr_pro
|
# homeassistant.components.qvr_pro
|
||||||
pyqvrpro==0.52
|
pyqvrpro==0.52
|
||||||
|
|
|
@ -823,7 +823,7 @@ pypoint==2.0.0
|
||||||
pyprof2calltree==1.4.5
|
pyprof2calltree==1.4.5
|
||||||
|
|
||||||
# homeassistant.components.ps4
|
# homeassistant.components.ps4
|
||||||
pyps4-2ndscreen==1.1.1
|
pyps4-2ndscreen==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.qwikswitch
|
# homeassistant.components.qwikswitch
|
||||||
pyqwikswitch==0.93
|
pyqwikswitch==0.93
|
||||||
|
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components import ps4
|
from homeassistant.components import ps4
|
||||||
|
from homeassistant.components.ps4.config_flow import LOCAL_UDP_PORT
|
||||||
from homeassistant.components.ps4.const import (
|
from homeassistant.components.ps4.const import (
|
||||||
DEFAULT_ALIAS,
|
DEFAULT_ALIAS,
|
||||||
DEFAULT_NAME,
|
DEFAULT_NAME,
|
||||||
|
@ -360,7 +361,7 @@ async def test_0_pin(hass):
|
||||||
result["flow_id"], mock_config
|
result["flow_id"], mock_config
|
||||||
)
|
)
|
||||||
mock_call.assert_called_once_with(
|
mock_call.assert_called_once_with(
|
||||||
MOCK_HOST, MOCK_CREDS, MOCK_CODE_LEAD_0_STR, DEFAULT_ALIAS
|
MOCK_HOST, MOCK_CREDS, MOCK_CODE_LEAD_0_STR, DEFAULT_ALIAS, LOCAL_UDP_PORT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Tests for the PS4 media player platform."""
|
"""Tests for the PS4 media player platform."""
|
||||||
from pyps4_2ndscreen.credential import get_ddp_message
|
from pyps4_2ndscreen.credential import get_ddp_message
|
||||||
|
from pyps4_2ndscreen.ddp import DEFAULT_UDP_PORT
|
||||||
|
from pyps4_2ndscreen.media_art import TYPE_APP as PS_TYPE_APP
|
||||||
|
|
||||||
from homeassistant.components import ps4
|
from homeassistant.components import ps4
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
|
@ -8,6 +10,7 @@ from homeassistant.components.media_player.const import (
|
||||||
ATTR_MEDIA_CONTENT_ID,
|
ATTR_MEDIA_CONTENT_ID,
|
||||||
ATTR_MEDIA_CONTENT_TYPE,
|
ATTR_MEDIA_CONTENT_TYPE,
|
||||||
ATTR_MEDIA_TITLE,
|
ATTR_MEDIA_TITLE,
|
||||||
|
MEDIA_TYPE_APP,
|
||||||
MEDIA_TYPE_GAME,
|
MEDIA_TYPE_GAME,
|
||||||
)
|
)
|
||||||
from homeassistant.components.ps4.const import (
|
from homeassistant.components.ps4.const import (
|
||||||
|
@ -149,7 +152,7 @@ async def setup_mock_component(hass, entry=None):
|
||||||
async def mock_ddp_response(hass, mock_status_data):
|
async def mock_ddp_response(hass, mock_status_data):
|
||||||
"""Mock raw UDP response from device."""
|
"""Mock raw UDP response from device."""
|
||||||
mock_protocol = hass.data[PS4_DATA].protocol
|
mock_protocol = hass.data[PS4_DATA].protocol
|
||||||
|
assert mock_protocol.local_port == DEFAULT_UDP_PORT
|
||||||
mock_code = mock_status_data.get("status_code")
|
mock_code = mock_status_data.get("status_code")
|
||||||
mock_status = mock_status_data.get("status")
|
mock_status = mock_status_data.get("status")
|
||||||
mock_status_header = f"{mock_code} {mock_status}"
|
mock_status_header = f"{mock_code} {mock_status}"
|
||||||
|
@ -224,7 +227,7 @@ async def test_media_attributes_are_fetched(hass):
|
||||||
mock_result = MagicMock()
|
mock_result = MagicMock()
|
||||||
mock_result.name = MOCK_TITLE_NAME
|
mock_result.name = MOCK_TITLE_NAME
|
||||||
mock_result.cover_art = MOCK_TITLE_ART_URL
|
mock_result.cover_art = MOCK_TITLE_ART_URL
|
||||||
mock_result.game_type = "game"
|
mock_result.game_type = "not_an_app"
|
||||||
|
|
||||||
with patch(mock_func, return_value=mock_result) as mock_fetch:
|
with patch(mock_func, return_value=mock_result) as mock_fetch:
|
||||||
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
|
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
|
||||||
|
@ -241,6 +244,21 @@ async def test_media_attributes_are_fetched(hass):
|
||||||
assert mock_attrs.get(ATTR_MEDIA_TITLE) == MOCK_TITLE_NAME
|
assert mock_attrs.get(ATTR_MEDIA_TITLE) == MOCK_TITLE_NAME
|
||||||
assert mock_attrs.get(ATTR_MEDIA_CONTENT_TYPE) == MOCK_TITLE_TYPE
|
assert mock_attrs.get(ATTR_MEDIA_CONTENT_TYPE) == MOCK_TITLE_TYPE
|
||||||
|
|
||||||
|
# Change state so that the next fetch is called.
|
||||||
|
await mock_ddp_response(hass, MOCK_STATUS_STANDBY)
|
||||||
|
|
||||||
|
# Test that content type of app is set.
|
||||||
|
mock_result.game_type = PS_TYPE_APP
|
||||||
|
|
||||||
|
with patch(mock_func, return_value=mock_result) as mock_fetch_app:
|
||||||
|
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
|
||||||
|
|
||||||
|
mock_state = hass.states.get(mock_entity_id)
|
||||||
|
mock_attrs = dict(mock_state.attributes)
|
||||||
|
|
||||||
|
assert len(mock_fetch_app.mock_calls) == 1
|
||||||
|
assert mock_attrs.get(ATTR_MEDIA_CONTENT_TYPE) == MEDIA_TYPE_APP
|
||||||
|
|
||||||
|
|
||||||
async def test_media_attributes_are_loaded(hass, patch_load_json):
|
async def test_media_attributes_are_loaded(hass, patch_load_json):
|
||||||
"""Test that media attributes are loaded."""
|
"""Test that media attributes are loaded."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue