Skip to content

Commit

Permalink
Fix Philips TV none recordings_list (#104665)
Browse files Browse the repository at this point in the history
Correct for missing recordings list in api client.
---------

Co-authored-by: Joakim Plate <elupus@ecce.se>
  • Loading branch information
Floyer007 and elupus committed Nov 29, 2023
1 parent bdf4c61 commit 7638b9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions homeassistant/components/philips_js/binary_sensor.py
Expand Up @@ -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
Expand Down
31 changes: 27 additions & 4 deletions tests/components/philips_js/test_binary_sensor.py
@@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -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 == 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 is STATE_ON
assert state.state == STATE_OFF

0 comments on commit 7638b9b

Please sign in to comment.