-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0b8437
commit 785a846
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |