1
1
from seamapi .types import (
2
+ AccessCode ,
3
+ ConnectedAccount ,
4
+ Device ,
2
5
Event ,
3
6
AbstractEvents ,
4
7
AbstractSeam as Seam ,
5
8
)
6
- from typing import List , Optional
9
+ from typing import List , Optional , Union
7
10
import requests
11
+ from seamapi .utils .convert_to_id import (
12
+ to_access_code_id ,
13
+ to_connected_account_id ,
14
+ to_device_id ,
15
+ to_event_id ,
16
+ )
8
17
9
18
from seamapi .utils .report_error import report_error
10
19
@@ -22,8 +31,11 @@ class Events(AbstractEvents):
22
31
23
32
Methods
24
33
-------
25
- list(since, device_id=None, device_ids=None, event_type=None, event_types=None)
34
+ list(since=None, between=None, device_id=None, device_ids=None, access_code_id=None, access_code_ids=None, event_type=None, event_types=None, connected_account_id =None)
26
35
Gets a list of events
36
+
37
+ get(device_id=None, event_id=None, event_type=None)
38
+ Gets an event
27
39
"""
28
40
29
41
seam : Seam
@@ -33,33 +45,45 @@ def __init__(self, seam: Seam):
33
45
Parameters
34
46
----------
35
47
seam : Seam
36
- Intial seam class
48
+ Initial seam class
37
49
"""
38
50
self .seam = seam
39
51
40
52
@report_error
41
53
def list (
42
54
self ,
43
- since : str ,
44
- device_id : Optional [str ] = None ,
55
+ since : Optional [str ] = None ,
56
+ between : Optional [list ] = None ,
57
+ device_id : Union [str , Device ] = None ,
45
58
device_ids : Optional [list ] = None ,
59
+ access_code_id : Union [str , AccessCode ] = None ,
60
+ access_code_ids : Optional [list ] = None ,
46
61
event_type : Optional [str ] = None ,
47
62
event_types : Optional [list ] = None ,
63
+ connected_account_id : Union [str , ConnectedAccount ] = None ,
48
64
) -> List [Event ]:
49
65
"""Gets a list of events.
50
66
51
67
Parameters
52
68
----------
53
- since : str
69
+ since : Optional[ str]
54
70
ISO 8601 timestamp of the earliest event to return
55
- device_id : Optional[str]
56
- Device ID to filter events by
71
+ between : Optional[list]
72
+ List of two ISO 8601 timestamps to specify a date range for filtering events
73
+ device_id : Union[str, Device]
74
+ Device ID or Device to filter events by
57
75
device_ids : Optional[list]
58
76
Device IDs to filter events by
77
+ access_code_id : Union[str, AccessCode]
78
+ Access Code ID or AccessCode to filter events by
79
+ access_code_ids : Optional[list]
80
+ Access Code IDs to filter events by
59
81
event_type : Optional[str]
60
82
Event type to filter events by
61
83
event_types : Optional[list]
62
84
Event types to filter events by
85
+ connected_account_id : Union[str, ConnectedAccount]
86
+ Connected Account ID or ConnectedAccount to filter events by
63
87
64
88
Raises
65
89
------
@@ -70,18 +94,27 @@ def list(
70
94
------
71
95
A list of events.
72
96
"""
73
- if not since :
74
- raise Exception ("'since' is required" )
75
-
76
- params = {
77
- "since" : since ,
78
- }
97
+ device_id = to_device_id (device_id ) if device_id else None
98
+ access_code_id = (
99
+ to_access_code_id (access_code_id ) if access_code_id else None
100
+ )
101
+ connected_account_id = (
102
+ to_connected_account_id (connected_account_id )
103
+ if connected_account_id
104
+ else None
105
+ )
79
106
107
+ params = {}
80
108
arguments = {
109
+ "since" : since ,
110
+ "between" : between ,
81
111
"device_id" : device_id ,
82
112
"device_ids" : device_ids ,
113
+ "access_code_id" : access_code_id ,
114
+ "access_code_ids" : access_code_ids ,
83
115
"event_type" : event_type ,
84
116
"event_types" : event_types ,
117
+ "connected_account_id" : connected_account_id ,
85
118
}
86
119
87
120
for name in arguments :
@@ -99,20 +132,20 @@ def list(
99
132
@report_error
100
133
def get (
101
134
self ,
102
- event_id : Optional [str ] = None ,
135
+ event_id : Union [str , Event ] = None ,
103
136
event_type : Optional [str ] = None ,
104
- device_id : Optional [str ] = None ,
137
+ device_id : Union [str , Device ] = None ,
105
138
) -> Event :
106
139
"""Get an Event.
107
140
108
141
Parameters
109
142
----------
110
- event_id : Optional [str]
111
- Event ID to filter events by
143
+ event_id : Union [str, Event ]
144
+ Event ID or Event to filter events by
112
145
event_type : Optional[str]
113
146
Event type to filter events by
114
- device_id : Optional [str]
115
- Device ID to filter events by
147
+ device_id : Union [str, Device ]
148
+ Device ID or Device to filter events by
116
149
117
150
Raises
118
151
------
@@ -123,8 +156,10 @@ def get(
123
156
------
124
157
An event or None.
125
158
"""
126
- params = {}
159
+ device_id = to_device_id (device_id ) if device_id else None
160
+ event_id = to_event_id (event_id ) if event_id else None
127
161
162
+ params = {}
128
163
arguments = {
129
164
"event_id" : event_id ,
130
165
"event_type" : event_type ,
0 commit comments