wyzeapy 0.5.26__py3-none-any.whl → 0.5.28__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.
@@ -0,0 +1,159 @@
1
+ import unittest
2
+ from unittest.mock import AsyncMock, MagicMock
3
+ from wyzeapy.services.sensor_service import SensorService, Sensor
4
+ from wyzeapy.types import DeviceTypes, PropertyIDs
5
+ from wyzeapy.wyze_auth_lib import WyzeAuthLib
6
+
7
+
8
+ class TestSensorService(unittest.IsolatedAsyncioTestCase):
9
+ async def asyncSetUp(self):
10
+ self.mock_auth_lib = MagicMock(spec=WyzeAuthLib)
11
+ self.sensor_service = SensorService(auth_lib=self.mock_auth_lib)
12
+ self.sensor_service._get_device_info = AsyncMock()
13
+ self.sensor_service.get_updated_params = AsyncMock()
14
+ self.sensor_service.get_object_list = AsyncMock()
15
+
16
+ # Reset the class-level subscribers list
17
+ self.sensor_service._subscribers = []
18
+
19
+ # Create test sensors
20
+ self.motion_sensor = Sensor({
21
+ "device_type": DeviceTypes.MOTION_SENSOR.value,
22
+ "product_model": "PIR3U",
23
+ "mac": "MOTION123",
24
+ "nickname": "Test Motion Sensor",
25
+ "device_params": {"ip": "192.168.1.100"},
26
+ "raw_dict": {}
27
+ })
28
+
29
+ self.contact_sensor = Sensor({
30
+ "device_type": DeviceTypes.CONTACT_SENSOR.value,
31
+ "product_model": "DWS3U",
32
+ "mac": "CONTACT456",
33
+ "nickname": "Test Contact Sensor",
34
+ "device_params": {"ip": "192.168.1.101"},
35
+ "raw_dict": {}
36
+ })
37
+
38
+ async def test_update_motion_sensor_detected(self):
39
+ self.sensor_service._get_device_info.return_value = {
40
+ 'data': {
41
+ 'property_list': [
42
+ {
43
+ 'pid': PropertyIDs.MOTION_STATE.value,
44
+ 'value': '1'
45
+ }
46
+ ]
47
+ }
48
+ }
49
+
50
+ updated_sensor = await self.sensor_service.update(self.motion_sensor)
51
+ self.assertTrue(updated_sensor.detected)
52
+
53
+ async def test_update_motion_sensor_not_detected(self):
54
+ self.sensor_service._get_device_info.return_value = {
55
+ 'data': {
56
+ 'property_list': [
57
+ {
58
+ 'pid': PropertyIDs.MOTION_STATE.value,
59
+ 'value': '0'
60
+ }
61
+ ]
62
+ }
63
+ }
64
+
65
+ updated_sensor = await self.sensor_service.update(self.motion_sensor)
66
+ self.assertFalse(updated_sensor.detected)
67
+
68
+ async def test_update_contact_sensor_detected(self):
69
+ self.sensor_service._get_device_info.return_value = {
70
+ 'data': {
71
+ 'property_list': [
72
+ {
73
+ 'pid': PropertyIDs.CONTACT_STATE.value,
74
+ 'value': '1'
75
+ }
76
+ ]
77
+ }
78
+ }
79
+
80
+ updated_sensor = await self.sensor_service.update(self.contact_sensor)
81
+ self.assertTrue(updated_sensor.detected)
82
+
83
+ async def test_update_contact_sensor_not_detected(self):
84
+ self.sensor_service._get_device_info.return_value = {
85
+ 'data': {
86
+ 'property_list': [
87
+ {
88
+ 'pid': PropertyIDs.CONTACT_STATE.value,
89
+ 'value': '0'
90
+ }
91
+ ]
92
+ }
93
+ }
94
+
95
+ updated_sensor = await self.sensor_service.update(self.contact_sensor)
96
+ self.assertFalse(updated_sensor.detected)
97
+
98
+ async def test_get_sensors(self):
99
+ mock_motion_device = MagicMock()
100
+ mock_motion_device.type = DeviceTypes.MOTION_SENSOR
101
+ mock_motion_device.raw_dict = {
102
+ "device_type": DeviceTypes.MOTION_SENSOR.value,
103
+ "product_model": "PIR3U",
104
+ "mac": "MOTION123"
105
+ }
106
+
107
+ mock_contact_device = MagicMock()
108
+ mock_contact_device.type = DeviceTypes.CONTACT_SENSOR
109
+ mock_contact_device.raw_dict = {
110
+ "device_type": DeviceTypes.CONTACT_SENSOR.value,
111
+ "product_model": "DWS3U",
112
+ "mac": "CONTACT456"
113
+ }
114
+
115
+ self.sensor_service.get_object_list.return_value = [
116
+ mock_motion_device,
117
+ mock_contact_device
118
+ ]
119
+
120
+ sensors = await self.sensor_service.get_sensors()
121
+
122
+ self.assertEqual(len(sensors), 2)
123
+ self.assertIsInstance(sensors[0], Sensor)
124
+ self.assertIsInstance(sensors[1], Sensor)
125
+ self.sensor_service.get_object_list.assert_awaited_once()
126
+
127
+ async def test_register_for_updates(self):
128
+ mock_callback = MagicMock()
129
+ await self.sensor_service.register_for_updates(self.motion_sensor, mock_callback)
130
+
131
+ self.assertEqual(len(self.sensor_service._subscribers), 1)
132
+ self.assertEqual(self.sensor_service._subscribers[0][0], self.motion_sensor)
133
+ self.assertEqual(self.sensor_service._subscribers[0][1], mock_callback)
134
+
135
+ async def test_deregister_for_updates(self):
136
+ mock_callback = MagicMock()
137
+ await self.sensor_service.register_for_updates(self.motion_sensor, mock_callback)
138
+ await self.sensor_service.deregister_for_updates(self.motion_sensor)
139
+
140
+ self.assertEqual(len(self.sensor_service._subscribers), 0)
141
+
142
+ async def test_update_with_unknown_property(self):
143
+ self.sensor_service._get_device_info.return_value = {
144
+ 'data': {
145
+ 'property_list': [
146
+ {
147
+ 'pid': 'unknown_property',
148
+ 'value': '1'
149
+ }
150
+ ]
151
+ }
152
+ }
153
+
154
+ updated_sensor = await self.sensor_service.update(self.motion_sensor)
155
+ self.assertFalse(updated_sensor.detected) # Should maintain default value
156
+
157
+
158
+ if __name__ == '__main__':
159
+ unittest.main()
@@ -0,0 +1,138 @@
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()
@@ -0,0 +1,136 @@
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()
@@ -0,0 +1,161 @@
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()
wyzeapy/types.py CHANGED
@@ -28,6 +28,7 @@ class DeviceTypes(Enum):
28
28
  CHIME_SENSOR = "ChimeSensor"
29
29
  CONTACT_SENSOR = "ContactSensor"
30
30
  MOTION_SENSOR = "MotionSensor"
31
+ LEAK_SENSOR = "LeakSensor"
31
32
  WRIST = "Wrist"
32
33
  BASE_STATION = "BaseStation"
33
34
  SCALE = "WyzeScale"
@@ -43,6 +44,7 @@ class DeviceTypes(Enum):
43
44
  KEYPAD = "Keypad"
44
45
  LIGHTSTRIP = "LightStrip"
45
46
 
47
+
46
48
  class Device:
47
49
  product_type: str
48
50
  product_model: str
@@ -102,7 +104,7 @@ class PropertyIDs(Enum):
102
104
  CONTACT_STATE = "P1301"
103
105
  MOTION_STATE = "P1302"
104
106
  CAMERA_SIREN = "P1049"
105
- FLOOD_LIGHT = "P1056" # Also lamp socket on v3/v4 with lamp socket accessory
107
+ ACCESSORY = "P1056" # Is state for camera accessories, like garage doors, light sockets, and floodlights.
106
108
  SUN_MATCH = "P1528"
107
109
  MOTION_DETECTION = "P1047" # Current Motion Detection State of the Camera
108
110
  MOTION_DETECTION_TOGGLE = "P1001" # This toggles Camera Motion Detection On/Off
wyzeapy/utils.py CHANGED
@@ -4,6 +4,7 @@
4
4
  # the license with this file. If not, please write to:
5
5
  # katie@mulliken.net to receive a copy
6
6
  import base64
7
+ import binascii
7
8
  import hashlib
8
9
  from typing import Dict, Any, List, Optional
9
10
 
@@ -66,6 +67,20 @@ def wyze_decrypt(key, enc):
66
67
  return decrypt_txt
67
68
 
68
69
 
70
+ def wyze_decrypt_cbc(key: str, enc_hex_str: str) -> str:
71
+ key_hash = hashlib.md5(key.encode("utf-8")).digest()
72
+
73
+ iv = b"0123456789ABCDEF"
74
+ cipher = AES.new(key_hash, AES.MODE_CBC, iv)
75
+
76
+ encrypted_bytes = binascii.unhexlify(enc_hex_str)
77
+ decrypted_bytes = cipher.decrypt(encrypted_bytes)
78
+
79
+ # PKCS5Padding
80
+ padding_length = decrypted_bytes[-1]
81
+ return decrypted_bytes[:-padding_length].decode()
82
+
83
+
69
84
  def create_password(password: str) -> str:
70
85
  hex1 = hashlib.md5(password.encode()).hexdigest()
71
86
  hex2 = hashlib.md5(hex1.encode()).hexdigest()
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: wyzeapy
3
- Version: 0.5.26
3
+ Version: 0.5.28
4
4
  Summary: A library for interacting with Wyze devices
5
5
  License: GPL-3.0-only
6
6
  Author: Katie Mulliken
@@ -12,5 +12,5 @@ Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Classifier: Programming Language :: Python :: 3.13
14
14
  Requires-Dist: aiodns (>=3.2.0,<4.0.0)
15
- Requires-Dist: aiohttp (>=3.10.8,<4.0.0)
15
+ Requires-Dist: aiohttp (>=3.11.12,<4.0.0)
16
16
  Requires-Dist: pycryptodome (>=3.21.0,<4.0.0)