11"""Tests for rpc_device.device module."""
22
3- from aioshelly .rpc_device .device import mergedicts
3+ from unittest .mock import Mock
4+
5+ import pytest
6+
7+ from aioshelly .rpc_device .device import RpcDevice , mergedicts
8+
9+ VIRT_COMP_STATUS = {"value" : 0 }
10+ VIRT_COMP_CONFIG = {
11+ "id" : 200 ,
12+ "name" : "Test" ,
13+ "min" : 0 ,
14+ "max" : 100 ,
15+ "meta" : {"ui" : {"view" : "slider" , "unit" : "%" , "step" : 1 }},
16+ }
17+ VIRT_COMP_ATTRS = {"role" : "current_humidity" }
418
519
620def test_mergedicts () -> None :
@@ -9,3 +23,52 @@ def test_mergedicts() -> None:
923 source = {"b" : {"c" : 4 , "e" : 5 }}
1024 mergedicts (dest , source )
1125 assert dest == {"a" : 1 , "b" : {"c" : 4 , "d" : 3 , "e" : 5 }}
26+
27+
28+ @pytest .mark .asyncio
29+ async def test_parse_dynamic_components () -> None :
30+ """Test RPC device _parse_dynamic_components() method."""
31+ device = await RpcDevice .create (Mock (), Mock (), "10.10.10.10" )
32+
33+ device ._status = {}
34+ device ._config = {}
35+
36+ device ._parse_dynamic_components (
37+ {
38+ "components" : [
39+ {
40+ "key" : "number:200" ,
41+ "status" : VIRT_COMP_STATUS ,
42+ "config" : VIRT_COMP_CONFIG ,
43+ }
44+ ]
45+ }
46+ )
47+
48+ assert device ._status ["number:200" ] == VIRT_COMP_STATUS
49+ assert device ._config ["number:200" ] == VIRT_COMP_CONFIG
50+
51+
52+ @pytest .mark .asyncio
53+ async def test_parse_dynamic_components_with_attrs () -> None :
54+ """Test RPC device _parse_dynamic_components() method with attrs."""
55+ device = await RpcDevice .create (Mock (), Mock (), "10.10.10.10" )
56+
57+ device ._status = {}
58+ device ._config = {}
59+
60+ device ._parse_dynamic_components (
61+ {
62+ "components" : [
63+ {
64+ "key" : "number:200" ,
65+ "status" : VIRT_COMP_STATUS ,
66+ "config" : VIRT_COMP_CONFIG ,
67+ "attrs" : VIRT_COMP_ATTRS ,
68+ }
69+ ]
70+ }
71+ )
72+
73+ assert device ._status ["number:200" ] == VIRT_COMP_STATUS
74+ assert device ._config ["number:200" ] == {** VIRT_COMP_CONFIG , ** VIRT_COMP_ATTRS }
0 commit comments