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.
@@ -1,135 +0,0 @@
1
- import unittest
2
- from unittest.mock import AsyncMock, MagicMock
3
- from wyzeapy.services.bulb_service import BulbService, Bulb
4
- from wyzeapy.types import DeviceTypes, PropertyIDs
5
-
6
-
7
- class TestBulbService(unittest.IsolatedAsyncioTestCase):
8
- async def asyncSetUp(self):
9
- mock_auth_lib = MagicMock()
10
- self.bulb_service = BulbService(auth_lib=mock_auth_lib)
11
- self.bulb_service._get_property_list = AsyncMock()
12
- self.bulb_service.get_updated_params = AsyncMock()
13
-
14
- async def test_update_bulb_basic_properties(self):
15
- mock_bulb = Bulb({
16
- "device_type": "Light",
17
- "product_model": "WLPA19",
18
- "mac": "TEST123",
19
- "raw_dict": {},
20
- "device_params": {"ip": "192.168.1.100"},
21
- "prop_map": {},
22
- 'product_type': DeviceTypes.MESH_LIGHT.value
23
- })
24
-
25
- # Mock the property list response
26
- self.bulb_service._get_property_list.return_value = [
27
- (PropertyIDs.BRIGHTNESS, "75"),
28
- (PropertyIDs.COLOR_TEMP, "4000"),
29
- (PropertyIDs.ON, "1"),
30
- (PropertyIDs.AVAILABLE, "1")
31
- ]
32
-
33
- updated_bulb = await self.bulb_service.update(mock_bulb)
34
-
35
- self.assertEqual(updated_bulb.brightness, 75)
36
- self.assertEqual(updated_bulb.color_temp, 4000)
37
- self.assertTrue(updated_bulb.on)
38
- self.assertTrue(updated_bulb.available)
39
-
40
- async def test_update_bulb_lightstrip_properties(self):
41
- mock_bulb = Bulb({
42
- "device_type": "Light",
43
- "product_model": "WLST19",
44
- "mac": "TEST456",
45
- "raw_dict": {},
46
- "device_params": {"ip": "192.168.1.101"},
47
- "prop_map": {},
48
- 'product_type': DeviceTypes.LIGHTSTRIP.value
49
- })
50
- mock_bulb.product_type = DeviceTypes.LIGHTSTRIP
51
-
52
- # Mock the property list response with the corrected color format (no # symbol)
53
- self.bulb_service._get_property_list.return_value = [
54
- (PropertyIDs.COLOR, "FF0000"), # Removed the # symbol
55
- (PropertyIDs.COLOR_MODE, "1"),
56
- (PropertyIDs.LIGHTSTRIP_EFFECTS, "rainbow"),
57
- (PropertyIDs.LIGHTSTRIP_MUSIC_MODE, "1"),
58
- (PropertyIDs.ON, "1"),
59
- (PropertyIDs.AVAILABLE, "1")
60
- ]
61
-
62
- updated_bulb = await self.bulb_service.update(mock_bulb)
63
-
64
- self.assertEqual(updated_bulb.color, "FF0000")
65
- self.assertEqual(updated_bulb.color_mode, "1")
66
- self.assertEqual(updated_bulb.effects, "rainbow")
67
- self.assertTrue(updated_bulb.music_mode)
68
- self.assertTrue(updated_bulb.on)
69
- self.assertTrue(updated_bulb.available)
70
-
71
- async def test_update_bulb_sun_match(self):
72
- mock_bulb = Bulb({
73
- "device_type": "Light",
74
- "product_model": "WLPA19",
75
- "mac": "TEST789",
76
- "raw_dict": {},
77
- "device_params": {"ip": "192.168.1.102"},
78
- "prop_map": {},
79
- 'product_type': DeviceTypes.MESH_LIGHT.value
80
- })
81
-
82
- # Mock the property list response
83
- self.bulb_service._get_property_list.return_value = [
84
- (PropertyIDs.SUN_MATCH, "1"),
85
- (PropertyIDs.ON, "1"),
86
- (PropertyIDs.AVAILABLE, "1")
87
- ]
88
-
89
- updated_bulb = await self.bulb_service.update(mock_bulb)
90
-
91
- self.assertTrue(updated_bulb.sun_match)
92
- self.assertTrue(updated_bulb.on)
93
- self.assertTrue(updated_bulb.available)
94
-
95
- async def test_update_bulb_invalid_color_temp(self):
96
- mock_bulb = Bulb({
97
- "device_type": "Light",
98
- "product_model": "WLPA19",
99
- "mac": "TEST101",
100
- "raw_dict": {},
101
- "device_params": {"ip": "192.168.1.103"},
102
- "prop_map": {},
103
- 'product_type': DeviceTypes.MESH_LIGHT.value
104
- })
105
-
106
- # Mock the property list response with invalid color temp
107
- self.bulb_service._get_property_list.return_value = [
108
- (PropertyIDs.COLOR_TEMP, "invalid"),
109
- (PropertyIDs.ON, "1")
110
- ]
111
-
112
- updated_bulb = await self.bulb_service.update(mock_bulb)
113
-
114
- # Should default to 2700K when invalid
115
- self.assertEqual(updated_bulb.color_temp, 2700)
116
- self.assertTrue(updated_bulb.on)
117
-
118
- async def test_get_bulbs(self):
119
- mock_device = MagicMock()
120
- mock_device.type = DeviceTypes.LIGHT
121
- mock_device.raw_dict = {
122
- "device_type": "Light",
123
- "product_model": "WLPA19",
124
- "device_params": {"ip": "192.168.1.104"},
125
- "prop_map": {},
126
- 'product_type': DeviceTypes.MESH_LIGHT.value
127
- }
128
-
129
- self.bulb_service.get_object_list = AsyncMock(return_value=[mock_device])
130
-
131
- bulbs = await self.bulb_service.get_bulbs()
132
-
133
- self.assertEqual(len(bulbs), 1)
134
- self.assertIsInstance(bulbs[0], Bulb)
135
- self.bulb_service.get_object_list.assert_awaited_once()
@@ -1,180 +0,0 @@
1
- import unittest
2
- from unittest.mock import AsyncMock, MagicMock
3
- from wyzeapy.services.camera_service import CameraService, Camera, DEVICEMGMT_API_MODELS
4
- from wyzeapy.types import DeviceTypes, PropertyIDs, Event
5
- from wyzeapy.wyze_auth_lib import WyzeAuthLib
6
-
7
-
8
- class TestCameraService(unittest.IsolatedAsyncioTestCase):
9
- async def asyncSetUp(self):
10
- self.mock_auth_lib = MagicMock(spec=WyzeAuthLib)
11
- self.camera_service = CameraService(auth_lib=self.mock_auth_lib)
12
- self.camera_service._get_property_list = AsyncMock()
13
- self.camera_service._get_event_list = AsyncMock()
14
- self.camera_service._run_action = AsyncMock()
15
- self.camera_service._run_action_devicemgmt = AsyncMock()
16
- self.camera_service._set_property = AsyncMock()
17
- self.camera_service._set_property_list = AsyncMock()
18
- self.camera_service._set_toggle = AsyncMock()
19
- self.camera_service.get_updated_params = AsyncMock()
20
-
21
- # Create a test camera
22
- self.test_camera = Camera({
23
- "device_type": DeviceTypes.CAMERA.value,
24
- "product_model": "WYZEC1",
25
- "mac": "TEST123",
26
- "nickname": "Test Camera",
27
- "device_params": {"ip": "192.168.1.100"},
28
- "raw_dict": {}
29
- })
30
-
31
- async def test_update_legacy_camera(self):
32
- # Mock responses
33
- self.camera_service._get_event_list.return_value = {
34
- 'data': {
35
- 'event_list': [{
36
- 'event_ts': 1234567890,
37
- 'device_mac': 'TEST123',
38
- 'event_type': 'motion'
39
- }]
40
- }
41
- }
42
-
43
- self.camera_service._get_property_list.return_value = [
44
- (PropertyIDs.AVAILABLE, "1"),
45
- (PropertyIDs.ON, "1"),
46
- (PropertyIDs.CAMERA_SIREN, "0"),
47
- (PropertyIDs.ACCESSORY, "0"),
48
- (PropertyIDs.NOTIFICATION, "1"),
49
- (PropertyIDs.MOTION_DETECTION, "1")
50
- ]
51
-
52
- updated_camera = await self.camera_service.update(self.test_camera)
53
-
54
- self.assertTrue(updated_camera.available)
55
- self.assertTrue(updated_camera.on)
56
- self.assertFalse(updated_camera.siren)
57
- self.assertFalse(updated_camera.floodlight)
58
- self.assertTrue(updated_camera.notify)
59
- self.assertTrue(updated_camera.motion)
60
- self.assertIsNotNone(updated_camera.last_event)
61
- self.assertEqual(updated_camera.last_event_ts, 1234567890)
62
-
63
- async def test_update_devicemgmt_camera(self):
64
- # Create a test camera using new API model
65
- devicemgmt_camera = Camera({
66
- "device_type": DeviceTypes.CAMERA.value,
67
- "product_model": "LD_CFP", # Floodlight pro model
68
- "mac": "TEST456",
69
- "nickname": "Test DeviceMgmt Camera",
70
- "device_params": {"ip": "192.168.1.101"},
71
- "raw_dict": {}
72
- })
73
-
74
- self.camera_service._get_iot_prop_devicemgmt = AsyncMock(return_value={
75
- 'data': {
76
- 'capabilities': [
77
- {
78
- 'name': 'camera',
79
- 'properties': {'motion-detect-recording': True}
80
- },
81
- {
82
- 'name': 'floodlight',
83
- 'properties': {'on': True}
84
- },
85
- {
86
- 'name': 'siren',
87
- 'properties': {'state': True}
88
- },
89
- {
90
- 'name': 'iot-device',
91
- 'properties': {
92
- 'push-switch': True,
93
- 'iot-power': True,
94
- 'iot-state': True
95
- }
96
- }
97
- ]
98
- }
99
- })
100
-
101
- updated_camera = await self.camera_service.update(devicemgmt_camera)
102
-
103
- self.assertTrue(updated_camera.available)
104
- self.assertTrue(updated_camera.on)
105
- self.assertTrue(updated_camera.siren)
106
- self.assertTrue(updated_camera.floodlight)
107
- self.assertTrue(updated_camera.notify)
108
- self.assertTrue(updated_camera.motion)
109
-
110
- async def test_turn_on_off_legacy_camera(self):
111
- await self.camera_service.turn_on(self.test_camera)
112
- self.camera_service._run_action.assert_awaited_with(self.test_camera, "power_on")
113
-
114
- await self.camera_service.turn_off(self.test_camera)
115
- self.camera_service._run_action.assert_awaited_with(self.test_camera, "power_off")
116
-
117
- async def test_siren_control_legacy_camera(self):
118
- await self.camera_service.siren_on(self.test_camera)
119
- self.camera_service._run_action.assert_awaited_with(self.test_camera, "siren_on")
120
-
121
- await self.camera_service.siren_off(self.test_camera)
122
- self.camera_service._run_action.assert_awaited_with(self.test_camera, "siren_off")
123
-
124
- async def test_floodlight_control_legacy_camera(self):
125
- await self.camera_service.floodlight_on(self.test_camera)
126
- self.camera_service._set_property.assert_awaited_with(
127
- self.test_camera,
128
- PropertyIDs.ACCESSORY.value,
129
- "1"
130
- )
131
-
132
- await self.camera_service.floodlight_off(self.test_camera)
133
- self.camera_service._set_property.assert_awaited_with(
134
- self.test_camera,
135
- PropertyIDs.ACCESSORY.value,
136
- "2"
137
- )
138
-
139
- async def test_notification_control_legacy_camera(self):
140
- await self.camera_service.turn_on_notifications(self.test_camera)
141
- self.camera_service._set_property.assert_awaited_with(
142
- self.test_camera,
143
- PropertyIDs.NOTIFICATION.value,
144
- "1"
145
- )
146
-
147
- await self.camera_service.turn_off_notifications(self.test_camera)
148
- self.camera_service._set_property.assert_awaited_with(
149
- self.test_camera,
150
- PropertyIDs.NOTIFICATION.value,
151
- "0"
152
- )
153
-
154
- async def test_motion_detection_control_legacy_camera(self):
155
- await self.camera_service.turn_on_motion_detection(self.test_camera)
156
- self.camera_service._set_property.assert_any_await(
157
- self.test_camera,
158
- PropertyIDs.MOTION_DETECTION.value,
159
- "1"
160
- )
161
- self.camera_service._set_property.assert_any_await(
162
- self.test_camera,
163
- PropertyIDs.MOTION_DETECTION_TOGGLE.value,
164
- "1"
165
- )
166
-
167
- await self.camera_service.turn_off_motion_detection(self.test_camera)
168
- self.camera_service._set_property.assert_any_await(
169
- self.test_camera,
170
- PropertyIDs.MOTION_DETECTION.value,
171
- "0"
172
- )
173
- self.camera_service._set_property.assert_any_await(
174
- self.test_camera,
175
- PropertyIDs.MOTION_DETECTION_TOGGLE.value,
176
- "0"
177
- )
178
-
179
- if __name__ == '__main__':
180
- unittest.main()
@@ -1,90 +0,0 @@
1
- import unittest
2
- from unittest.mock import AsyncMock, MagicMock
3
- from wyzeapy.services.hms_service import HMSService, HMSMode
4
- from wyzeapy.wyze_auth_lib import WyzeAuthLib
5
-
6
- class TestHMSService(unittest.IsolatedAsyncioTestCase):
7
- async def asyncSetUp(self):
8
- self.mock_auth_lib = MagicMock(spec=WyzeAuthLib)
9
- self.hms_service = await HMSService.create(self.mock_auth_lib)
10
- self.hms_service._get_plan_binding_list_by_user = AsyncMock()
11
- self.hms_service._monitoring_profile_state_status = AsyncMock()
12
- self.hms_service._monitoring_profile_active = AsyncMock()
13
- self.hms_service._disable_reme_alarm = AsyncMock()
14
-
15
- async def test_update_changing_mode(self):
16
- self.hms_service._monitoring_profile_state_status.return_value = {'message': 'changing'}
17
-
18
- mode = await self.hms_service.update('test_hms_id')
19
- self.assertEqual(mode, HMSMode.CHANGING)
20
-
21
- async def test_update_disarmed_mode(self):
22
- self.hms_service._monitoring_profile_state_status.return_value = {'message': 'disarm'}
23
-
24
- mode = await self.hms_service.update('test_hms_id')
25
- self.assertEqual(mode, HMSMode.DISARMED)
26
-
27
- async def test_update_away_mode(self):
28
- self.hms_service._monitoring_profile_state_status.return_value = {'message': 'away'}
29
-
30
- mode = await self.hms_service.update('test_hms_id')
31
- self.assertEqual(mode, HMSMode.AWAY)
32
-
33
- async def test_update_home_mode(self):
34
- self.hms_service._monitoring_profile_state_status.return_value = {'message': 'home'}
35
-
36
- mode = await self.hms_service.update('test_hms_id')
37
- self.assertEqual(mode, HMSMode.HOME)
38
-
39
- async def test_set_mode_disarmed(self):
40
- self.hms_service._hms_id = 'test_hms_id'
41
-
42
- await self.hms_service.set_mode(HMSMode.DISARMED)
43
-
44
- self.hms_service._disable_reme_alarm.assert_awaited_with('test_hms_id')
45
- self.hms_service._monitoring_profile_active.assert_awaited_with('test_hms_id', 0, 0)
46
-
47
- async def test_set_mode_away(self):
48
- self.hms_service._hms_id = 'test_hms_id'
49
-
50
- await self.hms_service.set_mode(HMSMode.AWAY)
51
-
52
- self.hms_service._monitoring_profile_active.assert_awaited_with('test_hms_id', 0, 1)
53
-
54
- async def test_set_mode_home(self):
55
- self.hms_service._hms_id = 'test_hms_id'
56
-
57
- await self.hms_service.set_mode(HMSMode.HOME)
58
-
59
- self.hms_service._monitoring_profile_active.assert_awaited_with('test_hms_id', 1, 0)
60
-
61
- async def test_get_hms_id_with_existing_id(self):
62
- self.hms_service._hms_id = 'existing_hms_id'
63
- hms_id = await self.hms_service._get_hms_id()
64
- self.assertEqual(hms_id, 'existing_hms_id')
65
-
66
- async def test_get_hms_id_with_no_hms(self):
67
- self.hms_service._hms_id = None
68
- self.hms_service._get_plan_binding_list_by_user.return_value = {'data': []}
69
-
70
- hms_id = await self.hms_service._get_hms_id()
71
- self.assertIsNone(hms_id)
72
-
73
- async def test_get_hms_id_finds_id(self):
74
- self.hms_service._hms_id = None
75
- self.hms_service._get_plan_binding_list_by_user.return_value = {
76
- 'data': [
77
- {
78
- 'deviceList': [
79
- {'device_id': 'found_hms_id'}
80
- ]
81
- }
82
- ]
83
- }
84
-
85
- hms_id = await self.hms_service._get_hms_id()
86
- self.assertEqual(hms_id, 'found_hms_id')
87
- self.assertEqual(self.hms_service._hms_id, 'found_hms_id')
88
-
89
- if __name__ == '__main__':
90
- unittest.main()
@@ -1,114 +0,0 @@
1
- import unittest
2
- from unittest.mock import AsyncMock, MagicMock
3
- from wyzeapy.services.lock_service import LockService, Lock
4
- from wyzeapy.types import DeviceTypes
5
- from wyzeapy.exceptions import UnknownApiError
6
-
7
- class TestLockService(unittest.IsolatedAsyncioTestCase):
8
- async def asyncSetUp(self):
9
- mock_auth_lib = MagicMock()
10
- self.lock_service = LockService(auth_lib=mock_auth_lib)
11
- self.lock_service._get_lock_info = AsyncMock()
12
- self.lock_service._lock_control = AsyncMock()
13
-
14
- async def test_update_lock_online(self):
15
- mock_lock = Lock({
16
- "device_type": "Lock",
17
- "onoff_line": 1,
18
- "door_open_status": 0,
19
- "trash_mode": 0,
20
- "locker_status": {"hardlock": 2},
21
- "raw_dict": {}
22
- })
23
- self.lock_service._get_lock_info.return_value = {
24
- "device": {
25
- "onoff_line": 1,
26
- "door_open_status": 0,
27
- "trash_mode": 0,
28
- "locker_status": {"hardlock": 2},
29
- }
30
- }
31
-
32
- updated_lock = await self.lock_service.update(mock_lock)
33
-
34
- self.assertTrue(updated_lock.available)
35
- self.assertFalse(updated_lock.door_open)
36
- self.assertFalse(updated_lock.trash_mode)
37
- self.assertTrue(updated_lock.unlocked)
38
- self.assertFalse(updated_lock.unlocking)
39
- self.assertFalse(updated_lock.locking)
40
- self.lock_service._get_lock_info.assert_awaited_once_with(mock_lock)
41
-
42
- async def test_update_lock_offline(self):
43
- mock_lock = Lock({
44
- "device_type": "Lock",
45
- "onoff_line": 0,
46
- "door_open_status": 1,
47
- "trash_mode": 1,
48
- "locker_status": {"hardlock": 1},
49
- "raw_dict": {}
50
- })
51
- self.lock_service._get_lock_info.return_value = {
52
- "device": {
53
- "onoff_line": 0,
54
- "door_open_status": 1,
55
- "trash_mode": 1,
56
- "locker_status": {"hardlock": 1},
57
- }
58
- }
59
-
60
- updated_lock = await self.lock_service.update(mock_lock)
61
-
62
- self.assertFalse(updated_lock.available)
63
- self.assertTrue(updated_lock.door_open)
64
- self.assertTrue(updated_lock.trash_mode)
65
- self.assertFalse(updated_lock.unlocked)
66
- self.assertFalse(updated_lock.unlocking)
67
- self.assertFalse(updated_lock.locking)
68
- self.lock_service._get_lock_info.assert_awaited_once_with(mock_lock)
69
-
70
- async def test_get_locks(self):
71
- mock_device = AsyncMock()
72
- mock_device.type = DeviceTypes.LOCK
73
- mock_device.raw_dict = {"device_type": "Lock"}
74
-
75
- self.lock_service.get_object_list = AsyncMock(return_value=[mock_device])
76
-
77
- locks = await self.lock_service.get_locks()
78
-
79
- self.assertEqual(len(locks), 1)
80
- self.assertIsInstance(locks[0], Lock)
81
- self.lock_service.get_object_list.assert_awaited_once()
82
-
83
- async def test_lock(self):
84
- mock_lock = Lock({
85
- "device_type": "Lock",
86
- "raw_dict": {}
87
- })
88
-
89
- await self.lock_service.lock(mock_lock)
90
- self.lock_service._lock_control.assert_awaited_with(mock_lock, "remoteLock")
91
-
92
- async def test_unlock(self):
93
- mock_lock = Lock({
94
- "device_type": "Lock",
95
- "raw_dict": {}
96
- })
97
-
98
- await self.lock_service.unlock(mock_lock)
99
- self.lock_service._lock_control.assert_awaited_with(mock_lock, "remoteUnlock")
100
-
101
- async def test_lock_control_error_handling(self):
102
- mock_lock = Lock({
103
- "device_type": "Lock",
104
- "raw_dict": {}
105
- })
106
- self.lock_service._lock_control.side_effect = UnknownApiError("Failed to lock/unlock")
107
-
108
- with self.assertRaises(UnknownApiError):
109
- await self.lock_service.lock(mock_lock)
110
-
111
- with self.assertRaises(UnknownApiError):
112
- await self.lock_service.unlock(mock_lock)
113
-
114
- # ... other test cases ...
@@ -1,159 +0,0 @@
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()