@@ -28,9 +28,14 @@ class NoiseThresholds(AbstractNoiseThresholds):
2828 -------
2929 list(device_id)
3030 Gets a list of noise thresholds of a noise-monitoring device
31- create(device_id, starts_daily_at, ends_daily_at, sync=None, noise_threshold_decibels=None, noise_threshold_nrs=None)
31+
32+ create(device_id, starts_daily_at, ends_daily_at, name=None noise_threshold_decibels=None, noise_threshold_nrs=None, wait_for_action_attempt=True)
3233 Creates a noise threshold on a noise-monitoring device
33- delete(noise_threshold_id, device_id, sync=None)
34+
35+ update(device_id, noise_threshold_id, name=None, starts_daily_at=None, ends_daily_at=None, noise_threshold_decibels=None, noise_threshold_nrs=None, wait_for_action_attempt=True)
36+ Updates a noise threshold on a noise-monitoring device
37+
38+ delete(noise_threshold_id, device_id, wait_for_action_attempt=True)
3439 Deletes a noise threshold on a noise-monitoring device
3540 """
3641
@@ -105,6 +110,7 @@ def create(
105110 The noise level in decibels
106111 noise_threshold_nrs: Optional[float],
107112 Noise Level in Noiseaware Noise Risk Score (NRS)
113+
108114 Raises
109115 ------
110116 Exception
@@ -168,8 +174,99 @@ def create(
168174 return NoiseThreshold .from_dict (noise_threshold )
169175
170176 @report_error
171- def update (self , noise_threshold_id ):
172- raise NotImplementedError ()
177+ def update (
178+ self ,
179+ device_id : str ,
180+ noise_threshold_id : str ,
181+ name : Optional [str ] = None ,
182+ starts_daily_at : Optional [str ] = None ,
183+ ends_daily_at : Optional [str ] = None ,
184+ noise_threshold_decibels : Optional [float ] = None ,
185+ noise_threshold_nrs : Optional [float ] = None ,
186+ wait_for_action_attempt : Optional [bool ] = True ,
187+ ) -> Union [ActionAttempt , NoiseThreshold ]:
188+ """Updates a noise threshold.
189+ Parameters
190+ ----------
191+ device_id : str
192+ Device ID of a device to update noise threshold of
193+ noise_threshold_id : str
194+ Id of a noise threshold to update
195+ name: Optional[str]
196+ Noise threshold name
197+ starts_daily_at: Optional[str],
198+ Time when noise threshold becomes active
199+ ends_daily_at: Optional[str],
200+ Time when noise threshold becomes inactive
201+ noise_threshold_decibels: Optional[float],
202+ Noise level in decibels
203+ noise_threshold_nrs: Optional[float],
204+ Noise Level in Noiseaware Noise Risk Score (NRS)
205+ wait_for_action_attempt: Optional[bool]
206+ Should wait for action attempt to resolve
207+
208+ Raises
209+ ------
210+ Exception
211+ If the API request wasn't successful.
212+
213+ Returns
214+ ------
215+ ActionAttempt or NoiseThreshold
216+ """
217+ params = {
218+ "device_id" : device_id ,
219+ "noise_threshold_id" : noise_threshold_id ,
220+ }
221+
222+ arguments = {
223+ "name" : name ,
224+ "starts_daily_at" : starts_daily_at ,
225+ "ends_daily_at" : ends_daily_at ,
226+ "noise_threshold_decibels" : noise_threshold_decibels ,
227+ "noise_threshold_nrs" : noise_threshold_nrs ,
228+ }
229+
230+ for name in arguments :
231+ if arguments [name ]:
232+ params .update ({name : arguments [name ]})
233+
234+ res = self .seam .make_request (
235+ "PUT" ,
236+ "/noise_sensors/noise_thresholds/update" ,
237+ json = params ,
238+ )
239+
240+ json_aa = res ["action_attempt" ]
241+ aa_error = None
242+ if "error" in json_aa and json_aa ["error" ] is not None :
243+ aa_error = ActionAttemptError (
244+ type = json_aa ["error" ]["type" ],
245+ message = json_aa ["error" ]["message" ],
246+ )
247+
248+ if not wait_for_action_attempt or aa_error :
249+ return ActionAttempt (
250+ action_attempt_id = json_aa ["action_attempt_id" ],
251+ status = json_aa ["status" ],
252+ action_type = json_aa ["action_type" ],
253+ result = json_aa ["result" ],
254+ error = aa_error ,
255+ )
256+
257+ updated_action_attempt = self .seam .action_attempts .poll_until_ready (
258+ json_aa ["action_attempt_id" ]
259+ )
260+
261+ action_attempt_result = getattr (updated_action_attempt , "result" , None )
262+ noise_threshold = action_attempt_result .get ("noise_threshold" , None )
263+ if not action_attempt_result or not noise_threshold :
264+ raise Exception (
265+ "Failed to create noise_threshold: no noise_threshold returned: "
266+ + json .dumps (asdict (updated_action_attempt ))
267+ )
268+
269+ return NoiseThreshold .from_dict (noise_threshold )
173270
174271 @report_error
175272 def delete (
0 commit comments