Update Ring to 0.6.0 (#30748)
* Update Ring to 0.6.0 * Update sensor tests * update -> async_update * Delete temp files * Address comments * Final tweaks * Remove stale print
This commit is contained in:
parent
ba3c3057da
commit
c4673ddee1
19 changed files with 417 additions and 418 deletions
|
@ -1,122 +1,46 @@
|
|||
"""The tests for the Ring sensor platform."""
|
||||
from asyncio import run_coroutine_threadsafe
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from .common import setup_platform
|
||||
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.components import ring as base_ring
|
||||
import homeassistant.components.ring.sensor as ring
|
||||
from homeassistant.helpers.icon import icon_for_battery_level
|
||||
|
||||
from tests.common import get_test_home_assistant, load_fixture, mock_storage
|
||||
from tests.components.ring.test_init import ATTRIBUTION, VALID_CONFIG
|
||||
WIFI_ENABLED = False
|
||||
|
||||
|
||||
class TestRingSensorSetup(unittest.TestCase):
|
||||
"""Test the Ring platform."""
|
||||
async def test_sensor(hass, requests_mock):
|
||||
"""Test the Ring sensors."""
|
||||
await setup_platform(hass, "sensor")
|
||||
|
||||
DEVICES = []
|
||||
front_battery_state = hass.states.get("sensor.front_battery")
|
||||
assert front_battery_state is not None
|
||||
assert front_battery_state.state == "80"
|
||||
|
||||
def add_entities(self, devices, action):
|
||||
"""Mock add devices."""
|
||||
for device in devices:
|
||||
self.DEVICES.append(device)
|
||||
front_door_battery_state = hass.states.get("sensor.front_door_battery")
|
||||
assert front_door_battery_state is not None
|
||||
assert front_door_battery_state.state == "100"
|
||||
|
||||
def setUp(self):
|
||||
"""Initialize values for this testcase class."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.config = {
|
||||
"username": "foo",
|
||||
"password": "bar",
|
||||
"monitored_conditions": [
|
||||
"battery",
|
||||
"last_activity",
|
||||
"last_ding",
|
||||
"last_motion",
|
||||
"volume",
|
||||
"wifi_signal_category",
|
||||
"wifi_signal_strength",
|
||||
],
|
||||
}
|
||||
downstairs_volume_state = hass.states.get("sensor.downstairs_volume")
|
||||
assert downstairs_volume_state is not None
|
||||
assert downstairs_volume_state.state == "2"
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
front_door_last_activity_state = hass.states.get("sensor.front_door_last_activity")
|
||||
assert front_door_last_activity_state is not None
|
||||
|
||||
@requests_mock.Mocker()
|
||||
def test_sensor(self, mock):
|
||||
"""Test the Ring sensor class and methods."""
|
||||
mock.post(
|
||||
"https://oauth.ring.com/oauth/token", text=load_fixture("ring_oauth.json")
|
||||
)
|
||||
mock.post(
|
||||
"https://api.ring.com/clients_api/session",
|
||||
text=load_fixture("ring_session.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/ring_devices",
|
||||
text=load_fixture("ring_devices.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/doorbots/987652/history",
|
||||
text=load_fixture("ring_doorbots.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/doorbots/987652/health",
|
||||
text=load_fixture("ring_doorboot_health_attrs.json"),
|
||||
)
|
||||
mock.get(
|
||||
"https://api.ring.com/clients_api/chimes/999999/health",
|
||||
text=load_fixture("ring_chime_health_attrs.json"),
|
||||
)
|
||||
downstairs_wifi_signal_strength_state = hass.states.get(
|
||||
"sensor.downstairs_wifi_signal_strength"
|
||||
)
|
||||
|
||||
with mock_storage(), patch("homeassistant.components.ring.PLATFORMS", []):
|
||||
run_coroutine_threadsafe(
|
||||
base_ring.async_setup(self.hass, VALID_CONFIG), self.hass.loop
|
||||
).result()
|
||||
run_coroutine_threadsafe(
|
||||
self.hass.async_block_till_done(), self.hass.loop
|
||||
).result()
|
||||
run_coroutine_threadsafe(
|
||||
ring.async_setup_entry(self.hass, None, self.add_entities),
|
||||
self.hass.loop,
|
||||
).result()
|
||||
if not WIFI_ENABLED:
|
||||
return
|
||||
|
||||
for device in self.DEVICES:
|
||||
# Mimick add to hass
|
||||
device.hass = self.hass
|
||||
run_coroutine_threadsafe(
|
||||
device.async_added_to_hass(), self.hass.loop,
|
||||
).result()
|
||||
assert downstairs_wifi_signal_strength_state is not None
|
||||
assert downstairs_wifi_signal_strength_state.state == "-39"
|
||||
|
||||
# Entity update data from ring data
|
||||
device.update()
|
||||
if device.name == "Front Battery":
|
||||
expected_icon = icon_for_battery_level(
|
||||
battery_level=int(device.state), charging=False
|
||||
)
|
||||
assert device.icon == expected_icon
|
||||
assert 80 == device.state
|
||||
if device.name == "Front Door Battery":
|
||||
assert 100 == device.state
|
||||
if device.name == "Downstairs Volume":
|
||||
assert 2 == device.state
|
||||
assert "ring_mock_wifi" == device.device_state_attributes["wifi_name"]
|
||||
assert "mdi:bell-ring" == device.icon
|
||||
if device.name == "Front Door Last Activity":
|
||||
assert not device.device_state_attributes["answered"]
|
||||
assert "America/New_York" == device.device_state_attributes["timezone"]
|
||||
front_door_wifi_signal_category_state = hass.states.get(
|
||||
"sensor.front_door_wifi_signal_category"
|
||||
)
|
||||
assert front_door_wifi_signal_category_state is not None
|
||||
assert front_door_wifi_signal_category_state.state == "good"
|
||||
|
||||
if device.name == "Downstairs WiFi Signal Strength":
|
||||
assert -39 == device.state
|
||||
|
||||
if device.name == "Front Door WiFi Signal Category":
|
||||
assert "good" == device.state
|
||||
|
||||
if device.name == "Front Door WiFi Signal Strength":
|
||||
assert -58 == device.state
|
||||
|
||||
assert device.entity_picture is None
|
||||
assert ATTRIBUTION == device.device_state_attributes["attribution"]
|
||||
assert not device.should_poll
|
||||
front_door_wifi_signal_strength_state = hass.states.get(
|
||||
"sensor.front_door_wifi_signal_strength"
|
||||
)
|
||||
assert front_door_wifi_signal_strength_state is not None
|
||||
assert front_door_wifi_signal_strength_state.state == "-58"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue