2019-08-06 21:55:54 +00:00
|
|
|
"""The tests for the Ring light platform."""
|
|
|
|
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
2019-12-09 10:58:40 +00:00
|
|
|
|
2019-08-06 21:55:54 +00:00
|
|
|
from .common import setup_platform
|
|
|
|
|
2019-12-09 10:58:40 +00:00
|
|
|
from tests.common import load_fixture
|
|
|
|
|
2019-08-06 21:55:54 +00:00
|
|
|
|
|
|
|
async def test_entity_registry(hass, requests_mock):
|
2020-01-31 16:33:00 +00:00
|
|
|
"""Tests that the devices are registered in the entity registry."""
|
2019-08-06 21:55:54 +00:00
|
|
|
await setup_platform(hass, LIGHT_DOMAIN)
|
|
|
|
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
|
|
|
|
|
|
|
entry = entity_registry.async_get("light.front_light")
|
2020-01-14 20:54:45 +00:00
|
|
|
assert entry.unique_id == 765432
|
2019-08-06 21:55:54 +00:00
|
|
|
|
|
|
|
entry = entity_registry.async_get("light.internal_light")
|
2020-01-14 20:54:45 +00:00
|
|
|
assert entry.unique_id == 345678
|
2019-08-06 21:55:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_light_off_reports_correctly(hass, requests_mock):
|
|
|
|
"""Tests that the initial state of a device that should be off is correct."""
|
|
|
|
await setup_platform(hass, LIGHT_DOMAIN)
|
|
|
|
|
|
|
|
state = hass.states.get("light.front_light")
|
|
|
|
assert state.state == "off"
|
|
|
|
assert state.attributes.get("friendly_name") == "Front light"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_on_reports_correctly(hass, requests_mock):
|
|
|
|
"""Tests that the initial state of a device that should be on is correct."""
|
|
|
|
await setup_platform(hass, LIGHT_DOMAIN)
|
|
|
|
|
|
|
|
state = hass.states.get("light.internal_light")
|
|
|
|
assert state.state == "on"
|
|
|
|
assert state.attributes.get("friendly_name") == "Internal light"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_can_be_turned_on(hass, requests_mock):
|
|
|
|
"""Tests the light turns on correctly."""
|
|
|
|
await setup_platform(hass, LIGHT_DOMAIN)
|
|
|
|
|
|
|
|
# Mocks the response for turning a light on
|
|
|
|
requests_mock.put(
|
2020-01-14 20:54:45 +00:00
|
|
|
"https://api.ring.com/clients_api/doorbots/765432/floodlight_light_on",
|
2019-08-06 21:55:54 +00:00
|
|
|
text=load_fixture("ring_doorbot_siren_on_response.json"),
|
|
|
|
)
|
|
|
|
|
|
|
|
state = hass.states.get("light.front_light")
|
|
|
|
assert state.state == "off"
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"light", "turn_on", {"entity_id": "light.front_light"}, blocking=True
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
state = hass.states.get("light.front_light")
|
|
|
|
assert state.state == "on"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_updates_work(hass, requests_mock):
|
|
|
|
"""Tests the update service works correctly."""
|
|
|
|
await setup_platform(hass, LIGHT_DOMAIN)
|
|
|
|
state = hass.states.get("light.front_light")
|
|
|
|
assert state.state == "off"
|
|
|
|
# Changes the return to indicate that the light is now on.
|
|
|
|
requests_mock.get(
|
|
|
|
"https://api.ring.com/clients_api/ring_devices",
|
|
|
|
text=load_fixture("ring_devices_updated.json"),
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.services.async_call("ring", "update", {}, blocking=True)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
state = hass.states.get("light.front_light")
|
|
|
|
assert state.state == "on"
|