Add support for multiple devices for PS4 component (#21302)

* Support multiple devices.

* Revert "Support multiple devices."

This reverts commit 3f5d4462a98da13ebb1ab1c07d341dbd7020e6cc.

* Support multiple devices

* Bump to 0.3.3

* bump 0.3.4

* Add tests for multiple devices.

* Update Requirements

* Update config_flow.py

* Update config_flow.py

* fixed typo

* Reordered functions

* Added multiple flow implementation test.

* fix

* typo

* fix tests

* bump 0.4.0

* Bump 0.4.0

* 0.4.0

* bump version

* bump version

* bump version

* Add keep alive feature with multiple devices

* bump version

* bump version

* bump version

* bump 0.4.7

* bump 0.4.7

* bump 0.4.7

* Edited tests.

* bump/pylint

* pylint

* bump/pylint

* bump/pylint

* Change to add additional entry

* Changed to multiple entries

* pylint

* Corrections to manage multiple devices.

* lint

* comments

* Removed redundant for loop

* Shorthand correction

* Remove reference to private object

* Test fix

* Revert changes. Test failure.

* Test fix

* test fix

* unindent assertions

* pylint
This commit is contained in:
ktnrg45 2019-03-04 17:48:25 -07:00 committed by Martin Hjelmare
parent df25128923
commit efa5d5dfe3
6 changed files with 214 additions and 34 deletions

View file

@ -37,10 +37,6 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow):
async def async_step_user(self, user_input=None):
"""Handle a user config flow."""
# Abort if device is configured.
if self.hass.config_entries.async_entries(DOMAIN):
return self.async_abort(reason='devices_configured')
# Check if able to bind to ports: UDP 987, TCP 997.
ports = PORT_MSG.keys()
failed = await self.hass.async_add_executor_job(
@ -48,6 +44,9 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow):
if failed in ports:
reason = PORT_MSG[failed]
return self.async_abort(reason=reason)
# Skip Creds Step if a device is configured.
if self.hass.config_entries.async_entries(DOMAIN):
return await self.async_step_link()
return await self.async_step_creds()
async def async_step_creds(self, user_input=None):
@ -78,6 +77,18 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow):
device_list = [
device['host-ip'] for device in devices]
# If entry exists check that devices found aren't configured.
if self.hass.config_entries.async_entries(DOMAIN):
for entry in self.hass.config_entries.async_entries(DOMAIN):
conf_devices = entry.data['devices']
for c_device in conf_devices:
if c_device['host'] in device_list:
# Remove configured device from search list.
device_list.remove(c_device['host'])
# If list is empty then all devices are configured.
if not device_list:
return self.async_abort(reason='devices_configured')
# Login to PS4 with user data.
if user_input is not None:
self.region = user_input[CONF_REGION]