Skip to content

Commit

Permalink
Add test for unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Aug 11, 2023
1 parent cd1ea5e commit 98b4950
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 0 additions & 1 deletion custom_components/frigate/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ def available(self) -> bool:

if data:
return True

return False

@property
Expand Down
27 changes: 26 additions & 1 deletion tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
from unittest.mock import AsyncMock

import pytest
from pytest_homeassistant_custom_component.common import async_fire_mqtt_message
from pytest_homeassistant_custom_component.common import (
async_fire_mqtt_message,
async_fire_time_changed,
)

from custom_components.frigate import SCAN_INTERVAL
from custom_components.frigate.const import (
ATTR_EVENT_ID,
ATTR_FAVORITE,
Expand All @@ -31,6 +35,7 @@
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
import homeassistant.util.dt as dt_util

from . import (
TEST_CAMERA_BIRDSEYE_ENTITY_ID,
Expand All @@ -39,6 +44,7 @@
TEST_CONFIG,
TEST_CONFIG_ENTRY_ID,
TEST_SERVER_VERSION,
TEST_STATS,
create_mock_frigate_client,
create_mock_frigate_config_entry,
setup_mock_frigate_config_entry,
Expand Down Expand Up @@ -345,6 +351,25 @@ async def test_camera_disable_motion_detection(
)


async def test_camera_unavailable(hass: HomeAssistant) -> None:
"""Test that camera is marked as unavailable."""
await setup_mock_frigate_config_entry(hass)
entity_state = hass.states.get(TEST_CAMERA_FRONT_DOOR_ENTITY_ID)
assert entity_state

client = create_mock_frigate_client()
stats = copy.deepcopy(TEST_STATS)
stats["front_door"]["camera_fps"] = 0.0
client.async_get_stats = AsyncMock(return_value=stats)

async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL)
await hass.async_block_till_done()

entity_state = hass.states.get(TEST_CAMERA_FRONT_DOOR_ENTITY_ID)
assert entity_state
assert entity_state.state == "unavailable"


@pytest.mark.parametrize(
"entityid_to_uniqueid",
[
Expand Down

0 comments on commit 98b4950

Please sign in to comment.