Fix Philips TV none recordings_list (#104665)
Correct for missing recordings list in api client. --------- Co-authored-by: Joakim Plate <elupus@ecce.se>
This commit is contained in:
parent
f1e8c1c7ee
commit
4acea82ca1
2 changed files with 29 additions and 4 deletions
|
@ -66,6 +66,8 @@ async def async_setup_entry(
|
|||
|
||||
def _check_for_recording_entry(api: PhilipsTV, entry: str, value: str) -> bool:
|
||||
"""Return True if at least one specified value is available within entry of list."""
|
||||
if api.recordings_list is None:
|
||||
return False
|
||||
for rec in api.recordings_list["recordings"]:
|
||||
if rec.get(entry) == value:
|
||||
return True
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""The tests for philips_js binary_sensor."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import STATE_ON
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import MOCK_NAME, MOCK_RECORDINGS_LIST
|
||||
|
@ -32,7 +32,16 @@ async def mock_tv_api_valid(mock_tv):
|
|||
return mock_tv
|
||||
|
||||
|
||||
async def test_recordings_list_invalid(
|
||||
@pytest.fixture
|
||||
async def mock_tv_recordings_list_unavailable(mock_tv):
|
||||
"""Set up a valid mock_tv with should create sensors."""
|
||||
mock_tv.secured_transport = True
|
||||
mock_tv.api_version = 6
|
||||
mock_tv.recordings_list = None
|
||||
return mock_tv
|
||||
|
||||
|
||||
async def test_recordings_list_api_invalid(
|
||||
mock_tv_api_invalid, mock_config_entry, hass: HomeAssistant
|
||||
) -> None:
|
||||
"""Test if sensors are not created if mock_tv is invalid."""
|
||||
|
@ -54,7 +63,21 @@ async def test_recordings_list_valid(
|
|||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
|
||||
state = hass.states.get(ID_RECORDING_AVAILABLE)
|
||||
assert state.state is STATE_ON
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get(ID_RECORDING_ONGOING)
|
||||
assert state.state is STATE_ON
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
async def test_recordings_list_unavailable(
|
||||
mock_tv_recordings_list_unavailable, mock_config_entry, hass: HomeAssistant
|
||||
) -> None:
|
||||
"""Test if sensors are created correctly."""
|
||||
|
||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
|
||||
state = hass.states.get(ID_RECORDING_AVAILABLE)
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
state = hass.states.get(ID_RECORDING_ONGOING)
|
||||
assert state.state == STATE_OFF
|
||||
|
|
Loading…
Add table
Reference in a new issue