diff --git a/homeassistant/components/ps4/manifest.json b/homeassistant/components/ps4/manifest.json index fa1d998cd5b..797a5432f97 100644 --- a/homeassistant/components/ps4/manifest.json +++ b/homeassistant/components/ps4/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/components/ps4", "requirements": [ - "pyps4-homeassistant==0.8.5" + "pyps4-homeassistant==0.8.7" ], "dependencies": [], "codeowners": [ diff --git a/homeassistant/components/ps4/media_player.py b/homeassistant/components/ps4/media_player.py index 7cd0d77113e..a6260c879a5 100644 --- a/homeassistant/components/ps4/media_player.py +++ b/homeassistant/components/ps4/media_player.py @@ -2,6 +2,9 @@ import logging import asyncio +import pyps4_homeassistant.ps4 as pyps4 +from pyps4_homeassistant.errors import NotReady + from homeassistant.core import callback from homeassistant.components.media_player import ( ENTITY_IMAGE_URL, MediaPlayerDevice) @@ -27,6 +30,8 @@ ICON = 'mdi:playstation' GAMES_FILE = '.ps4-games.json' MEDIA_IMAGE_DEFAULT = None +DEFAULT_RETRIES = 2 + async def async_setup_entry(hass, config_entry, async_add_entities): """Set up PS4 from a config entry.""" @@ -38,7 +43,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): """Set up PS4 Platform.""" - import pyps4_homeassistant.ps4 as pyps4 games_file = hass.config.path(GAMES_FILE) creds = config.data[CONF_TOKEN] device_list = [] @@ -118,8 +122,15 @@ class PS4Device(MediaPlayerDevice): if self._ps4.ddp_protocol is not None: # Request Status with asyncio transport. self._ps4.get_status() - if not self._ps4.connected and not self._ps4.is_standby: - await self._ps4.async_connect() + + # Don't attempt to connect if entity is connected or if, + # PS4 is in standby or disconnected from LAN or powered off. + if not self._ps4.connected and not self._ps4.is_standby and\ + self._ps4.is_available: + try: + await self._ps4.async_connect() + except NotReady: + pass # Try to ensure correct status is set on startup for device info. if self._ps4.ddp_protocol is None: @@ -162,7 +173,7 @@ class PS4Device(MediaPlayerDevice): if self._state != STATE_OFF: self.state_off() - elif self._retry > 5: + elif self._retry > DEFAULT_RETRIES: self.state_unknown() else: self._retry += 1 diff --git a/requirements_all.txt b/requirements_all.txt index 6243158a098..ecadcb46ba3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1324,7 +1324,7 @@ pypjlink2==1.2.0 pypoint==1.1.1 # homeassistant.components.ps4 -pyps4-homeassistant==0.8.5 +pyps4-homeassistant==0.8.7 # homeassistant.components.qwikswitch pyqwikswitch==0.93 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f8b5f8c9411..f12e1052504 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -286,7 +286,7 @@ pyopenuv==1.0.9 pyotp==2.2.7 # homeassistant.components.ps4 -pyps4-homeassistant==0.8.5 +pyps4-homeassistant==0.8.7 # homeassistant.components.qwikswitch pyqwikswitch==0.93