|
32 | 32 | from kasa.discover import Discover, DiscoveryResult
|
33 | 33 | from kasa.iot import IotDevice
|
34 | 34 |
|
35 |
| -from .conftest import device_iot, device_smart, handle_turn_on, new_discovery, turn_on |
| 35 | +from .conftest import ( |
| 36 | + device_iot, |
| 37 | + device_smart, |
| 38 | + get_device_for_file, |
| 39 | + handle_turn_on, |
| 40 | + new_discovery, |
| 41 | + turn_on, |
| 42 | +) |
36 | 43 |
|
37 | 44 |
|
38 | 45 | async def test_update_called_by_cli(dev, mocker):
|
@@ -684,3 +691,99 @@ async def test_errors(mocker):
|
684 | 691 | )
|
685 | 692 | assert res.exit_code == 2
|
686 | 693 | assert "Raised error:" not in res.output
|
| 694 | + |
| 695 | + |
| 696 | +async def test_feature(mocker): |
| 697 | + """Test feature command.""" |
| 698 | + dummy_device = await get_device_for_file("P300(EU)_1.0_1.0.13.json", "SMART") |
| 699 | + mocker.patch("kasa.discover.Discover.discover_single", return_value=dummy_device) |
| 700 | + runner = CliRunner() |
| 701 | + res = await runner.invoke( |
| 702 | + cli, |
| 703 | + ["--host", "127.0.0.123", "--debug", "feature"], |
| 704 | + catch_exceptions=False, |
| 705 | + ) |
| 706 | + assert "LED" in res.output |
| 707 | + assert "== Child " in res.output # child listing |
| 708 | + |
| 709 | + assert res.exit_code == 0 |
| 710 | + |
| 711 | + |
| 712 | +async def test_feature_single(mocker): |
| 713 | + """Test feature command returning single value.""" |
| 714 | + dummy_device = await get_device_for_file("P300(EU)_1.0_1.0.13.json", "SMART") |
| 715 | + mocker.patch("kasa.discover.Discover.discover_single", return_value=dummy_device) |
| 716 | + runner = CliRunner() |
| 717 | + res = await runner.invoke( |
| 718 | + cli, |
| 719 | + ["--host", "127.0.0.123", "--debug", "feature", "led"], |
| 720 | + catch_exceptions=False, |
| 721 | + ) |
| 722 | + assert "LED" in res.output |
| 723 | + assert "== Features ==" not in res.output |
| 724 | + assert res.exit_code == 0 |
| 725 | + |
| 726 | +async def test_feature_missing(mocker): |
| 727 | + """Test feature command returning single value.""" |
| 728 | + dummy_device = await get_device_for_file("P300(EU)_1.0_1.0.13.json", "SMART") |
| 729 | + mocker.patch("kasa.discover.Discover.discover_single", return_value=dummy_device) |
| 730 | + runner = CliRunner() |
| 731 | + res = await runner.invoke( |
| 732 | + cli, |
| 733 | + ["--host", "127.0.0.123", "--debug", "feature", "missing"], |
| 734 | + catch_exceptions=False, |
| 735 | + ) |
| 736 | + assert "No feature by name 'missing'" in res.output |
| 737 | + assert "== Features ==" not in res.output |
| 738 | + assert res.exit_code == 0 |
| 739 | + |
| 740 | +async def test_feature_set(mocker): |
| 741 | + """Test feature command's set value.""" |
| 742 | + dummy_device = await get_device_for_file("P300(EU)_1.0_1.0.13.json", "SMART") |
| 743 | + led_setter = mocker.patch("kasa.smart.modules.ledmodule.LedModule.set_led") |
| 744 | + mocker.patch("kasa.discover.Discover.discover_single", return_value=dummy_device) |
| 745 | + |
| 746 | + runner = CliRunner() |
| 747 | + res = await runner.invoke( |
| 748 | + cli, |
| 749 | + ["--host", "127.0.0.123", "--debug", "feature", "led", "True"], |
| 750 | + catch_exceptions=False, |
| 751 | + ) |
| 752 | + |
| 753 | + led_setter.assert_called_with(True) |
| 754 | + assert "Setting led to True" in res.output |
| 755 | + assert res.exit_code == 0 |
| 756 | + |
| 757 | + |
| 758 | +async def test_feature_set_child(mocker): |
| 759 | + """Test feature command's set value.""" |
| 760 | + dummy_device = await get_device_for_file("P300(EU)_1.0_1.0.13.json", "SMART") |
| 761 | + setter = mocker.patch("kasa.smart.smartdevice.SmartDevice.set_state") |
| 762 | + |
| 763 | + mocker.patch("kasa.discover.Discover.discover_single", return_value=dummy_device) |
| 764 | + get_child_device = mocker.spy(dummy_device, "get_child_device") |
| 765 | + |
| 766 | + child_id = "000000000000000000000000000000000000000001" |
| 767 | + |
| 768 | + runner = CliRunner() |
| 769 | + res = await runner.invoke( |
| 770 | + cli, |
| 771 | + [ |
| 772 | + "--host", |
| 773 | + "127.0.0.123", |
| 774 | + "--debug", |
| 775 | + "feature", |
| 776 | + "--child", |
| 777 | + child_id, |
| 778 | + "state", |
| 779 | + "False", |
| 780 | + ], |
| 781 | + catch_exceptions=False, |
| 782 | + ) |
| 783 | + |
| 784 | + get_child_device.assert_called() |
| 785 | + setter.assert_called_with(False) |
| 786 | + |
| 787 | + assert f"Targeting child device {child_id}" |
| 788 | + assert "Setting state to False" in res.output |
| 789 | + assert res.exit_code == 0 |
0 commit comments