wyzeapy 0.5.28__py3-none-any.whl → 0.5.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wyzeapy/__init__.py +277 -45
- wyzeapy/const.py +9 -4
- wyzeapy/crypto.py +31 -2
- wyzeapy/exceptions.py +11 -8
- wyzeapy/payload_factory.py +205 -170
- wyzeapy/services/__init__.py +3 -0
- wyzeapy/services/base_service.py +406 -212
- wyzeapy/services/bulb_service.py +67 -63
- wyzeapy/services/camera_service.py +136 -50
- wyzeapy/services/hms_service.py +8 -17
- wyzeapy/services/irrigation_service.py +189 -0
- wyzeapy/services/lock_service.py +5 -3
- wyzeapy/services/sensor_service.py +32 -11
- wyzeapy/services/switch_service.py +6 -2
- wyzeapy/services/thermostat_service.py +29 -15
- wyzeapy/services/update_manager.py +38 -11
- wyzeapy/services/wall_switch_service.py +18 -8
- wyzeapy/tests/test_irrigation_service.py +536 -0
- wyzeapy/types.py +29 -12
- wyzeapy/utils.py +98 -17
- wyzeapy/wyze_auth_lib.py +195 -37
- wyzeapy-0.5.30.dist-info/METADATA +13 -0
- wyzeapy-0.5.30.dist-info/RECORD +24 -0
- {wyzeapy-0.5.28.dist-info → wyzeapy-0.5.30.dist-info}/WHEEL +1 -1
- wyzeapy/tests/test_bulb_service.py +0 -135
- wyzeapy/tests/test_camera_service.py +0 -180
- wyzeapy/tests/test_hms_service.py +0 -90
- wyzeapy/tests/test_lock_service.py +0 -114
- wyzeapy/tests/test_sensor_service.py +0 -159
- wyzeapy/tests/test_switch_service.py +0 -138
- wyzeapy/tests/test_thermostat_service.py +0 -136
- wyzeapy/tests/test_wall_switch_service.py +0 -161
- wyzeapy-0.5.28.dist-info/LICENSES/GPL-3.0-only.txt +0 -232
- wyzeapy-0.5.28.dist-info/METADATA +0 -16
- wyzeapy-0.5.28.dist-info/RECORD +0 -31
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from datetime import datetime, timedelta
|
|
3
|
-
from unittest.mock import AsyncMock, MagicMock
|
|
4
|
-
from wyzeapy.services.switch_service import SwitchService, SwitchUsageService, Switch
|
|
5
|
-
from wyzeapy.types import DeviceTypes, PropertyIDs
|
|
6
|
-
from wyzeapy.wyze_auth_lib import WyzeAuthLib
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TestSwitchService(unittest.IsolatedAsyncioTestCase):
|
|
10
|
-
async def asyncSetUp(self):
|
|
11
|
-
self.mock_auth_lib = MagicMock(spec=WyzeAuthLib)
|
|
12
|
-
self.switch_service = SwitchService(auth_lib=self.mock_auth_lib)
|
|
13
|
-
self.switch_service._get_property_list = AsyncMock()
|
|
14
|
-
self.switch_service.get_updated_params = AsyncMock()
|
|
15
|
-
self.switch_service.get_object_list = AsyncMock()
|
|
16
|
-
self.switch_service._set_property = AsyncMock()
|
|
17
|
-
|
|
18
|
-
# Create test switch
|
|
19
|
-
self.test_switch = Switch({
|
|
20
|
-
"device_type": DeviceTypes.PLUG.value,
|
|
21
|
-
"product_model": "WLPP1",
|
|
22
|
-
"mac": "SWITCH123",
|
|
23
|
-
"nickname": "Test Switch",
|
|
24
|
-
"device_params": {"ip": "192.168.1.100"},
|
|
25
|
-
"raw_dict": {}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
async def test_update_switch_on(self):
|
|
29
|
-
self.switch_service._get_property_list.return_value = [
|
|
30
|
-
(PropertyIDs.ON, "1"),
|
|
31
|
-
(PropertyIDs.AVAILABLE, "1")
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
updated_switch = await self.switch_service.update(self.test_switch)
|
|
35
|
-
|
|
36
|
-
self.assertTrue(updated_switch.on)
|
|
37
|
-
self.assertTrue(updated_switch.available)
|
|
38
|
-
|
|
39
|
-
async def test_update_switch_off(self):
|
|
40
|
-
self.switch_service._get_property_list.return_value = [
|
|
41
|
-
(PropertyIDs.ON, "0"),
|
|
42
|
-
(PropertyIDs.AVAILABLE, "1")
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
updated_switch = await self.switch_service.update(self.test_switch)
|
|
46
|
-
|
|
47
|
-
self.assertFalse(updated_switch.on)
|
|
48
|
-
self.assertTrue(updated_switch.available)
|
|
49
|
-
|
|
50
|
-
async def test_get_switches(self):
|
|
51
|
-
mock_plug = MagicMock()
|
|
52
|
-
mock_plug.type = DeviceTypes.PLUG
|
|
53
|
-
mock_plug.raw_dict = {
|
|
54
|
-
"device_type": DeviceTypes.PLUG.value,
|
|
55
|
-
"product_model": "WLPP1",
|
|
56
|
-
"mac": "PLUG123"
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
mock_outdoor_plug = MagicMock()
|
|
60
|
-
mock_outdoor_plug.type = DeviceTypes.OUTDOOR_PLUG
|
|
61
|
-
mock_outdoor_plug.raw_dict = {
|
|
62
|
-
"device_type": DeviceTypes.OUTDOOR_PLUG.value,
|
|
63
|
-
"product_model": "WLPPO",
|
|
64
|
-
"mac": "OUTPLUG456"
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
self.switch_service.get_object_list.return_value = [
|
|
68
|
-
mock_plug,
|
|
69
|
-
mock_outdoor_plug
|
|
70
|
-
]
|
|
71
|
-
|
|
72
|
-
switches = await self.switch_service.get_switches()
|
|
73
|
-
|
|
74
|
-
self.assertEqual(len(switches), 2)
|
|
75
|
-
self.assertIsInstance(switches[0], Switch)
|
|
76
|
-
self.assertIsInstance(switches[1], Switch)
|
|
77
|
-
self.switch_service.get_object_list.assert_awaited_once()
|
|
78
|
-
|
|
79
|
-
async def test_turn_on(self):
|
|
80
|
-
await self.switch_service.turn_on(self.test_switch)
|
|
81
|
-
self.switch_service._set_property.assert_awaited_with(
|
|
82
|
-
self.test_switch,
|
|
83
|
-
PropertyIDs.ON.value,
|
|
84
|
-
"1"
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
async def test_turn_off(self):
|
|
88
|
-
await self.switch_service.turn_off(self.test_switch)
|
|
89
|
-
self.switch_service._set_property.assert_awaited_with(
|
|
90
|
-
self.test_switch,
|
|
91
|
-
PropertyIDs.ON.value,
|
|
92
|
-
"0"
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class TestSwitchUsageService(unittest.IsolatedAsyncioTestCase):
|
|
97
|
-
async def asyncSetUp(self):
|
|
98
|
-
self.mock_auth_lib = MagicMock(spec=WyzeAuthLib)
|
|
99
|
-
self.usage_service = SwitchUsageService(auth_lib=self.mock_auth_lib)
|
|
100
|
-
self.usage_service._get_plug_history = AsyncMock()
|
|
101
|
-
|
|
102
|
-
# Create test switch
|
|
103
|
-
self.test_switch = Switch({
|
|
104
|
-
"device_type": DeviceTypes.PLUG.value,
|
|
105
|
-
"product_model": "WLPP1",
|
|
106
|
-
"mac": "SWITCH123",
|
|
107
|
-
"nickname": "Test Switch",
|
|
108
|
-
"device_params": {"ip": "192.168.1.100"},
|
|
109
|
-
"raw_dict": {}
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
async def test_update_usage_history(self):
|
|
113
|
-
mock_usage_data = {
|
|
114
|
-
"total_power": 100,
|
|
115
|
-
"time_series": [
|
|
116
|
-
{"power": 10, "timestamp": 1234567890},
|
|
117
|
-
{"power": 20, "timestamp": 1234567891}
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
self.usage_service._get_plug_history.return_value = mock_usage_data
|
|
121
|
-
|
|
122
|
-
# Calculate expected timestamps
|
|
123
|
-
now = datetime.now()
|
|
124
|
-
expected_end_time = int(datetime.timestamp(now) * 1000)
|
|
125
|
-
expected_start_time = int(datetime.timestamp(now - timedelta(hours=25)) * 1000)
|
|
126
|
-
|
|
127
|
-
updated_switch = await self.usage_service.update(self.test_switch)
|
|
128
|
-
|
|
129
|
-
self.assertEqual(updated_switch.usage_history, mock_usage_data)
|
|
130
|
-
self.usage_service._get_plug_history.assert_awaited_with(
|
|
131
|
-
self.test_switch,
|
|
132
|
-
expected_start_time,
|
|
133
|
-
expected_end_time
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if __name__ == '__main__':
|
|
138
|
-
unittest.main()
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from unittest.mock import AsyncMock, MagicMock
|
|
3
|
-
from wyzeapy.services.thermostat_service import (
|
|
4
|
-
ThermostatService, Thermostat, HVACMode, FanMode,
|
|
5
|
-
TemperatureUnit, Preset, HVACState, ThermostatProps
|
|
6
|
-
)
|
|
7
|
-
from wyzeapy.types import DeviceTypes
|
|
8
|
-
from wyzeapy.wyze_auth_lib import WyzeAuthLib
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TestThermostatService(unittest.IsolatedAsyncioTestCase):
|
|
12
|
-
async def asyncSetUp(self):
|
|
13
|
-
self.mock_auth_lib = MagicMock(spec=WyzeAuthLib)
|
|
14
|
-
self.thermostat_service = ThermostatService(auth_lib=self.mock_auth_lib)
|
|
15
|
-
self.thermostat_service._thermostat_get_iot_prop = AsyncMock()
|
|
16
|
-
self.thermostat_service._thermostat_set_iot_prop = AsyncMock()
|
|
17
|
-
self.thermostat_service.get_object_list = AsyncMock()
|
|
18
|
-
|
|
19
|
-
# Create test thermostat
|
|
20
|
-
self.test_thermostat = Thermostat({
|
|
21
|
-
"device_type": DeviceTypes.THERMOSTAT.value,
|
|
22
|
-
"product_model": "WLPTH1",
|
|
23
|
-
"mac": "THERM123",
|
|
24
|
-
"nickname": "Test Thermostat",
|
|
25
|
-
"device_params": {"ip": "192.168.1.100"},
|
|
26
|
-
"raw_dict": {}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
async def test_update_thermostat(self):
|
|
30
|
-
self.thermostat_service._thermostat_get_iot_prop.return_value = {
|
|
31
|
-
'data': {
|
|
32
|
-
'props': {
|
|
33
|
-
'temp_unit': 'F',
|
|
34
|
-
'cool_sp': '74',
|
|
35
|
-
'heat_sp': '64',
|
|
36
|
-
'fan_mode': 'auto',
|
|
37
|
-
'mode_sys': 'auto',
|
|
38
|
-
'current_scenario': 'home',
|
|
39
|
-
'temperature': '71.5',
|
|
40
|
-
'iot_state': 'connected',
|
|
41
|
-
'humidity': '50',
|
|
42
|
-
'working_state': 'idle'
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
updated_thermostat = await self.thermostat_service.update(self.test_thermostat)
|
|
48
|
-
|
|
49
|
-
self.assertEqual(updated_thermostat.temp_unit, TemperatureUnit.FAHRENHEIT)
|
|
50
|
-
self.assertEqual(updated_thermostat.cool_set_point, 74)
|
|
51
|
-
self.assertEqual(updated_thermostat.heat_set_point, 64)
|
|
52
|
-
self.assertEqual(updated_thermostat.fan_mode, FanMode.AUTO)
|
|
53
|
-
self.assertEqual(updated_thermostat.hvac_mode, HVACMode.AUTO)
|
|
54
|
-
self.assertEqual(updated_thermostat.preset, Preset.HOME)
|
|
55
|
-
self.assertEqual(updated_thermostat.temperature, 71.5)
|
|
56
|
-
self.assertTrue(updated_thermostat.available)
|
|
57
|
-
self.assertEqual(updated_thermostat.humidity, 50)
|
|
58
|
-
self.assertEqual(updated_thermostat.hvac_state, HVACState.IDLE)
|
|
59
|
-
|
|
60
|
-
async def test_get_thermostats(self):
|
|
61
|
-
mock_thermostat = MagicMock()
|
|
62
|
-
mock_thermostat.type = DeviceTypes.THERMOSTAT
|
|
63
|
-
mock_thermostat.raw_dict = {
|
|
64
|
-
"device_type": DeviceTypes.THERMOSTAT.value,
|
|
65
|
-
"product_model": "WLPTH1",
|
|
66
|
-
"mac": "THERM123"
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
self.thermostat_service.get_object_list.return_value = [mock_thermostat]
|
|
70
|
-
|
|
71
|
-
thermostats = await self.thermostat_service.get_thermostats()
|
|
72
|
-
|
|
73
|
-
self.assertEqual(len(thermostats), 1)
|
|
74
|
-
self.assertIsInstance(thermostats[0], Thermostat)
|
|
75
|
-
self.thermostat_service.get_object_list.assert_awaited_once()
|
|
76
|
-
|
|
77
|
-
async def test_set_cool_point(self):
|
|
78
|
-
await self.thermostat_service.set_cool_point(self.test_thermostat, 75)
|
|
79
|
-
self.thermostat_service._thermostat_set_iot_prop.assert_awaited_with(
|
|
80
|
-
self.test_thermostat,
|
|
81
|
-
ThermostatProps.COOL_SP,
|
|
82
|
-
75
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
async def test_set_heat_point(self):
|
|
86
|
-
await self.thermostat_service.set_heat_point(self.test_thermostat, 68)
|
|
87
|
-
self.thermostat_service._thermostat_set_iot_prop.assert_awaited_with(
|
|
88
|
-
self.test_thermostat,
|
|
89
|
-
ThermostatProps.HEAT_SP,
|
|
90
|
-
68
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
async def test_set_hvac_mode(self):
|
|
94
|
-
await self.thermostat_service.set_hvac_mode(self.test_thermostat, HVACMode.COOL)
|
|
95
|
-
self.thermostat_service._thermostat_set_iot_prop.assert_awaited_with(
|
|
96
|
-
self.test_thermostat,
|
|
97
|
-
ThermostatProps.MODE_SYS,
|
|
98
|
-
HVACMode.COOL.value
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
async def test_set_fan_mode(self):
|
|
102
|
-
await self.thermostat_service.set_fan_mode(self.test_thermostat, FanMode.ON)
|
|
103
|
-
self.thermostat_service._thermostat_set_iot_prop.assert_awaited_with(
|
|
104
|
-
self.test_thermostat,
|
|
105
|
-
ThermostatProps.FAN_MODE,
|
|
106
|
-
FanMode.ON.value
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
async def test_set_preset(self):
|
|
110
|
-
await self.thermostat_service.set_preset(self.test_thermostat, Preset.AWAY)
|
|
111
|
-
self.thermostat_service._thermostat_set_iot_prop.assert_awaited_with(
|
|
112
|
-
self.test_thermostat,
|
|
113
|
-
ThermostatProps.CURRENT_SCENARIO,
|
|
114
|
-
Preset.AWAY.value
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
async def test_update_with_invalid_property(self):
|
|
118
|
-
self.thermostat_service._thermostat_get_iot_prop.return_value = {
|
|
119
|
-
'data': {
|
|
120
|
-
'props': {
|
|
121
|
-
'invalid_property': 'some_value',
|
|
122
|
-
'temperature': '71.5'
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
updated_thermostat = await self.thermostat_service.update(self.test_thermostat)
|
|
128
|
-
self.assertEqual(updated_thermostat.temperature, 71.5)
|
|
129
|
-
# Other properties should maintain their default values
|
|
130
|
-
self.assertEqual(updated_thermostat.temp_unit, TemperatureUnit.FAHRENHEIT)
|
|
131
|
-
self.assertEqual(updated_thermostat.cool_set_point, 74)
|
|
132
|
-
self.assertEqual(updated_thermostat.heat_set_point, 64)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if __name__ == '__main__':
|
|
136
|
-
unittest.main()
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from unittest.mock import AsyncMock, MagicMock
|
|
3
|
-
from wyzeapy.services.wall_switch_service import (
|
|
4
|
-
WallSwitchService, WallSwitch, SinglePressType, WallSwitchProps
|
|
5
|
-
)
|
|
6
|
-
from wyzeapy.types import DeviceTypes
|
|
7
|
-
from wyzeapy.wyze_auth_lib import WyzeAuthLib
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class TestWallSwitchService(unittest.IsolatedAsyncioTestCase):
|
|
11
|
-
async def asyncSetUp(self):
|
|
12
|
-
self.mock_auth_lib = MagicMock(spec=WyzeAuthLib)
|
|
13
|
-
self.wall_switch_service = WallSwitchService(auth_lib=self.mock_auth_lib)
|
|
14
|
-
self.wall_switch_service._wall_switch_get_iot_prop = AsyncMock()
|
|
15
|
-
self.wall_switch_service._wall_switch_set_iot_prop = AsyncMock()
|
|
16
|
-
self.wall_switch_service.get_object_list = AsyncMock()
|
|
17
|
-
|
|
18
|
-
# Create test wall switch
|
|
19
|
-
self.test_switch = WallSwitch({
|
|
20
|
-
"device_type": DeviceTypes.COMMON.value,
|
|
21
|
-
"product_model": "LD_SS1",
|
|
22
|
-
"mac": "SWITCH123",
|
|
23
|
-
"nickname": "Test Wall Switch",
|
|
24
|
-
"device_params": {"ip": "192.168.1.100"},
|
|
25
|
-
"raw_dict": {}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
async def test_update_wall_switch(self):
|
|
29
|
-
self.wall_switch_service._wall_switch_get_iot_prop.return_value = {
|
|
30
|
-
'data': {
|
|
31
|
-
'props': {
|
|
32
|
-
'iot_state': 'connected',
|
|
33
|
-
'switch-power': True,
|
|
34
|
-
'switch-iot': False,
|
|
35
|
-
'single_press_type': 1
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
updated_switch = await self.wall_switch_service.update(self.test_switch)
|
|
41
|
-
|
|
42
|
-
self.assertTrue(updated_switch.available)
|
|
43
|
-
self.assertTrue(updated_switch.switch_power)
|
|
44
|
-
self.assertFalse(updated_switch.switch_iot)
|
|
45
|
-
self.assertEqual(updated_switch.single_press_type, SinglePressType.CLASSIC)
|
|
46
|
-
# Test the property that depends on single_press_type
|
|
47
|
-
self.assertTrue(updated_switch.on) # Should be True because switch_power is True and type is CLASSIC
|
|
48
|
-
|
|
49
|
-
async def test_update_wall_switch_iot_mode(self):
|
|
50
|
-
self.wall_switch_service._wall_switch_get_iot_prop.return_value = {
|
|
51
|
-
'data': {
|
|
52
|
-
'props': {
|
|
53
|
-
'iot_state': 'connected',
|
|
54
|
-
'switch-power': False,
|
|
55
|
-
'switch-iot': True,
|
|
56
|
-
'single_press_type': 2
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
updated_switch = await self.wall_switch_service.update(self.test_switch)
|
|
62
|
-
|
|
63
|
-
self.assertTrue(updated_switch.available)
|
|
64
|
-
self.assertFalse(updated_switch.switch_power)
|
|
65
|
-
self.assertTrue(updated_switch.switch_iot)
|
|
66
|
-
self.assertEqual(updated_switch.single_press_type, SinglePressType.IOT)
|
|
67
|
-
# Test the property that depends on single_press_type
|
|
68
|
-
self.assertTrue(updated_switch.on) # Should be True because switch_iot is True and type is IOT
|
|
69
|
-
|
|
70
|
-
async def test_get_switches(self):
|
|
71
|
-
mock_switch = MagicMock()
|
|
72
|
-
mock_switch.type = DeviceTypes.COMMON
|
|
73
|
-
mock_switch.product_model = "LD_SS1"
|
|
74
|
-
mock_switch.raw_dict = {
|
|
75
|
-
"device_type": DeviceTypes.COMMON.value,
|
|
76
|
-
"product_model": "LD_SS1",
|
|
77
|
-
"mac": "SWITCH123"
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
# Add a non-wall switch device to test filtering
|
|
81
|
-
mock_other_device = MagicMock()
|
|
82
|
-
mock_other_device.type = DeviceTypes.COMMON
|
|
83
|
-
mock_other_device.product_model = "OTHER_MODEL"
|
|
84
|
-
|
|
85
|
-
self.wall_switch_service.get_object_list.return_value = [
|
|
86
|
-
mock_switch,
|
|
87
|
-
mock_other_device
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
switches = await self.wall_switch_service.get_switches()
|
|
91
|
-
|
|
92
|
-
self.assertEqual(len(switches), 1)
|
|
93
|
-
self.assertIsInstance(switches[0], WallSwitch)
|
|
94
|
-
self.wall_switch_service.get_object_list.assert_awaited_once()
|
|
95
|
-
|
|
96
|
-
async def test_turn_on_classic_mode(self):
|
|
97
|
-
self.test_switch.single_press_type = SinglePressType.CLASSIC
|
|
98
|
-
await self.wall_switch_service.turn_on(self.test_switch)
|
|
99
|
-
self.wall_switch_service._wall_switch_set_iot_prop.assert_awaited_with(
|
|
100
|
-
self.test_switch,
|
|
101
|
-
WallSwitchProps.SWITCH_POWER,
|
|
102
|
-
True
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
async def test_turn_off_classic_mode(self):
|
|
106
|
-
self.test_switch.single_press_type = SinglePressType.CLASSIC
|
|
107
|
-
await self.wall_switch_service.turn_off(self.test_switch)
|
|
108
|
-
self.wall_switch_service._wall_switch_set_iot_prop.assert_awaited_with(
|
|
109
|
-
self.test_switch,
|
|
110
|
-
WallSwitchProps.SWITCH_POWER,
|
|
111
|
-
False
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
async def test_turn_on_iot_mode(self):
|
|
115
|
-
self.test_switch.single_press_type = SinglePressType.IOT
|
|
116
|
-
await self.wall_switch_service.turn_on(self.test_switch)
|
|
117
|
-
self.wall_switch_service._wall_switch_set_iot_prop.assert_awaited_with(
|
|
118
|
-
self.test_switch,
|
|
119
|
-
WallSwitchProps.SWITCH_IOT,
|
|
120
|
-
True
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
async def test_turn_off_iot_mode(self):
|
|
124
|
-
self.test_switch.single_press_type = SinglePressType.IOT
|
|
125
|
-
await self.wall_switch_service.turn_off(self.test_switch)
|
|
126
|
-
self.wall_switch_service._wall_switch_set_iot_prop.assert_awaited_with(
|
|
127
|
-
self.test_switch,
|
|
128
|
-
WallSwitchProps.SWITCH_IOT,
|
|
129
|
-
False
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
async def test_set_single_press_type(self):
|
|
133
|
-
await self.wall_switch_service.set_single_press_type(
|
|
134
|
-
self.test_switch,
|
|
135
|
-
SinglePressType.IOT
|
|
136
|
-
)
|
|
137
|
-
self.wall_switch_service._wall_switch_set_iot_prop.assert_awaited_with(
|
|
138
|
-
self.test_switch,
|
|
139
|
-
WallSwitchProps.SINGLE_PRESS_TYPE,
|
|
140
|
-
SinglePressType.IOT.value
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
async def test_update_with_invalid_property(self):
|
|
144
|
-
self.wall_switch_service._wall_switch_get_iot_prop.return_value = {
|
|
145
|
-
'data': {
|
|
146
|
-
'props': {
|
|
147
|
-
'invalid_property': 'some_value',
|
|
148
|
-
'switch-power': True
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
updated_switch = await self.wall_switch_service.update(self.test_switch)
|
|
154
|
-
self.assertTrue(updated_switch.switch_power)
|
|
155
|
-
# Other properties should maintain their default values
|
|
156
|
-
self.assertEqual(updated_switch.single_press_type, SinglePressType.CLASSIC)
|
|
157
|
-
self.assertFalse(updated_switch.switch_iot)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if __name__ == '__main__':
|
|
161
|
-
unittest.main()
|