Skip to content

Commit

Permalink
Add tests for remote entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgruter committed Nov 2, 2023
1 parent f0b8437 commit 785a846
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Empty file added tests/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from homeassistant.core import HomeAssistant
from pytest_homeassistant_custom_component.common import Mock
import unfoldedcircle.device as uc

from custom_components.unfoldedcircle.remote import UCRemoteTwoRemote


async def test_state_always_on():
"""Tests a failed async_update."""
device = Mock()
device.unique_id = "foo"
api = Mock()
api.endpoint = "bar"

remote = UCRemoteTwoRemote(device, api)
assert remote.state == "on"
assert remote.activity_list is None


async def test_async_update(hass: HomeAssistant):
"""Tests an async_update."""
test_activities = ["Watch TV", "Listen to Spotify"]
device = Mock()
device.unique_id = "foo"
api = Mock()
api.endpoint = "bar"
api.fetch_activities = Mock(
return_value=[{"name": {"en": a}} for a in test_activities]
)
remote = UCRemoteTwoRemote(device, api)
remote.hass = hass

await remote.async_update()
assert remote.activity_list == test_activities


async def test_async_update_failed(hass: HomeAssistant):
"""Tests a failed async_update."""
device = Mock()
device.unique_id = "foo"
api = Mock()
api.endpoint = "bar"
api.fetch_activities = Mock(side_effect=uc.HTTPError("mock error"))
remote = UCRemoteTwoRemote(device, api)
remote.hass = hass

await remote.async_update()
assert remote.available is False

0 comments on commit 785a846

Please sign in to comment.