PS4 handle no connection/ fix spamming of logs when device is off (#25091)

* Bump 0.8.7

* Bump 0.8.7

* 0.8.7

* Handle exception. Handle  device unavailable.

* Typo

* Blank line
This commit is contained in:
ktnrg45 2019-07-12 19:45:04 -07:00 committed by Aaron Bach
parent c6b63b15b8
commit 68edf10270
4 changed files with 18 additions and 7 deletions

View File

@ -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": [

View File

@ -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

View File

@ -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

View File

@ -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