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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788
|
"""Test the node model."""
import asyncio
from copy import deepcopy
from datetime import UTC, datetime
import json
from typing import Any
from unittest.mock import AsyncMock, patch
import pytest
from zwave_js_server.const import (
INTERVIEW_FAILED,
CommandClass,
CommandStatus,
NodeStatus,
PowerLevel,
ProtocolDataRate,
ProtocolVersion,
Protocols,
RFRegion,
SecurityClass,
SupervisionStatus,
Weekday,
)
from zwave_js_server.const.command_class.entry_control import (
EntryControlDataType,
EntryControlEventType,
)
from zwave_js_server.const.command_class.multilevel_switch import (
MultilevelSwitchCommand,
)
from zwave_js_server.const.command_class.power_level import PowerLevelTestStatus
from zwave_js_server.event import Event
from zwave_js_server.exceptions import (
FailedCommand,
NotFoundError,
RssiErrorReceived,
UnwriteableValue,
)
from zwave_js_server.model import endpoint as endpoint_pkg, node as node_pkg
from zwave_js_server.model.node import Node
from zwave_js_server.model.node.firmware import (
NodeFirmwareUpdateInfo,
NodeFirmwareUpdateStatus,
)
from zwave_js_server.model.node.health_check import (
LifelineHealthCheckResultDataType,
RouteHealthCheckResultDataType,
)
from zwave_js_server.model.node.statistics import NodeStatistics
from zwave_js_server.model.value import (
ConfigurationValue,
ConfigurationValueFormat,
SetConfigParameterResult,
get_value_id_str,
)
from .. import load_fixture
# pylint: disable=unused-argument
FIRMWARE_UPDATE_INFO = {
"version": "1.0.0",
"changelog": "changelog",
"channel": "stable",
"files": [{"target": 0, "url": "http://example.com", "integrity": "test"}],
"downgrade": True,
"normalizedVersion": "1.0.0",
"device": {
"manufacturerId": 1,
"productType": 2,
"productId": 3,
"firmwareVersion": "0.4.4",
"rfRegion": 1,
},
}
def test_firmware():
"""Test NodeFirmwareUpdateInfo."""
firmware_update_info = NodeFirmwareUpdateInfo.from_dict(FIRMWARE_UPDATE_INFO)
assert firmware_update_info.version == "1.0.0"
assert firmware_update_info.changelog == "changelog"
assert firmware_update_info.channel == "stable"
assert len(firmware_update_info.files) == 1
assert firmware_update_info.files[0].target == 0
assert firmware_update_info.files[0].url == "http://example.com"
assert firmware_update_info.files[0].integrity == "test"
assert firmware_update_info.downgrade
assert firmware_update_info.normalized_version == "1.0.0"
assert firmware_update_info.device.manufacturer_id == 1
assert firmware_update_info.device.product_type == 2
assert firmware_update_info.device.product_id == 3
assert firmware_update_info.device.firmware_version == "0.4.4"
assert firmware_update_info.device.rf_region == RFRegion.USA
assert firmware_update_info.to_dict() == FIRMWARE_UPDATE_INFO
def test_from_state(client):
"""Test from_state method."""
state = json.loads(load_fixture("basic_dump.txt").split("\n")[0])["result"]["state"]
node = node_pkg.Node(client, state["nodes"][0])
assert node.node_id == 1
assert node.index == 0
assert node.status == 4
assert node.ready is True
assert node.device_class.basic.key == 2
assert node.device_class.generic.label == "Static Controller"
assert node.is_listening is True
assert node.is_frequent_listening is False
assert node.is_routing is False
assert node.max_data_rate == 100000
assert node.supported_data_rates == [40000, 100000]
assert node.is_secure is False
assert node.protocol is None
assert node.protocol_version == ProtocolVersion.VERSION_4_5X_OR_6_0X
assert node.supports_beaming is True
assert node.supports_security is False
assert node.zwave_plus_node_type is None
assert node.zwave_plus_role_type is None
assert node.manufacturer_id == 134
assert node.product_id == 90
assert node.product_type == 257
assert node.label == "ZW090"
assert node.interview_attempts == 0
assert node.installer_icon is None
assert node.user_icon is None
assert node.firmware_version is None
assert node.name is None
assert node.zwave_plus_version is None
assert node.location is None
assert node.endpoint_count_is_dynamic is None
assert node.endpoints_have_identical_capabilities is None
assert node.individual_endpoint_count is None
assert node.aggregated_endpoint_count is None
assert node.interview_stage == "Neighbors"
assert not node.is_controller_node
assert not node.keep_awake
assert len(node.command_classes) == 0
assert len(node.endpoints) == 1
assert node.endpoints[0].index == 0
assert node.endpoints[0].installer_icon is None
assert node.endpoints[0].user_icon is None
assert node.endpoints[0].command_classes == []
assert node.endpoints[0].endpoint_label is None
device_class = node.endpoints[0].device_class
assert device_class.basic.key == 2
assert device_class.generic.key == 2
assert device_class.specific.key == 1
stats = node.statistics
assert (
stats.commands_dropped_rx
== stats.commands_dropped_tx
== stats.commands_rx
== stats.commands_tx
== stats.timeout_response
== 0
)
assert node == node_pkg.Node(client, state["nodes"][0])
assert node != node.node_id
assert hash(node) == hash((client.driver, node.node_id))
assert node.endpoints[0] == endpoint_pkg.Endpoint(
client, node, state["nodes"][0]["endpoints"][0], {}
)
assert node.endpoints[0] != node.endpoints[0].index
assert hash(node.endpoints[0]) == hash((client.driver, node.node_id, 0))
assert node.last_seen is None
event = Event(
"statistics updated",
{
"source": "node",
"event": "statistics updated",
"nodeId": node.node_id,
"statistics": {
"commandsTX": 1,
"commandsRX": 2,
"commandsDroppedTX": 3,
"commandsDroppedRX": 4,
"timeoutResponse": 5,
"rssi": 7,
"lastSeen": "2023-07-18T15:42:34.701Z",
},
},
)
node.receive_event(event)
assert node.last_seen == datetime(2023, 7, 18, 15, 42, 34, 701000, UTC)
async def test_last_seen(lock_schlage_be469):
"""Test last seen property."""
assert lock_schlage_be469.last_seen == datetime(
2023, 7, 18, 15, 42, 34, 701000, UTC
)
assert (
lock_schlage_be469.last_seen
== lock_schlage_be469.statistics.last_seen
== datetime.fromisoformat(lock_schlage_be469.statistics.data.get("lastSeen"))
)
async def test_highest_security_value(lock_schlage_be469, ring_keypad):
"""Test the highest_security_class property."""
assert lock_schlage_be469.highest_security_class == SecurityClass.S0_LEGACY
assert ring_keypad.highest_security_class is None
async def test_command_classes(endpoints_with_command_classes: Node) -> None:
"""Test command_classes property on endpoint."""
node = endpoints_with_command_classes
assert len(node.endpoints[0].command_classes) == 17
command_class_info = node.endpoints[0].command_classes[0]
assert command_class_info.id == 38
assert command_class_info.command_class == CommandClass.SWITCH_MULTILEVEL
assert command_class_info.name == "Multilevel Switch"
assert command_class_info.version == 2
assert command_class_info.is_secure is False
assert command_class_info.to_dict() == command_class_info.data
async def test_device_config(
wallmote_central_scene, climate_radio_thermostat_ct100_plus
):
"""Test a device config."""
node: node_pkg.Node = wallmote_central_scene
device_config = node.device_config
assert device_config.is_embedded
assert device_config.filename == (
"/usr/src/app/node_modules/@zwave-js/config/config/devices/0x0086/zw130.json"
)
assert device_config.manufacturer == "AEON Labs"
assert device_config.manufacturer_id == 134
assert device_config.label == "ZW130"
assert device_config.description == "WallMote Quad"
assert len(device_config.devices) == 3
assert device_config.devices[0].product_id == 130
assert device_config.devices[0].product_type == 2
assert device_config.firmware_version.min == "0.0"
assert device_config.firmware_version.max == "255.255"
assert device_config.metadata.inclusion == (
"To add the ZP3111 to the Z-Wave network (inclusion), place the Z-Wave "
"primary controller into inclusion mode. Press the Program Switch of ZP3111 "
"for sending the NIF. After sending NIF, Z-Wave will send the auto inclusion, "
"otherwise, ZP3111 will go to sleep after 20 seconds."
)
assert device_config.metadata.exclusion == (
"To remove the ZP3111 from the Z-Wave network (exclusion), place the Z-Wave "
"primary controller into \u201cexclusion\u201d mode, and following its "
"instruction to delete the ZP3111 to the controller. Press the Program Switch "
"of ZP3111 once to be excluded."
)
assert device_config.metadata.reset == (
"Remove cover to trigged tamper switch, LED flash once & send out Alarm "
"Report. Press Program Switch 10 times within 10 seconds, ZP3111 will send "
"the \u201cDevice Reset Locally Notification\u201d command and reset to the "
"factory default. (Remark: This is to be used only in the case of primary "
"controller being inoperable or otherwise unavailable.)"
)
assert device_config.metadata.manual == (
"https://products.z-wavealliance.org/ProductManual/File?folder=&filename="
"MarketCertificationFiles/2479/ZP3111-5_R2_20170316.pdf"
)
assert device_config.metadata.wakeup is None
assert device_config.metadata.comments == [{"level": "info", "text": "test"}]
assert device_config.associations == {}
assert device_config.param_information == {"_map": {}}
assert device_config.supports_zwave_plus is None
assert climate_radio_thermostat_ct100_plus.device_config.metadata.comments == []
async def test_protocol(client, wallmote_central_scene_state):
"""Test protocol of a node."""
node_state = deepcopy(wallmote_central_scene_state)
node_state["protocol"] = 0
node = node_pkg.Node(client, node_state)
assert node.protocol is Protocols.ZWAVE
async def test_endpoint_no_device_class(climate_radio_thermostat_ct100_plus):
"""Test endpoint without a device class."""
assert climate_radio_thermostat_ct100_plus.endpoints[0].device_class is None
async def test_unknown_values(cover_qubino_shutter):
"""Test that values that are unknown return as None."""
node = cover_qubino_shutter
assert (
"5-38-0-currentValue" in node.values
and node.values["5-38-0-currentValue"].value is None
)
assert (
"5-37-0-currentValue" in node.values
and node.values["5-37-0-currentValue"].value is None
)
async def test_device_database_url(cover_qubino_shutter):
"""Test that the device database URL is available."""
assert (
cover_qubino_shutter.device_database_url
== "https://devices.zwave-js.io/?jumpTo=0x0159:0x0003:0x0053:0.0"
)
async def test_values_without_property_key_name(multisensor_6):
"""Test that values with property key and without property key name can be found."""
node = multisensor_6
assert "52-112-0-101-1" in node.values
assert "52-112-0-101-16" in node.values
async def test_hash(climate_radio_thermostat_ct100_plus):
"""Test node hash."""
node = climate_radio_thermostat_ct100_plus
assert hash(node) == hash((node.client.driver, node.node_id))
async def test_command_class_values(climate_radio_thermostat_ct100_plus):
"""Test node methods to get command class values."""
node = climate_radio_thermostat_ct100_plus
assert node.node_id == 13
switch_values = node.get_command_class_values(CommandClass.SENSOR_MULTILEVEL)
assert len(switch_values) == 2
with pytest.raises(UnwriteableValue):
await node.async_set_value("13-112-0-2", 1)
async def test_set_value(multisensor_6, uuid4, mock_command):
"""Test set value."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.set_value", "nodeId": node.node_id},
{"success": True},
)
value_id = "52-32-0-targetValue"
assert await node.async_set_value(value_id, 42) is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_value",
"nodeId": node.node_id,
"valueId": {"commandClass": 32, "endpoint": 0, "property": "targetValue"},
"value": 42,
"messageId": uuid4,
}
# Set value with options
assert await node.async_set_value(value_id, 42, {"transitionDuration": 1}) is None
assert len(ack_commands) == 2
assert ack_commands[1] == {
"command": "node.set_value",
"nodeId": node.node_id,
"valueId": {"commandClass": 32, "endpoint": 0, "property": "targetValue"},
"value": 42,
"options": {"transitionDuration": 1},
"messageId": uuid4,
}
# Set value with illegal option
with pytest.raises(NotFoundError):
await node.async_set_value(value_id, 42, {"fake_option": 1})
# Use invalid value
with pytest.raises(NotFoundError):
await node.async_set_value(f"{value_id}_fake_value", 42)
async def test_set_value_node_status_change(driver, multisensor_6_state):
"""Test set value when node status changes."""
async def async_send_command(
message: dict[str, Any], require_schema: int | None = None
) -> dict:
"""Send a mock command that never returns."""
block_event = asyncio.Event()
await block_event.wait()
with patch("zwave_js_server.client.Client", autospec=True) as client_class:
client = client_class.return_value
client.driver = driver
client.async_send_command = AsyncMock(side_effect=async_send_command)
node = node_pkg.Node(client, multisensor_6_state)
# wake up node
event = Event(type="wake up")
node.handle_wake_up(event)
task = asyncio.create_task(node.async_send_command("mock_cmd"))
task_2 = asyncio.create_task(node.endpoints[0].async_send_command("mock_cmd"))
await asyncio.sleep(0.01)
# we are waiting for the response
assert not task.done()
assert not task_2.done()
# node goes to sleep
event = Event(type="sleep")
node.handle_sleep(event)
await asyncio.sleep(0.01)
# we are no longer waiting for the response
assert task.done()
assert task.result() is None
assert task_2.done()
assert task_2.result() is None
# mark node as alive
event = Event(type="alive")
node.handle_alive(event)
task = asyncio.create_task(node.async_send_command("mock_cmd"))
task_2 = asyncio.create_task(node.endpoints[0].async_send_command("mock_cmd"))
await asyncio.sleep(0.01)
# we are waiting for the response
assert not task.done()
assert not task_2.done()
# node is marked dead
event = Event(type="dead")
node.handle_dead(event)
await asyncio.sleep(0.01)
# we are no longer waiting for the response
assert task.done()
assert task.result() is None
assert task_2.done()
assert task_2.result() is None
async def test_poll_value(multisensor_6, uuid4, mock_command):
"""Test poll value."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.poll_value", "nodeId": node.node_id},
{"result": "something"},
)
value_id = "52-32-0-currentValue"
assert await node.async_poll_value(value_id) is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.poll_value",
"nodeId": node.node_id,
"valueId": {"commandClass": 32, "endpoint": 0, "property": "currentValue"},
"messageId": uuid4,
}
async def test_ping(multisensor_6, uuid4, mock_command):
"""Test ping."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.ping", "nodeId": node.node_id},
{"responded": True},
)
assert await node.async_ping()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.ping",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_refresh_info(multisensor_6, uuid4, mock_command):
"""Test refresh info."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.refresh_info", "nodeId": node.node_id},
{},
)
assert await node.async_refresh_info() is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.refresh_info",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_value_added_event(multisensor_6):
"""Test Node value removed event."""
node = multisensor_6
assert "52-112-0-2" in node.values
event = Event(
type="value removed",
data={
"source": "node",
"event": "value removed",
"nodeId": 52,
"args": {
"commandClassName": "Configuration",
"commandClass": 112,
"endpoint": 0,
"property": 2,
"propertyName": "Stay Awake in Battery Mode",
"metadata": {
"type": "number",
"readable": True,
"writeable": True,
"valueSize": 1,
"min": 0,
"max": 1,
"default": 0,
"format": 0,
"allowManualEntry": False,
"states": {"0": "Disable", "1": "Enable"},
"label": "Stay Awake in Battery Mode",
"description": "Stay awake for 10 minutes at power on",
"isFromConfig": True,
},
"value": 0,
},
},
)
node.handle_value_removed(event)
assert "52-112-0-2" not in node.values
async def test_get_defined_value_ids(multisensor_6, uuid4, mock_command):
"""Test get defined value ids."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_defined_value_ids", "nodeId": node.node_id},
{
"valueIds": [
{
"commandClassName": "Wake Up",
"commandClass": 132,
"endpoint": 0,
"property": "wakeUpInterval",
"propertyName": "wakeUpInterval",
},
{
"commandClassName": "Wake Up",
"commandClass": 132,
"endpoint": 0,
"property": "controllerNodeId",
"propertyName": "controllerNodeId",
},
]
},
)
result = await node.async_get_defined_value_ids()
assert len(result) == 2
assert result[0].command_class_name == "Wake Up"
assert result[0].command_class == 132
assert result[0].endpoint == 0
assert result[0].property_ == "wakeUpInterval"
assert result[0].property_name == "wakeUpInterval"
assert result[1].command_class_name == "Wake Up"
assert result[1].command_class == 132
assert result[1].endpoint == 0
assert result[1].property_ == "controllerNodeId"
assert result[1].property_name == "controllerNodeId"
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_defined_value_ids",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_get_value_metadata(multisensor_6, uuid4, mock_command):
"""Test get value metadata."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_value_metadata", "nodeId": node.node_id},
{
"type": "any",
"readable": True,
"writeable": False,
"label": "Node ID of the controller",
"description": "Description of the value metadata",
},
)
result = await node.async_get_value_metadata("52-32-0-targetValue")
assert result.type == "any"
assert result.readable is True
assert result.writeable is False
assert result.label == "Node ID of the controller"
assert result.description == "Description of the value metadata"
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_value_metadata",
"nodeId": node.node_id,
"valueId": {"commandClass": 32, "endpoint": 0, "property": "targetValue"},
"messageId": uuid4,
}
ack_commands.clear()
async def test_abort_firmware_update(multisensor_6, uuid4, mock_command):
"""Test abort firmware update."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.abort_firmware_update", "nodeId": node.node_id},
{},
)
assert await node.async_abort_firmware_update() is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.abort_firmware_update",
"nodeId": node.node_id,
"messageId": uuid4,
}
def test_node_inclusion(multisensor_6_state):
"""Emulate a node being added."""
# when a node node is added, it has minimal info first
node = node_pkg.Node(
None, {"nodeId": 52, "status": 1, "ready": False, "values": [], "endpoints": []}
)
assert node.node_id == 52
assert node.status == 1
assert not node.ready
assert len(node.values) == 0
assert node.device_config.manufacturer is None
# the ready event contains a full (and complete) dump of the node, including values
event = Event(
"ready",
{
"event": "ready",
"source": "node",
"nodeId": node.node_id,
"nodeState": multisensor_6_state,
"result": [],
},
)
node.receive_event(event)
assert node.device_config.manufacturer == "AEON Labs"
assert len(node.values) > 0
new_state = deepcopy(multisensor_6_state)
new_state["values"].append(
{
"commandClassName": "Binary Sensor",
"commandClass": 48,
"endpoint": 0,
"property": "test",
"propertyName": "test",
"metadata": {
"type": "boolean",
"readable": True,
"writeable": False,
"label": "Any",
"ccSpecific": {"sensorType": 255},
},
"value": False,
}
)
new_state["endpoints"].append(
{"nodeId": 52, "index": 1, "installerIcon": 3079, "userIcon": 3079}
)
event = Event(
"ready",
{
"event": "ready",
"source": "node",
"nodeId": node.node_id,
"nodeState": new_state,
"result": [],
},
)
node.receive_event(event)
assert "52-48-0-test" in node.values
assert 1 in node.endpoints
new_state = deepcopy(new_state)
new_state["endpoints"].pop(1)
event = Event(
"ready",
{
"event": "ready",
"source": "node",
"nodeId": node.node_id,
"nodeState": multisensor_6_state,
"result": [],
},
)
node.receive_event(event)
assert 1 not in node.endpoints
def test_node_ready_event(switch_enbrighten_zw3010_state):
"""Emulate a node ready event."""
# when a node node is added, it has minimal info first
node = node_pkg.Node(
None, {"nodeId": 2, "status": 1, "ready": False, "values": [], "endpoints": []}
)
assert node.node_id == 2
assert node.status == 1
assert not node.ready
assert len(node.values) == 0
assert node.device_config.manufacturer is None
# the ready event contains a full (and complete) dump of the node, including values
event = Event(
"ready",
{
"event": "ready",
"source": "node",
"nodeId": node.node_id,
"nodeState": switch_enbrighten_zw3010_state,
"result": [],
},
)
# This will fail if the schema is invalid
node.receive_event(event)
assert len(node.values) > 0
async def test_node_status_events(multisensor_6):
"""Test Node status events."""
node = multisensor_6
assert node.status == NodeStatus.ASLEEP
# mock node wake up event
event = Event(type="wake up")
node.handle_wake_up(event)
assert node.status == NodeStatus.AWAKE
# mock node dead event
event = Event(type="dead")
node.handle_dead(event)
assert node.status == NodeStatus.DEAD
# mock node alive event
event = Event(type="alive")
node.handle_alive(event)
assert node.status == NodeStatus.ALIVE
# mock node sleep event
event = Event(type="sleep")
node.handle_sleep(event)
assert node.status == NodeStatus.ASLEEP
async def test_value_added_events(multisensor_6):
"""Test Node value added events for new value."""
node = multisensor_6
value_id = "52-112-0-6"
# Validate that the value doesn't exist in the node state data
assert value_id not in node.values
event = Event(
type="value added",
data={
"source": "node",
"event": "value added",
"nodeId": 52,
"args": {
"commandClassName": "Configuration",
"commandClass": 112,
"endpoint": 0,
"property": 6,
"propertyName": "Stay Awake in Battery Mode",
"metadata": {
"type": "number",
"readable": True,
"writeable": True,
"valueSize": 1,
"min": 0,
"max": 1,
"default": 0,
"format": 0,
"allowManualEntry": False,
"states": {"0": "Disable", "1": "Enable"},
"label": "Stay Awake in Battery Mode",
"description": "Stay awake for 10 minutes at power on",
"isFromConfig": True,
},
"value": 0,
},
},
)
node.handle_value_added(event)
assert isinstance(event.data["value"], ConfigurationValue)
assert isinstance(node.values[value_id], ConfigurationValue)
# ensure that the value was added to the node's state data
assert value_id in node.values
async def test_value_updated_events(multisensor_6):
"""Test Node value updated events."""
node = multisensor_6
value_id = "52-112-0-2"
# ensure that the value is in the node's state data
assert value_id in node.values
# assert the old value of the ZwaveValue
assert (value_data := node.values[value_id].data) is not None
assert value_data["value"] == node.values[value_id].value == 0
event = Event(
type="value updated",
data={
"source": "node",
"event": "value updated",
"nodeId": 52,
"args": {
"commandClassName": "Configuration",
"commandClass": 112,
"endpoint": 0,
"property": 2,
"propertyName": "Stay Awake in Battery Mode",
"value": -1,
"newValue": 1,
"prevValue": 0,
},
},
)
node.handle_value_updated(event)
assert isinstance(event.data["value"], ConfigurationValue)
assert isinstance(node.values[value_id], ConfigurationValue)
# ensure that the value is in to the node's state data
assert value_id in node.values
# ensure that the node's state data was updated and that old keys were removed
assert (value_data := node.values[value_id].data) is not None
assert value_data["metadata"]
assert value_data["value"] == 1
assert "newValue" not in value_data
assert "prevValue" not in value_data
# ensure that the value's state data was updated and that old keys were removed
val = node.values[value_id]
assert val.data["value"] == 1
assert val.value == 1
assert "newValue" not in val.data
assert "prevValue" not in val.data
async def test_value_removed_events(multisensor_6):
"""Test Node value removed events."""
node = multisensor_6
value_id = "52-112-0-2"
event = Event(
type="value removed",
data={
"source": "node",
"event": "value removed",
"nodeId": 52,
"args": {
"commandClassName": "Configuration",
"commandClass": 112,
"endpoint": 0,
"property": 2,
"propertyName": "Stay Awake in Battery Mode",
"prevValue": 0,
},
},
)
node.handle_value_removed(event)
assert isinstance(event.data["value"], ConfigurationValue)
# ensure that the value was removed from the nodes value's dict
assert node.values.get(value_id) is None
# ensure that the value was removed from the node's state data
assert value_id not in node.values
async def test_value_notification(wallmote_central_scene: node_pkg.Node):
"""Test value notification events."""
node = wallmote_central_scene
# Validate that metadata gets added to notification when it's not included
event = Event(
type="value notification",
data={
"source": "node",
"event": "value notification",
"nodeId": 35,
"args": {
"commandClass": 91,
"commandClassName": "Central Scene",
"property": "scene",
"propertyKey": "002",
"propertyName": "scene",
"propertyKeyName": "002",
"ccVersion": 2,
"value": 1,
},
},
)
node.handle_value_notification(event)
assert event.data["value_notification"].metadata.states
assert event.data["value_notification"].endpoint is not None
assert event.data["value_notification"].value == 1
# Let's make sure that the Value was not updated by the value notification event
assert node.values["35-91-0-scene-002"].value is None
# Validate that a value notification event for an unknown value gets returned as is
event = Event(
type="value notification",
data={
"source": "node",
"event": "value notification",
"nodeId": 35,
"args": {
"commandClass": 91,
"commandClassName": "Central Scene",
"property": "scene",
"propertyKey": "005",
"propertyName": "scene",
"propertyKeyName": "005",
"ccVersion": 2,
"value": 2,
},
},
)
node.handle_value_notification(event)
assert event.data["value_notification"].command_class == 91
assert event.data["value_notification"].command_class_name == "Central Scene"
assert event.data["value_notification"].property_ == "scene"
assert event.data["value_notification"].property_name == "scene"
assert event.data["value_notification"].property_key == "005"
assert event.data["value_notification"].property_key_name == "005"
assert event.data["value_notification"].value == 2
async def test_metadata_updated(climate_radio_thermostat_ct100_plus: node_pkg.Node):
"""Test metadata updated events."""
node = climate_radio_thermostat_ct100_plus
value = node.values["13-135-1-value"]
assert not value.metadata.states
# Validate that states becomes available on a value that doesn't have a state when
# a metadata updated event with states is received
event = Event(
type="value notification",
data={
"source": "node",
"event": "metadata updated",
"nodeId": 13,
"args": {
"commandClassName": "Indicator",
"commandClass": 135,
"endpoint": 1,
"property": "value",
"propertyName": "value",
"metadata": {
"type": "number",
"readable": True,
"writeable": True,
"min": 0,
"max": 255,
"label": "Indicator value",
"ccSpecific": {"indicatorId": 0},
"states": {
"0": "Idle",
"1": "Heating",
"2": "Cooling",
"3": "Fan Only",
"4": "Pending Heat",
"5": "Pending Cool",
"6": "Vent/Economizer",
"7": "Aux Heating",
"8": "2nd Stage Heating",
"9": "2nd Stage Cooling",
"10": "2nd Stage Aux Heat",
"11": "3rd Stage Aux Heat",
},
},
"value": 0,
},
},
)
node.handle_metadata_updated(event)
assert value.metadata.states
async def test_notification(lock_schlage_be469: node_pkg.Node):
"""Test notification CC notification events."""
node = lock_schlage_be469
# Validate that Entry Control CC notification event is received as expected
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 23,
"ccId": 111,
"endpointIndex": 0,
"args": {
"eventType": 0,
"eventTypeLabel": "a",
"dataType": 0,
"dataTypeLabel": "b",
"eventData": "test",
},
},
)
node.handle_notification(event)
assert event.data["notification"].command_class == CommandClass.ENTRY_CONTROL
assert event.data["notification"].node_id == 23
assert event.data["notification"].endpoint_idx == 0
assert event.data["notification"].event_type == EntryControlEventType.CACHING
assert event.data["notification"].event_type_label == "a"
assert event.data["notification"].data_type == EntryControlDataType.NONE
assert event.data["notification"].data_type_label == "b"
assert event.data["notification"].event_data == "test"
# Validate that Notification CC notification event is received as expected
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 23,
"endpointIndex": 0,
"ccId": 113,
"args": {
"type": 6,
"event": 5,
"label": "Access Control",
"eventLabel": "Keypad lock operation",
"parameters": {"userId": 1},
},
},
)
node.handle_notification(event)
assert event.data["notification"].command_class == CommandClass.NOTIFICATION
assert event.data["notification"].node_id == 23
assert event.data["notification"].endpoint_idx == 0
assert event.data["notification"].type_ == 6
assert event.data["notification"].event == 5
assert event.data["notification"].label == "Access Control"
assert event.data["notification"].event_label == "Keypad lock operation"
assert event.data["notification"].parameters == {"userId": 1}
# Validate that Power Level CC notification event is received as expected
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 23,
"endpointIndex": 0,
"ccId": CommandClass.POWERLEVEL.value,
"args": {"testNodeId": 1, "status": 0, "acknowledgedFrames": 2},
},
)
node.handle_notification(event)
assert event.data["notification"].command_class == CommandClass.POWERLEVEL
assert event.data["notification"].node_id == 23
assert event.data["notification"].endpoint_idx == 0
assert event.data["notification"].test_node_id == 1
assert event.data["notification"].status == PowerLevelTestStatus.FAILED
assert event.data["notification"].acknowledged_frames == 2
# Validate that Multilevel Switch CC notification event is received as expected
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 23,
"endpointIndex": 0,
"ccId": CommandClass.SWITCH_MULTILEVEL.value,
"args": {"direction": "up", "eventType": 4, "eventTypeLabel": "c"},
},
)
node.handle_notification(event)
assert event.data["notification"].command_class == CommandClass.SWITCH_MULTILEVEL
assert event.data["notification"].node_id == 23
assert event.data["notification"].endpoint_idx == 0
assert event.data["notification"].direction == "up"
assert (
event.data["notification"].event_type
== MultilevelSwitchCommand.START_LEVEL_CHANGE
)
assert event.data["notification"].event_type_label == "c"
# Validate that Multilevel Switch CC notification event without a direction is valid
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 23,
"endpointIndex": 0,
"ccId": CommandClass.SWITCH_MULTILEVEL.value,
"args": {"eventType": 4, "eventTypeLabel": "c"},
},
)
node.handle_notification(event)
assert event.data["notification"].command_class == CommandClass.SWITCH_MULTILEVEL
assert event.data["notification"].node_id == 23
assert event.data["notification"].endpoint_idx == 0
assert event.data["notification"].direction is None
assert (
event.data["notification"].event_type
== MultilevelSwitchCommand.START_LEVEL_CHANGE
)
assert event.data["notification"].event_type_label == "c"
async def test_notification_unknown(lock_schlage_be469: node_pkg.Node, caplog):
"""Test unrecognized command class notification events."""
# Validate that an unrecognized CC notification event raises Exception
node = lock_schlage_be469
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 23,
"ccId": 0,
},
)
node.handle_notification(event)
assert "notification" not in event.data
async def test_entry_control_notification(ring_keypad):
"""Test entry control CC notification events."""
node = ring_keypad
# Validate that Entry Control CC notification event is received as expected
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 10,
"endpointIndex": 0,
"ccId": 111,
"args": {
"eventType": 5,
"eventTypeLabel": "foo",
"dataType": 2,
"dataTypeLabel": "bar",
"eventData": "cat",
},
},
)
node.handle_notification(event)
assert event.data["notification"].command_class == CommandClass.ENTRY_CONTROL
assert event.data["notification"].node_id == 10
assert event.data["notification"].endpoint_idx == 0
assert event.data["notification"].event_type == EntryControlEventType.ARM_AWAY
assert event.data["notification"].event_type_label == "foo"
assert event.data["notification"].data_type == EntryControlDataType.ASCII
assert event.data["notification"].data_type_label == "bar"
assert event.data["notification"].event_data == "cat"
async def test_interview_events(multisensor_6):
"""Test Node interview events."""
node = multisensor_6
assert node.interview_stage is None
assert node.ready
assert not node.in_interview
event = Event(
type="interview started",
data={
"source": "node",
"event": "interview started",
"nodeId": 52,
},
)
node.handle_interview_started(event)
assert node.interview_stage is None
assert not node.ready
assert not node.in_interview
assert node.awaiting_manual_interview
event = Event(
type="interview stage completed",
data={
"source": "node",
"event": "interview stage completed",
"nodeId": 52,
"stageName": "test",
},
)
node.handle_interview_stage_completed(event)
assert node.interview_stage == "test"
assert not node.ready
assert node.in_interview
event = Event(
type="interview failed",
data={
"source": "node",
"event": "interview failed",
"nodeId": 52,
},
)
node.handle_interview_failed(event)
assert node.interview_stage == INTERVIEW_FAILED
assert not node.ready
assert not node.in_interview
event = Event(
type="interview completed",
data={
"source": "node",
"event": "interview completed",
"nodeId": 52,
},
)
node.handle_interview_completed(event)
assert node.ready
assert not node.in_interview
async def test_refresh_values(multisensor_6, uuid4, mock_command):
"""Test refresh_values and refresh_cc_values commands."""
node: node_pkg.Node = multisensor_6
ack_commands = mock_command(
{"command": "node.refresh_values", "nodeId": node.node_id},
{"success": True},
)
await node.async_refresh_values()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.refresh_values",
"nodeId": node.node_id,
"messageId": uuid4,
}
ack_commands = mock_command(
{
"command": "node.refresh_cc_values",
"nodeId": node.node_id,
"commandClass": 112,
},
{"success": True},
)
await node.async_refresh_cc_values(CommandClass.CONFIGURATION)
assert len(ack_commands) == 2
assert ack_commands[1] == {
"command": "node.refresh_cc_values",
"nodeId": node.node_id,
"commandClass": 112,
"messageId": uuid4,
}
async def test_firmware_events(wallmote_central_scene: node_pkg.Node):
"""Test firmware events."""
node = wallmote_central_scene
assert node.firmware_update_progress is None
event = Event(
type="firmware update progress",
data={
"source": "node",
"event": "firmware update progress",
"nodeId": 35,
"progress": {
"currentFile": 1,
"totalFiles": 1,
"sentFragments": 1,
"totalFragments": 10,
"progress": 10.0,
},
},
)
node.handle_firmware_update_progress(event)
progress = event.data["firmware_update_progress"]
assert progress.current_file == 1
assert progress.total_files == 1
assert progress.sent_fragments == 1
assert progress.total_fragments == 10
assert progress.progress == 10.0
assert node.firmware_update_progress
assert node.firmware_update_progress.current_file == 1
assert node.firmware_update_progress.total_files == 1
assert node.firmware_update_progress.sent_fragments == 1
assert node.firmware_update_progress.total_fragments == 10
assert node.firmware_update_progress.progress == 10.0
event = Event(
type="firmware update finished",
data={
"source": "node",
"event": "firmware update finished",
"nodeId": 35,
"result": {
"status": 255,
"success": True,
"waitTime": 10,
"reInterview": False,
},
},
)
node.handle_firmware_update_finished(event)
result = event.data["firmware_update_finished"]
assert result.status == NodeFirmwareUpdateStatus.OK_RESTART_PENDING
assert result.success
assert result.wait_time == 10
assert not result.reinterview
assert node.firmware_update_progress is None
async def test_value_added_value_exists(climate_radio_thermostat_ct100_plus):
"""Test value added event when value exists."""
node: node_pkg.Node = climate_radio_thermostat_ct100_plus
value_id = f"{node.node_id}-128-1-isHigh"
value = node.values.get(value_id)
assert value
event = Event(
"value added",
{
"source": "node",
"event": "value added",
"nodeId": node.node_id,
"args": {
"commandClassName": "Battery",
"commandClass": 128,
"endpoint": 1,
"property": "isHigh",
"propertyName": "isHigh",
"metadata": {
"type": "boolean",
"readable": True,
"writeable": False,
"label": "High battery level",
},
"value": True,
},
},
)
node.receive_event(event)
assert value_id in node.values
assert node.values[value_id] is value
async def test_value_added_new_value(climate_radio_thermostat_ct100_plus):
"""Test value added event when new value is added."""
node: node_pkg.Node = climate_radio_thermostat_ct100_plus
event = Event(
"value added",
{
"source": "node",
"event": "value added",
"nodeId": node.node_id,
"args": {
"commandClassName": "Battery",
"commandClass": 128,
"endpoint": 1,
"property": "isMedium",
"propertyName": "isMedium",
"metadata": {
"type": "boolean",
"readable": True,
"writeable": False,
"label": "Medium battery level",
},
"value": True,
},
},
)
node.receive_event(event)
assert f"{node.node_id}-128-1-isMedium" in node.values
async def test_invoke_cc_api(client, lock_schlage_be469, uuid4, mock_command):
"""Test endpoint.invoke_cc_api commands."""
node = lock_schlage_be469
ack_commands = mock_command(
{"command": "endpoint.invoke_cc_api", "nodeId": node.node_id, "endpoint": 0},
{"response": "ok"},
)
assert (
await node.async_invoke_cc_api(CommandClass.USER_CODE, "set", 1, 1, "1234")
== "ok"
)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.invoke_cc_api",
"nodeId": node.node_id,
"endpoint": 0,
"commandClass": 99,
"methodName": "set",
"args": [1, 1, "1234"],
"messageId": uuid4,
}
assert (
await node.async_invoke_cc_api(
CommandClass.USER_CODE, "set", 2, 2, "1234", wait_for_result=True
)
== "ok"
)
assert len(ack_commands) == 2
assert ack_commands[1] == {
"command": "endpoint.invoke_cc_api",
"nodeId": node.node_id,
"endpoint": 0,
"commandClass": 99,
"methodName": "set",
"args": [2, 2, "1234"],
"messageId": uuid4,
}
with pytest.raises(NotFoundError):
await node.async_invoke_cc_api(CommandClass.ANTITHEFT, "test", 1)
async def test_supports_cc_api(multisensor_6, uuid4, mock_command):
"""Test endpoint.supports_cc_api commands."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.supports_cc_api", "nodeId": node.node_id, "endpoint": 0},
{"supported": True},
)
assert await node.async_supports_cc_api(CommandClass.USER_CODE)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.supports_cc_api",
"nodeId": node.node_id,
"endpoint": 0,
"commandClass": 99,
"messageId": uuid4,
}
# Test that command fails when client is disconnected
with patch("zwave_js_server.client.asyncio.Event.wait", return_value=True):
await node.client.disconnect()
with pytest.raises(FailedCommand):
await node.async_supports_cc_api(CommandClass.USER_CODE)
async def test_supports_cc(multisensor_6, uuid4, mock_command):
"""Test endpoint.supports_cc_api commands."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.supports_cc", "nodeId": node.node_id, "endpoint": 0},
{"supported": True},
)
assert await node.async_supports_cc(CommandClass.USER_CODE)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.supports_cc",
"nodeId": node.node_id,
"endpoint": 0,
"commandClass": 99,
"messageId": uuid4,
}
# Test that command fails when client is disconnected
with patch("zwave_js_server.client.asyncio.Event.wait", return_value=True):
await node.client.disconnect()
with pytest.raises(FailedCommand):
await node.async_supports_cc(CommandClass.USER_CODE)
async def test_controls_cc(multisensor_6, uuid4, mock_command):
"""Test endpoint.controls_cc commands."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.controls_cc", "nodeId": node.node_id, "endpoint": 0},
{"controlled": True},
)
assert await node.async_controls_cc(CommandClass.USER_CODE)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.controls_cc",
"nodeId": node.node_id,
"endpoint": 0,
"commandClass": 99,
"messageId": uuid4,
}
# Test that command fails when client is disconnected
with patch("zwave_js_server.client.asyncio.Event.wait", return_value=True):
await node.client.disconnect()
with pytest.raises(FailedCommand):
await node.async_controls_cc(CommandClass.USER_CODE)
async def test_is_cc_secure(multisensor_6, uuid4, mock_command):
"""Test endpoint.is_cc_secure commands."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.is_cc_secure", "nodeId": node.node_id, "endpoint": 0},
{"secure": True},
)
assert await node.async_is_cc_secure(CommandClass.USER_CODE)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.is_cc_secure",
"nodeId": node.node_id,
"endpoint": 0,
"commandClass": 99,
"messageId": uuid4,
}
# Test that command fails when client is disconnected
with patch("zwave_js_server.client.asyncio.Event.wait", return_value=True):
await node.client.disconnect()
with pytest.raises(FailedCommand):
await node.async_is_cc_secure(CommandClass.USER_CODE)
async def test_get_cc_version(multisensor_6, uuid4, mock_command):
"""Test endpoint.get_cc_version commands."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.get_cc_version", "nodeId": node.node_id, "endpoint": 0},
{"version": 1},
)
assert await node.async_get_cc_version(CommandClass.USER_CODE) == 1
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.get_cc_version",
"nodeId": node.node_id,
"endpoint": 0,
"commandClass": 99,
"messageId": uuid4,
}
# Test that command fails when client is disconnected
with patch("zwave_js_server.client.asyncio.Event.wait", return_value=True):
await node.client.disconnect()
with pytest.raises(FailedCommand):
await node.async_get_cc_version(CommandClass.USER_CODE)
async def test_get_node_unsafe(multisensor_6, uuid4, mock_command):
"""Test endpoint.get_node_unsafe commands."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.get_node_unsafe", "nodeId": node.node_id, "endpoint": 0},
{"node": multisensor_6},
)
assert await node.async_get_node_unsafe() == multisensor_6
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.get_node_unsafe",
"nodeId": node.node_id,
"endpoint": 0,
"messageId": uuid4,
}
# Test that command fails when client is disconnected
with patch("zwave_js_server.client.asyncio.Event.wait", return_value=True):
await node.client.disconnect()
with pytest.raises(FailedCommand):
await node.async_get_node_unsafe()
async def test_statistics_updated(
wallmote_central_scene: node_pkg.Node, multisensor_6, ring_keypad
):
"""Test that statistics get updated on events."""
node = wallmote_central_scene
assert node.statistics.commands_rx == 0
event = Event(
"statistics updated",
{
"source": "node",
"event": "statistics updated",
"nodeId": node.node_id,
"statistics": {
"commandsTX": 1,
"commandsRX": 2,
"commandsDroppedTX": 3,
"commandsDroppedRX": 4,
"timeoutResponse": 5,
"rtt": 6,
"rssi": 7,
"lwr": {
"protocolDataRate": 1,
"repeaters": [f"{wallmote_central_scene.node_id}"],
"repeaterRSSI": [1],
"routeFailedBetween": [
f"{ring_keypad.node_id}",
f"{multisensor_6.node_id}",
],
},
"nlwr": {
"protocolDataRate": 2,
"repeaters": [],
"repeaterRSSI": [127],
"routeFailedBetween": [
f"{multisensor_6.node_id}",
f"{ring_keypad.node_id}",
],
},
},
},
)
node.receive_event(event)
# Event should be modified with the NodeStatistics object
assert "statistics_updated" in event.data
event_stats: NodeStatistics = event.data["statistics_updated"]
assert isinstance(event_stats, NodeStatistics)
assert event_stats.commands_tx == 1
assert event_stats.commands_rx == 2
assert event_stats.commands_dropped_tx == 3
assert event_stats.commands_dropped_rx == 4
assert event_stats.timeout_response == 5
assert event_stats.rtt == 6
assert event_stats.rssi == 7
assert event_stats.lwr
assert event_stats.lwr.protocol_data_rate == ProtocolDataRate.ZWAVE_9K6
assert event_stats.nlwr
assert event_stats.nlwr.protocol_data_rate == ProtocolDataRate.ZWAVE_40K
assert node.statistics == event_stats
assert event_stats.lwr.as_dict() == {
"protocol_data_rate": 1,
"repeaters": [wallmote_central_scene],
"repeater_rssi": [1],
"rssi": None,
"route_failed_between": (
ring_keypad,
multisensor_6,
),
}
statistics_data = {
"commandsTX": 1,
"commandsRX": 2,
"commandsDroppedTX": 3,
"commandsDroppedRX": 4,
"timeoutResponse": 5,
}
assert node.data.get("statistics") != statistics_data
event = Event(
"statistics updated",
{
"source": "node",
"event": "statistics updated",
"nodeId": node.node_id,
"statistics": statistics_data,
},
)
node.receive_event(event)
# Event should be modified with the NodeStatistics object
assert "statistics_updated" in event.data
event_stats: NodeStatistics = event.data["statistics_updated"]
assert isinstance(event_stats, NodeStatistics)
assert event_stats.commands_tx == 1
assert event_stats.commands_rx == 2
assert event_stats.commands_dropped_tx == 3
assert event_stats.commands_dropped_rx == 4
assert event_stats.timeout_response == 5
assert not event_stats.rtt
assert not event_stats.rssi
assert not event_stats.lwr
assert not event_stats.nlwr
assert node.statistics == event_stats
assert node.data["statistics"] == statistics_data
# Test that invalid protocol data rate doesn't raise error
event = Event(
"statistics updated",
{
"source": "node",
"event": "statistics updated",
"nodeId": node.node_id,
"statistics": {
"commandsTX": 1,
"commandsRX": 2,
"commandsDroppedTX": 3,
"commandsDroppedRX": 4,
"timeoutResponse": 5,
"rtt": 6,
"rssi": 7,
"lwr": {
"protocolDataRate": 0,
"repeaters": [],
"repeaterRSSI": [],
"routeFailedBetween": [],
},
"nlwr": {
"protocolDataRate": 0,
"repeaters": [],
"repeaterRSSI": [],
"routeFailedBetween": [],
},
},
},
)
node.receive_event(event)
# Event should be modified with the NodeStatistics object
assert "statistics_updated" in event.data
event_stats: NodeStatistics = event.data["statistics_updated"]
assert isinstance(event_stats, NodeStatistics)
assert not event_stats.lwr
assert not event_stats.nlwr
async def test_statistics_updated_rssi_error(
wallmote_central_scene: node_pkg.Node, multisensor_6, ring_keypad
):
"""Test that statistics get updated on events and rssi error is handled."""
node = wallmote_central_scene
assert node.statistics.commands_rx == 0
event = Event(
"statistics updated",
{
"source": "node",
"event": "statistics updated",
"nodeId": node.node_id,
"statistics": {
"commandsTX": 1,
"commandsRX": 2,
"commandsDroppedTX": 3,
"commandsDroppedRX": 4,
"timeoutResponse": 5,
"rtt": 6,
"rssi": 127,
"lwr": {
"protocolDataRate": 1,
"repeaters": [f"{wallmote_central_scene.node_id}"],
"repeaterRSSI": [1],
"routeFailedBetween": [
f"{ring_keypad.node_id}",
f"{multisensor_6.node_id}",
],
},
"nlwr": {
"protocolDataRate": 2,
"repeaters": [],
"repeaterRSSI": [127],
"routeFailedBetween": [
f"{multisensor_6.node_id}",
f"{ring_keypad.node_id}",
],
},
},
},
)
node.receive_event(event)
# Event should be modified with the NodeStatistics object
assert "statistics_updated" in event.data
event_stats: NodeStatistics = event.data["statistics_updated"]
assert isinstance(event_stats, NodeStatistics)
with pytest.raises(RssiErrorReceived):
assert event_stats.rssi
async def test_has_security_class(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.has_security_class command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.has_security_class", "nodeId": node.node_id},
{"hasSecurityClass": True},
)
assert await node.async_has_security_class(SecurityClass.S2_AUTHENTICATED)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.has_security_class",
"nodeId": node.node_id,
"securityClass": SecurityClass.S2_AUTHENTICATED.value,
"messageId": uuid4,
}
async def test_has_security_class_undefined(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.has_security_class command response is undefined."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.has_security_class", "nodeId": node.node_id},
{},
)
assert await node.async_has_security_class(SecurityClass.S2_AUTHENTICATED) is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.has_security_class",
"nodeId": node.node_id,
"securityClass": SecurityClass.S2_AUTHENTICATED.value,
"messageId": uuid4,
}
async def test_get_highest_security_class(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.get_highest_security_class command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_highest_security_class", "nodeId": node.node_id},
{"highestSecurityClass": SecurityClass.S2_AUTHENTICATED.value},
)
assert (
await node.async_get_highest_security_class() == SecurityClass.S2_AUTHENTICATED
)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_highest_security_class",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_get_highest_security_class_undefined(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.get_highest_security_class command response is undefined."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_highest_security_class", "nodeId": node.node_id},
{},
)
assert await node.async_get_highest_security_class() is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_highest_security_class",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_test_power_level(
multisensor_6: node_pkg.Node,
wallmote_central_scene: node_pkg.Node,
uuid4,
mock_command,
):
"""Test node.test_powerlevel command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.test_powerlevel", "nodeId": node.node_id},
{"framesAcked": 1},
)
assert (
await node.async_test_power_level(
wallmote_central_scene, PowerLevel.DBM_MINUS_1, 3
)
== 1
)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.test_powerlevel",
"nodeId": node.node_id,
"testNodeId": wallmote_central_scene.node_id,
"powerlevel": PowerLevel.DBM_MINUS_1.value,
"testFrameCount": 3,
"messageId": uuid4,
}
async def test_test_power_level_progress_event(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test test power level progress event."""
event = Event(
"test powerlevel progress",
{
"source": "node",
"event": "test powerlevel progress",
"nodeId": multisensor_6.node_id,
"acknowledged": 1,
"total": 2,
},
)
multisensor_6.receive_event(event)
assert event.data["test_power_level_progress"]
assert event.data["test_power_level_progress"].acknowledged == 1
assert event.data["test_power_level_progress"].total == 2
async def test_check_lifeline_health(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.check_lifeline_health command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.check_lifeline_health", "nodeId": node.node_id},
{
"summary": {
"rating": 10,
"results": [
LifelineHealthCheckResultDataType(
latency=1,
numNeighbors=2,
failedPingsNode=3,
rating=9,
routeChanges=4,
minPowerlevel=5,
failedPingsController=6,
snrMargin=7,
)
],
}
},
)
summary = await node.async_check_lifeline_health(1)
assert summary.rating == 10
assert summary.results[0].latency == 1
assert summary.results[0].num_neighbors == 2
assert summary.results[0].failed_pings_node == 3
assert summary.results[0].rating == 9
assert summary.results[0].route_changes == 4
assert summary.results[0].min_power_level == PowerLevel.DBM_MINUS_5
assert summary.results[0].failed_pings_controller == 6
assert summary.results[0].snr_margin == 7
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.check_lifeline_health",
"nodeId": node.node_id,
"rounds": 1,
"messageId": uuid4,
}
async def test_check_lifeline_health_progress_event(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test check lifeline health progress event."""
event = Event(
"check lifeline health progress",
{
"source": "node",
"event": "check lifeline health progress",
"nodeId": multisensor_6.node_id,
"rounds": 1,
"totalRounds": 2,
"lastRating": 10,
"lastResult": LifelineHealthCheckResultDataType(
latency=1,
numNeighbors=2,
failedPingsNode=3,
rating=9,
routeChanges=4,
minPowerlevel=5,
failedPingsController=6,
snrMargin=7,
),
},
)
multisensor_6.receive_event(event)
assert event.data["check_lifeline_health_progress"]
assert event.data["check_lifeline_health_progress"].rounds == 1
assert event.data["check_lifeline_health_progress"].total_rounds == 2
assert event.data["check_lifeline_health_progress"].last_rating == 10
assert event.data["check_lifeline_health_progress"].last_result.latency == 1
async def test_check_route_health(
multisensor_6: node_pkg.Node,
wallmote_central_scene: node_pkg.Node,
uuid4,
mock_command,
):
"""Test node.check_route_health command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.check_route_health", "nodeId": node.node_id},
{
"summary": {
"rating": 10,
"results": [
RouteHealthCheckResultDataType(
numNeighbors=1,
rating=10,
failedPingsToSource=2,
failedPingsToTarget=3,
minPowerlevelSource=4,
minPowerlevelTarget=5,
)
],
}
},
)
summary = await node.async_check_route_health(wallmote_central_scene, 1)
assert summary.rating == 10
assert summary.results[0].num_neighbors == 1
assert summary.results[0].rating == 10
assert summary.results[0].failed_pings_to_source == 2
assert summary.results[0].failed_pings_to_target == 3
assert summary.results[0].min_power_level_source == PowerLevel.DBM_MINUS_4
assert summary.results[0].min_power_level_target == PowerLevel.DBM_MINUS_5
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.check_route_health",
"nodeId": node.node_id,
"targetNodeId": wallmote_central_scene.node_id,
"rounds": 1,
"messageId": uuid4,
}
async def test_check_route_health_progress_event(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test check route health progress event."""
event = Event(
"check route health progress",
{
"source": "node",
"event": "check route health progress",
"nodeId": multisensor_6.node_id,
"rounds": 1,
"totalRounds": 2,
"lastRating": 10,
"lastResult": RouteHealthCheckResultDataType(
numNeighbors=1,
rating=10,
failedPingsToSource=2,
failedPingsToTarget=3,
minPowerlevelSource=4,
minPowerlevelTarget=5,
),
},
)
multisensor_6.receive_event(event)
assert event.data["check_route_health_progress"]
assert event.data["check_route_health_progress"].rounds == 1
assert event.data["check_route_health_progress"].total_rounds == 2
assert event.data["check_route_health_progress"].last_rating == 10
assert event.data["check_route_health_progress"].last_result.num_neighbors == 1
async def test_get_state(
multisensor_6: node_pkg.Node,
multisensor_6_state: node_pkg.NodeDataType,
uuid4,
mock_command,
):
"""Test node.get_state command."""
node = multisensor_6
value_id = get_value_id_str(node, 32, "currentValue", 0)
# Verify original values
assert node.endpoints[0].installer_icon == 3079
assert node.values[value_id].value == 255
new_state = deepcopy(multisensor_6_state)
# Update endpoint 0 installer icon
new_state["endpoints"][0]["installerIcon"] = 1
# Update value of {nodeId}-32-0-currentValue
new_state["values"][0] = {
"commandClassName": "Basic",
"commandClass": 32,
"endpoint": 0,
"property": "currentValue",
"propertyName": "currentValue",
"metadata": {
"type": "number",
"readable": True,
"writeable": False,
"min": 0,
"max": 99,
"label": "Current value",
},
"value": 0,
}
ack_commands = mock_command(
{"command": "node.get_state", "nodeId": node.node_id},
{"state": new_state},
)
# Verify new values
assert await node.async_get_state() == new_state
# Verify original values are still the same
assert node.endpoints[0].installer_icon != 1
assert node.values[value_id].value != 0
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_state",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_update_endpoints(
shelly_wave_shutter_state: node_pkg.NodeDataType,
shelly_wave_shutter: node_pkg.Node,
) -> None:
"""Test updating endpoints of a node."""
node = shelly_wave_shutter
assert len(node.endpoints) == 3
for endpoint_idx, endpoint in node.endpoints.items():
assert endpoint.node_id == node.node_id
assert endpoint.index == endpoint_idx
for value in endpoint.values.values():
assert value.node.node_id == node.node_id
assert value.endpoint == endpoint_idx
node_data = deepcopy(shelly_wave_shutter_state)
new_endpoints = [
endpoint_pkg.EndpointDataType(
nodeId=node.node_id,
index=0,
commandClasses=[],
),
endpoint_pkg.EndpointDataType(
nodeId=node.node_id,
index=1,
commandClasses=[],
),
endpoint_pkg.EndpointDataType(
nodeId=node.node_id,
index=3,
commandClasses=[],
),
]
node_data["endpoints"] = new_endpoints
node.update(node_data)
assert len(node.endpoints) == 3
for endpoint_data in new_endpoints:
assert endpoint_data["index"] in node.endpoints
assert node.endpoints[endpoint_data["index"]].node_id == node.node_id
assert node.endpoints[endpoint_data["index"]].index == endpoint_data["index"]
for endpoint_idx, endpoint in node.endpoints.items():
assert endpoint.node_id == node.node_id
assert endpoint.index == endpoint_idx
for value in endpoint.values.values():
assert value.node.node_id == node.node_id
assert value.endpoint == endpoint_idx
async def test_set_name(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.set_name command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.set_name", "nodeId": node.node_id},
{},
)
assert node.name != "new_name"
assert await node.async_set_name("new_name", False) is None
assert node.name == "new_name"
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_name",
"nodeId": node.node_id,
"name": "new_name",
"updateCC": False,
"messageId": uuid4,
}
async def test_set_location(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.set_location command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.set_location", "nodeId": node.node_id},
{},
)
assert node.location != "new_location"
assert await node.async_set_location("new_location", False) is None
assert node.location == "new_location"
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_location",
"nodeId": node.node_id,
"location": "new_location",
"updateCC": False,
"messageId": uuid4,
}
async def test_set_keep_awake(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.set_keep_awake command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.set_keep_awake", "nodeId": node.node_id},
{},
)
assert node.keep_awake
assert await node.async_set_keep_awake(False) is None
assert node.keep_awake is False
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_keep_awake",
"nodeId": node.node_id,
"keepAwake": False,
"messageId": uuid4,
}
async def test_get_firmware_update_capabilities(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.get_firmware_update_capabilities command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_firmware_update_capabilities", "nodeId": node.node_id},
{
"capabilities": {
"firmwareUpgradable": True,
"firmwareTargets": [0],
"continuesToFunction": True,
"supportsActivation": True,
}
},
)
capabilities = await node.async_get_firmware_update_capabilities()
assert capabilities.firmware_upgradable
assert capabilities.firmware_targets == [0]
assert capabilities.continues_to_function
assert capabilities.supports_activation
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_firmware_update_capabilities",
"nodeId": node.node_id,
"messageId": uuid4,
}
assert capabilities.to_dict() == {
"firmware_upgradable": True,
"firmware_targets": [0],
"continues_to_function": True,
"supports_activation": True,
}
async def test_get_firmware_update_capabilities_false(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.get_firmware_update_capabilities cmd without firmware support."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_firmware_update_capabilities", "nodeId": node.node_id},
{"capabilities": {"firmwareUpgradable": False}},
)
capabilities = await node.async_get_firmware_update_capabilities()
assert not capabilities.firmware_upgradable
with pytest.raises(TypeError):
assert capabilities.firmware_targets
with pytest.raises(TypeError):
assert capabilities.continues_to_function
with pytest.raises(TypeError):
assert capabilities.supports_activation
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_firmware_update_capabilities",
"nodeId": node.node_id,
"messageId": uuid4,
}
assert capabilities.to_dict() == {"firmware_upgradable": False}
async def test_get_firmware_update_capabilities_string(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.get_firmware_update_capabilities cmd without firmware support."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_firmware_update_capabilities", "nodeId": node.node_id},
{
"capabilities": {
"firmwareUpgradable": True,
"firmwareTargets": [0],
"continuesToFunction": "unknown",
"supportsActivation": "unknown",
}
},
)
capabilities = await node.async_get_firmware_update_capabilities()
assert capabilities.firmware_upgradable
assert capabilities.firmware_targets == [0]
assert capabilities.continues_to_function is None
assert capabilities.supports_activation is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_firmware_update_capabilities",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_get_firmware_update_capabilities_cached(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.get_firmware_update_capabilities_cached command."""
node = multisensor_6
ack_commands = mock_command(
{
"command": "node.get_firmware_update_capabilities_cached",
"nodeId": node.node_id,
},
{
"capabilities": {
"firmwareUpgradable": True,
"firmwareTargets": [0],
"continuesToFunction": True,
"supportsActivation": True,
}
},
)
capabilities = await node.async_get_firmware_update_capabilities_cached()
assert capabilities.firmware_upgradable
assert capabilities.firmware_targets == [0]
assert capabilities.continues_to_function
assert capabilities.supports_activation
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_firmware_update_capabilities_cached",
"nodeId": node.node_id,
"messageId": uuid4,
}
assert capabilities.to_dict() == {
"firmware_upgradable": True,
"firmware_targets": [0],
"continues_to_function": True,
"supports_activation": True,
}
async def test_is_firmware_update_in_progress(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.is_firmware_update_in_progress command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.is_firmware_update_in_progress", "nodeId": node.node_id},
{"progress": True},
)
assert await node.async_is_firmware_update_in_progress()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.is_firmware_update_in_progress",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_interview(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.interview command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.interview", "nodeId": node.node_id},
{},
)
await node.async_interview()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.interview",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_manually_idle_notification_value(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.manually_idle_notification_value command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.manually_idle_notification_value", "nodeId": node.node_id},
{},
)
await node.async_manually_idle_notification_value(
f"{node.node_id}-113-0-Home Security-Cover status"
)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.manually_idle_notification_value",
"nodeId": node.node_id,
"valueId": {
"commandClass": 113,
"endpoint": 0,
"property": "Home Security",
"propertyKey": "Cover status",
},
"messageId": uuid4,
}
# Raise ValueError if the value is not for the right CommandClass
with pytest.raises(ValueError):
await node.async_manually_idle_notification_value(f"{node.node_id}-112-0-255")
async def test_set_date_and_time_no_wait(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.set_date_and_time command without waiting."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.set_date_and_time", "nodeId": node.node_id},
{"success": True},
)
assert await node.async_set_date_and_time(datetime(2020, 1, 1, 12, 0, 0)) is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_date_and_time",
"nodeId": node.node_id,
"date": "2020-01-01T12:00:00",
"messageId": uuid4,
}
async def test_set_date_and_time(
climate_radio_thermostat_ct100_plus: node_pkg.Node, uuid4, mock_command
):
"""Test node.set_date_and_time command while waiting for response."""
node = climate_radio_thermostat_ct100_plus
ack_commands = mock_command(
{"command": "node.set_date_and_time", "nodeId": node.node_id},
{"success": True},
)
assert await node.async_set_date_and_time(datetime(2020, 1, 1, 12, 0, 0))
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_date_and_time",
"nodeId": node.node_id,
"date": "2020-01-01T12:00:00",
"messageId": uuid4,
}
async def test_get_date_and_time(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.get_date_and_time command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_date_and_time", "nodeId": node.node_id},
{"dateAndTime": {"hour": 1, "minute": 2, "weekday": 5}},
)
date_and_time = await node.async_get_date_and_time()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_date_and_time",
"nodeId": node.node_id,
"messageId": uuid4,
}
assert date_and_time.hour == 1
assert date_and_time.minute == 2
assert date_and_time.weekday == Weekday.FRIDAY
async def test_get_value_timestamp(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.get_value_timestamp command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.get_value_timestamp", "nodeId": node.node_id},
{"timestamp": 1234567890},
)
val = node.values["52-32-0-targetValue"]
assert await node.async_get_value_timestamp(val) == 1234567890
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.get_value_timestamp",
"nodeId": node.node_id,
"valueId": {"commandClass": 32, "endpoint": 0, "property": "targetValue"},
"messageId": uuid4,
}
assert await node.async_get_value_timestamp("52-112-0-2") == 1234567890
assert len(ack_commands) == 2
assert ack_commands[1] == {
"command": "node.get_value_timestamp",
"nodeId": node.node_id,
"valueId": {"commandClass": 112, "endpoint": 0, "property": 2},
"messageId": uuid4,
}
async def test_is_health_check_in_progress(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test node.is_health_check_in_progress command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.is_health_check_in_progress", "nodeId": node.node_id},
{"progress": True},
)
assert await node.async_is_health_check_in_progress()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.is_health_check_in_progress",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_abort_health_check(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test node.abort_health_check command."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.abort_health_check", "nodeId": node.node_id},
{},
)
await node.async_abort_health_check()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.abort_health_check",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_unknown_event(multisensor_6: node_pkg.Node):
"""Test that an unknown event type causes an exception."""
with pytest.raises(KeyError):
assert multisensor_6.receive_event(Event("unknown_event", {"source": "node"}))
async def test_default_volume(multisensor_6: node_pkg.Node, uuid4, mock_command):
"""Test default volume."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.set_default_volume", "nodeId": node.node_id},
{},
)
assert node.default_volume is None
await node.async_set_default_volume(10)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_default_volume",
"defaultVolume": 10,
"nodeId": node.node_id,
"messageId": uuid4,
}
assert node.default_volume == 10
async def test_default_transition_duration(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test default transition duration."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.set_default_transition_duration", "nodeId": node.node_id},
{},
)
assert node.default_transition_duration is None
await node.async_set_default_transition_duration(10)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_default_transition_duration",
"defaultTransitionDuration": 10,
"nodeId": node.node_id,
"messageId": uuid4,
}
assert node.default_transition_duration == 10
async def test_has_device_config_changed(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test has device config changed."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.has_device_config_changed", "nodeId": node.node_id},
{"changed": True},
)
assert await node.async_has_device_config_changed()
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.has_device_config_changed",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_has_device_config_changed_undefined(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test has device config changed returns undefined."""
node = multisensor_6
ack_commands = mock_command(
{"command": "node.has_device_config_changed", "nodeId": node.node_id},
{},
)
assert await node.async_has_device_config_changed() is None
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.has_device_config_changed",
"nodeId": node.node_id,
"messageId": uuid4,
}
async def test_is_secure_none(client, multisensor_6_state):
"""Test is_secure when it's not included in the dump."""
node_state = deepcopy(multisensor_6_state)
node_state.pop("isSecure")
node = node_pkg.Node(client, node_state)
assert node.is_secure is None
async def test_set_raw_config_parameter_value(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test set raw config parameter value."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.set_raw_config_parameter_value", "nodeId": node.node_id},
{},
)
result = await node.async_set_raw_config_parameter_value(1, 101, 1)
assert result == SetConfigParameterResult(CommandStatus.QUEUED)
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.set_raw_config_parameter_value",
"nodeId": node.node_id,
"endpoint": 0,
"parameter": 101,
"bitMask": 1,
"value": 1,
"messageId": uuid4,
}
result = await node.async_set_raw_config_parameter_value(2, 0)
assert result == SetConfigParameterResult(CommandStatus.QUEUED)
assert len(ack_commands) == 2
assert ack_commands[1] == {
"command": "endpoint.set_raw_config_parameter_value",
"nodeId": node.node_id,
"endpoint": 0,
"parameter": 0,
"value": 2,
"messageId": uuid4,
}
# wake up node
event = Event(
"wake up", {"source": "node", "event": "wake up", "nodeId": node.node_id}
)
node.receive_event(event)
result = await node.async_set_raw_config_parameter_value(
1, 2, value_size=1, value_format=ConfigurationValueFormat.SIGNED_INTEGER
)
assert result == SetConfigParameterResult(CommandStatus.ACCEPTED)
assert len(ack_commands) == 3
assert ack_commands[2] == {
"command": "endpoint.set_raw_config_parameter_value",
"nodeId": node.node_id,
"endpoint": 0,
"parameter": 2,
"valueSize": 1,
"valueFormat": 0,
"value": 1,
"messageId": uuid4,
}
# Test failures
with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(1, 101, 1, 1)
with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(
1, 101, 1, value_format=ConfigurationValueFormat.SIGNED_INTEGER
)
with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(
1, 101, 1, 1, ConfigurationValueFormat.SIGNED_INTEGER
)
async def test_get_raw_config_parameter_value(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test get raw config parameter value."""
node = multisensor_6
ack_commands = mock_command(
{"command": "endpoint.get_raw_config_parameter_value", "nodeId": node.node_id},
{"value": 1},
)
value = await node.async_get_raw_config_parameter_value(101)
assert value == 1
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "endpoint.get_raw_config_parameter_value",
"nodeId": node.node_id,
"endpoint": 0,
"parameter": 101,
"messageId": uuid4,
}
async def test_supervision_result(inovelli_switch: node_pkg.Node, uuid4, mock_command):
"""Test Supervision Result."""
node = inovelli_switch
mock_command(
{"command": "endpoint.set_raw_config_parameter_value", "nodeId": node.node_id},
{"result": {"status": 1, "remainingDuration": "default"}},
)
result = await node.async_set_raw_config_parameter_value(1, 1)
assert result.result.status is SupervisionStatus.WORKING
duration = result.result.remaining_duration
assert duration.unit == "default"
async def test_supervision_result_invalid(
inovelli_switch: node_pkg.Node, uuid4, mock_command
):
"""Test invalid Supervision Result."""
node = inovelli_switch
mock_command(
{"command": "endpoint.set_raw_config_parameter_value", "nodeId": node.node_id},
{"result": {"status": 1}},
)
with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(1, 1)
|