forked from bachya/simplisafe-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_base.py
More file actions
51 lines (42 loc) · 1.81 KB
/
Copy pathtest_base.py
File metadata and controls
51 lines (42 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Define base tests for Sensor objects."""
import aiohttp
import pytest
from aresponses import ResponsesMockServer
from simplipy import API
from simplipy.device import DeviceTypes
from tests.common import TEST_AUTHORIZATION_CODE, TEST_CODE_VERIFIER, TEST_SYSTEM_ID
@pytest.mark.asyncio
async def test_properties_base(
aresponses: ResponsesMockServer,
authenticated_simplisafe_server_v2: ResponsesMockServer,
) -> None:
"""Test that base sensor properties are created properly."""
async with authenticated_simplisafe_server_v2, aiohttp.ClientSession() as session:
simplisafe = await API.async_from_auth(
TEST_AUTHORIZATION_CODE, TEST_CODE_VERIFIER, session=session
)
systems = await simplisafe.async_get_systems()
system = systems[TEST_SYSTEM_ID]
sensor = system.sensors["195"]
assert sensor.name == "Garage Keypad"
assert sensor.serial == "195"
assert sensor.type == DeviceTypes.KEYPAD
aresponses.assert_plan_strictly_followed()
@pytest.mark.asyncio
async def test_properties_base_missing_name_falls_back_to_serial(
aresponses: ResponsesMockServer,
authenticated_simplisafe_server_v3: ResponsesMockServer,
) -> None:
"""Test that name falls back to serial when the API omits the 'name' field.
Regression test for home-assistant/core#172599.
"""
async with authenticated_simplisafe_server_v3, aiohttp.ClientSession() as session:
simplisafe = await API.async_from_auth(
TEST_AUTHORIZATION_CODE, TEST_CODE_VERIFIER, session=session
)
systems = await simplisafe.async_get_systems()
system = systems[TEST_SYSTEM_ID]
sensor = system.sensors["825"]
del system.sensor_data["825"]["name"]
assert sensor.name == "825"
aresponses.assert_plan_strictly_followed()