Fix ps4 not able to use different PSN accounts (#22799)

* Remove skipping of creds step.

* Check for device added per account

* typo

* lint

* Pylint

* Fix test

* Fix test

* Typo

* Add auto location

* blank space

* Add new identifier handling + fix select source

* Add cred_timeout error

* add credential timeout error

* Fix Tests

* patch decorator

* Update test_config_flow.py

* add test

* Revert

* Rename vars

* fix tests

* Add attr location

* Bump 0.6.0

* Bump 0.6.0

* Bump 0.6.0

* Update handling exception

* Update remove method

* Update tests

* Refactoring

* Pylint

* revert

* chmod

* 0.6.1

* 0.6.1

* 0.6.1

* Remove func

* Add migration

* Version 3

* Remove redefinition

* Add format unique id

* Add format unique id

* pylint

* pylint

* 0.7.1

* 0.7.1

* 0.7.1

* Changes with media_art call

* Add library exception

* 0.7.2

* 0.7.2

* 0.7.2

* Version and entry_version update

* Revert list comprehension

* Corrected exception handling

* Update media_player.py

* Update media_player.py

* white space
This commit is contained in:
ktnrg45 authored and Martin Hjelmare committed 2019-04-24 01:32:36 +02:00
1 parent d505f1c5f2
commit 68d3e624e6
9 files changed
+157 -47

No files matched your search

+32
View File
@@ -7,6 +7,7 @@ from homeassistant.components.ps4.const import (
DEFAULT_NAME, DEFAULT_REGION)
from homeassistant.const import (
CONF_CODE, CONF_HOST, CONF_IP_ADDRESS, CONF_NAME, CONF_REGION, CONF_TOKEN)
from homeassistant.util import location
from tests.common import MockConfigEntry
@@ -47,11 +48,17 @@ MOCK_TCP_PORT = int(997)
MOCK_AUTO = {"Config Mode": 'Auto Discover'}
MOCK_MANUAL = {"Config Mode": 'Manual Entry', CONF_IP_ADDRESS: MOCK_HOST}
MOCK_LOCATION = location.LocationInfo(
'0.0.0.0', 'US', 'United States', 'CA', 'California',
'San Diego', '92122', 'America/Los_Angeles', 32.8594,
-117.2073, True)
async def test_full_flow_implementation(hass):
"""Test registering an implementation and flow works."""
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
flow.location = MOCK_LOCATION
manager = hass.config_entries
# User Step Started, results in Step Creds
@@ -105,6 +112,7 @@ async def test_multiple_flow_implementation(hass):
"""Test multiple device flows."""
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
flow.location = MOCK_LOCATION
manager = hass.config_entries
# User Step Started, results in Step Creds
@@ -165,6 +173,13 @@ async def test_multiple_flow_implementation(hass):
{'host-ip': MOCK_HOST_ADDITIONAL}]):
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'creds'
# Step Creds results with form in Step Mode.
with patch('pyps4_homeassistant.Helper.get_creds',
return_value=MOCK_CREDS):
result = await flow.async_step_creds({})
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'mode'
# Step Mode with User Input which is not manual, results in Step Link.
@@ -229,6 +244,7 @@ async def test_duplicate_abort(hass):
MockConfigEntry(domain=ps4.DOMAIN, data=MOCK_DATA).add_to_hass(hass)
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
flow.creds = MOCK_CREDS
with patch('pyps4_homeassistant.Helper.has_devices',
return_value=[{'host-ip': MOCK_HOST}]):
@@ -284,6 +300,7 @@ async def test_manual_mode(hass):
"""Test host specified in manual mode is passed to Step Link."""
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
flow.location = MOCK_LOCATION
# Step Mode with User Input: manual, results in Step Link.
with patch('pyps4_homeassistant.Helper.has_devices',
@@ -305,10 +322,24 @@ async def test_credential_abort(hass):
assert result['reason'] == 'credential_error'
async def test_credential_timeout(hass):
"""Test that Credential Timeout shows error."""
from pyps4_homeassistant.errors import CredentialTimeout
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
with patch('pyps4_homeassistant.Helper.get_creds',
side_effect=CredentialTimeout):
result = await flow.async_step_creds({})
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['errors'] == {'base': 'credential_timeout'}
async def test_wrong_pin_error(hass):
"""Test that incorrect pin throws an error."""
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
flow.location = MOCK_LOCATION
with patch('pyps4_homeassistant.Helper.link',
return_value=(True, False)), \
@@ -324,6 +355,7 @@ async def test_device_connection_error(hass):
"""Test that device not connected or on throws an error."""
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
flow.location = MOCK_LOCATION
with patch('pyps4_homeassistant.Helper.link',
return_value=(False, True)), \