| 1 | # """Test scripts for BSDGO1 Outlets.""" |
| 2 | # from __future__ import annotations |
| 3 | # from typing import TYPE_CHECKING |
| 4 | # import orjson |
| 5 | # from pyvesync.devices.vesyncoutlet import VeSyncOutletBSDGO1 |
| 6 | # from pyvesync.utils.helpers import Helpers as Helpers |
| 7 | # from pyvesync.models.vesync_models import ResponseDeviceDetailsModel |
| 8 | # from pyvesync.device_map import get_outlet |
| 9 | # import call_json |
| 10 | # import call_json_outlets |
| 11 | # from base_test_cases import TestBase |
| 12 | # from defaults import Defaults |
| 13 | |
| 14 | # if TYPE_CHECKING: |
| 15 | # from pyvesync.device_map import OutletMap |
| 16 | |
| 17 | # DEVICE_TYPE = 'BSDOG01' |
| 18 | # if get_outlet(DEVICE_TYPE) is not None: |
| 19 | # DEVICE_MAP = get_outlet(DEVICE_TYPE) |
| 20 | |
| 21 | # DEV_LIST_DETAIL = call_json.DeviceList.device_list_item(DEVICE_MAP) |
| 22 | |
| 23 | # CORRECT_BSDGO1_DETAILS = call_json_outlets.DETAILS_RESPONSES[DEVICE_TYPE] |
| 24 | |
| 25 | # BAD_BSDGO1_LIST = call_json.DETAILS_BADCODE |
| 26 | |
| 27 | |
| 28 | # class TestVeSyncBSDGO1Switch(TestBase): |
| 29 | # """Test BSDGO1 outlet API.""" |
| 30 | |
| 31 | # def device_map(self) -> OutletMap: |
| 32 | # outlet_map = get_outlet(DEVICE_TYPE) |
| 33 | # if outlet_map is None: |
| 34 | # raise ValueError(f'No device map found for {DEVICE_TYPE}') |
| 35 | # return outlet_map |
| 36 | |
| 37 | # def device_list_model(self) -> ResponseDeviceDetailsModel: |
| 38 | # return ResponseDeviceDetailsModel.from_dict(call_json.DeviceList.device_list_item(self.device_map())) |
| 39 | |
| 40 | # def test_bsdgo1_conf(self): |
| 41 | # """Test initialization of BSDGO1 outlet.""" |
| 42 | # self.mock_api.return_value = call_json.DeviceList.device_list_response(DEVICE_TYPE) |
| 43 | # self.run_in_loop(self.manager.get_devices) |
| 44 | # outlets = self.manager.devices.outlets |
| 45 | # assert len(outlets) == 1 |
| 46 | # bsdgo1_outlet = outlets[0] |
| 47 | # assert isinstance(bsdgo1_outlet, VeSyncOutletBSDGO1) |
| 48 | # assert bsdgo1_outlet.device_name == call_json.Defaults.name(DEVICE_TYPE) |
| 49 | # assert bsdgo1_outlet.device_type == DEVICE_TYPE |
| 50 | # assert bsdgo1_outlet.cid == call_json.Defaults.cid(DEVICE_TYPE) |
| 51 | # assert bsdgo1_outlet.uuid == call_json.Defaults.uuid(DEVICE_TYPE) |
| 52 | |
| 53 | # def test_bsdgo1_details(self): |
| 54 | # """Test BSDGO1 get_details().""" |
| 55 | # resp_dict, status = self.device_list_model(), 200 |
| 56 | # self.mock_api.return_value = orjson.dumps(resp_dict), status |
| 57 | |
| 58 | # bsdgo1_outlet = VeSyncOutletBSDGO1( |
| 59 | # self.device_list_model(), |
| 60 | # self.manager, |
| 61 | # self.device_map(), |
| 62 | # ) |
| 63 | # self.run_in_loop(bsdgo1_outlet.get_details) |
| 64 | # response = CORRECT_BSDGO1_DETAILS[0] |
| 65 | # result = response.get('result', {}) |
| 66 | |
| 67 | # expected_status = 'on' if result.get('powerSwitch_1') == 1 else 'off' |
| 68 | # assert bsdgo1_outlet.state.device_status == expected_status |
| 69 | |
| 70 | # assert result.get('active_time') == Defaults.active_time |
| 71 | # assert result.get('connectionStatus') == 'online' |
| 72 | |
| 73 | # def test_bsdgo1_details_fail(self): |
| 74 | # """Test BSDGO1 get_details with bad response.""" |
| 75 | # resp_dict, status = BAD_BSDGO1_LIST |
| 76 | # self.mock_api.return_value = orjson.dumps(resp_dict), status |
| 77 | # bsdgo1_outlet = VeSyncOutletBSDGO1( |
| 78 | # self.device_list_model(), |
| 79 | # self.manager, |
| 80 | # self.device_map(), |
| 81 | # ) |
| 82 | # self.run_in_loop(bsdgo1_outlet.get_details) |
| 83 | # assert len(self.caplog.records) == 1 |
| 84 | # assert 'details' in self.caplog.text |
| 85 | |
| 86 | # def test_bsdgo1_onoff(self): |
| 87 | # """Test BSDGO1 Device On/Off Methods.""" |
| 88 | # self.mock_api.return_value = (orjson.dumps({'code': 0}), 200) |
| 89 | # bsdgo1_outlet = VeSyncOutletBSDGO1( |
| 90 | # self.device_list_model(), |
| 91 | # self.manager, |
| 92 | # self.device_map(), |
| 93 | # ) |
| 94 | # head = Helpers.req_header_bypass() |
| 95 | # body = Helpers.req_body(self.manager, 'bypassV2') |
| 96 | # body['cid'] = bsdgo1_outlet.cid |
| 97 | # body['configModule'] = bsdgo1_outlet.config_module |
| 98 | |
| 99 | # # Test turn_on |
| 100 | # body['payload'] = { |
| 101 | # 'data': {'powerSwitch_1': 1}, |
| 102 | # 'method': 'setProperty', |
| 103 | # 'source': 'APP' |
| 104 | # } |
| 105 | # on = self.run_in_loop(bsdgo1_outlet.turn_on) |
| 106 | # self.mock_api.assert_called_with( |
| 107 | # '/cloud/v2/deviceManaged/bypassV2', |
| 108 | # 'post', |
| 109 | # headers=head, |
| 110 | # json_object=body |
| 111 | # ) |
| 112 | # assert on |
| 113 | |
| 114 | # # Test turn_off |
| 115 | # body['payload'] = { |
| 116 | # 'data': {'powerSwitch_1': 0}, |
| 117 | # 'method': 'setProperty', |
| 118 | # 'source': 'APP' |
| 119 | # } |
| 120 | # off = self.run_in_loop(bsdgo1_outlet.turn_off) |
| 121 | # self.mock_api.assert_called_with( |
| 122 | # '/cloud/v2/deviceManaged/bypassV2', |
| 123 | # 'post', |
| 124 | # headers=head, |
| 125 | # json_object=body |
| 126 | # ) |
| 127 | # assert off |
| 128 | |
| 129 | # def test_bsdgo1_onoff_fail(self): |
| 130 | # """Test BSDGO1 On/Off Fail with bad response.""" |
| 131 | # resp_dict, status = BAD_BSDGO1_LIST |
| 132 | # self.mock_api.return_value = orjson.dumps(resp_dict), status |
| 133 | # bsdgo1_outlet = VeSyncOutletBSDGO1( |
| 134 | # self.device_list_model(), |
| 135 | # self.manager, |
| 136 | # self.device_map(), |
| 137 | # ) |
| 138 | # assert not self.run_in_loop(bsdgo1_outlet.turn_on) |
| 139 | # assert not self.run_in_loop(bsdgo1_outlet.turn_off) |