Bump pyheos to 0.4.1 (#23360)

* Bump pyheos==0.4.1

* Refresh player after reconnection
This commit is contained in:
Andrew Sayre 2019-04-24 23:31:32 -05:00 committed by Paulus Schoutsen
parent 6fb5b8467b
commit e3e7fb5ff6
5 changed files with 41 additions and 6 deletions

View File

@ -3,7 +3,7 @@
"name": "Heos",
"documentation": "https://www.home-assistant.io/components/heos",
"requirements": [
"pyheos==0.4.0"
"pyheos==0.4.1"
],
"dependencies": [],
"codeowners": [

View File

@ -1,4 +1,5 @@
"""Denon HEOS Media Player."""
import asyncio
from functools import reduce, wraps
import logging
from operator import ior
@ -48,7 +49,7 @@ def log_command_error(command: str):
from pyheos import CommandError
try:
await func(*args, **kwargs)
except CommandError as ex:
except (CommandError, asyncio.TimeoutError, ConnectionError) as ex:
_LOGGER.error("Unable to %s: %s", command, ex)
return wrapper
return decorator
@ -86,6 +87,13 @@ class HeosMediaPlayer(MediaPlayerDevice):
async def _heos_event(self, event):
"""Handle connection event."""
from pyheos import CommandError, const
if event == const.EVENT_CONNECTED:
try:
await self._player.refresh()
except (CommandError, asyncio.TimeoutError, ConnectionError) as ex:
_LOGGER.error("Unable to refresh player %s: %s",
self._player, ex)
await self.async_update_ha_state(True)
async def _player_update(self, player_id, event):

View File

@ -1079,7 +1079,7 @@ pygtt==1.1.2
pyhaversion==2.2.1
# homeassistant.components.heos
pyheos==0.4.0
pyheos==0.4.1
# homeassistant.components.hikvision
pyhik==0.2.2

View File

@ -223,7 +223,7 @@ pydeconz==54
pydispatcher==2.0.5
# homeassistant.components.heos
pyheos==0.4.0
pyheos==0.4.1
# homeassistant.components.homematic
pyhomematic==0.1.58

View File

@ -109,13 +109,40 @@ async def test_updates_start_from_signals(
state = hass.states.get('media_player.test_player')
assert state.state == STATE_UNAVAILABLE
# Test heos events update
async def test_updates_from_connection_event(
hass, config_entry, config, controller, input_sources, caplog):
"""Tests player updates from connection event after connection failure."""
# Connected
await setup_platform(hass, config_entry, config)
player = controller.players[1]
player.available = True
player.heos.dispatcher.send(
const.SIGNAL_HEOS_EVENT, const.EVENT_CONNECTED)
await hass.async_block_till_done()
state = hass.states.get('media_player.test_player')
assert state.state == STATE_PLAYING
assert state.state == STATE_IDLE
assert player.refresh.call_count == 1
# Connected handles refresh failure
player.reset_mock()
player.refresh.side_effect = CommandError(None, "Failure", 1)
player.heos.dispatcher.send(
const.SIGNAL_HEOS_EVENT, const.EVENT_CONNECTED)
await hass.async_block_till_done()
state = hass.states.get('media_player.test_player')
assert player.refresh.call_count == 1
assert "Unable to refresh player" in caplog.text
# Disconnected
player.reset_mock()
player.available = False
player.heos.dispatcher.send(
const.SIGNAL_HEOS_EVENT, const.EVENT_DISCONNECTED)
await hass.async_block_till_done()
state = hass.states.get('media_player.test_player')
assert state.state == STATE_UNAVAILABLE
assert player.refresh.call_count == 0
async def test_updates_from_sources_updated(