mirror of
https://github.com/home-assistant/core.git
synced 2025-08-06 06:05:10 +02:00
Add button test
This commit is contained in:
@@ -1,17 +1,40 @@
|
||||
"""The tests for the Ring sensor platform."""
|
||||
"""The tests for the Ring button platform."""
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import setup_platform
|
||||
|
||||
WIFI_ENABLED = False
|
||||
|
||||
async def test_entity_registry(
|
||||
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
||||
) -> None:
|
||||
"""Tests that the devices are registered in the entity registry."""
|
||||
await setup_platform(hass, Platform.BUTTON)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
entry = entity_registry.async_get("button.ingress_open_door")
|
||||
assert entry.unique_id == "185036587-open_door"
|
||||
|
||||
|
||||
async def test_sensor(hass: HomeAssistant, requests_mock: requests_mock.Mocker) -> None:
|
||||
"""Test the Ring buttons."""
|
||||
await setup_platform(hass, "button")
|
||||
async def test_button_opens_door(
|
||||
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
||||
) -> None:
|
||||
"""Tests the siren turns on correctly."""
|
||||
await setup_platform(hass, Platform.BUTTON)
|
||||
|
||||
front_door_state = hass.states.get("button.front_door_intercom_open_door")
|
||||
assert front_door_state is not None
|
||||
# Mocks the response for opening door
|
||||
mock = requests_mock.put(
|
||||
"https://api.ring.com/commands/v1/devices/185036587/device_rpc",
|
||||
status_code=200,
|
||||
text="{}",
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"button", "press", {"entity_id": "button.ingress_open_door"}, blocking=True
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert mock.called_once
|
||||
|
Reference in New Issue
Block a user