uiprotect 7.7.0__py3-none-any.whl → 7.9.0__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.

Potentially problematic release.


This version of uiprotect might be problematic. Click here for more details.

uiprotect/api.py CHANGED
@@ -390,12 +390,15 @@ class BaseApiClient:
390
390
  method: str = "get",
391
391
  require_auth: bool = True,
392
392
  raise_exception: bool = True,
393
+ api_path: str | None = None,
393
394
  **kwargs: Any,
394
395
  ) -> bytes | None:
395
- """Make a request to UniFi Protect API"""
396
+ """Make a API request"""
397
+ path = api_path if api_path is not None else self.api_path
398
+
396
399
  response = await self.request(
397
400
  method,
398
- f"{self.api_path}{url}",
401
+ f"{path}{url}",
399
402
  require_auth=require_auth,
400
403
  auto_close=False,
401
404
  **kwargs,
@@ -449,6 +452,7 @@ class BaseApiClient:
449
452
  method: str = "get",
450
453
  require_auth: bool = True,
451
454
  raise_exception: bool = True,
455
+ api_path: str | None = None,
452
456
  **kwargs: Any,
453
457
  ) -> list[Any] | dict[str, Any] | None:
454
458
  data = await self.api_request_raw(
@@ -456,6 +460,7 @@ class BaseApiClient:
456
460
  method=method,
457
461
  require_auth=require_auth,
458
462
  raise_exception=raise_exception,
463
+ api_path=api_path,
459
464
  **kwargs,
460
465
  )
461
466
 
@@ -2038,3 +2043,31 @@ class ProtectApiClient(BaseApiClient):
2038
2043
  method="post",
2039
2044
  )
2040
2045
  return PTZPreset(**preset)
2046
+
2047
+ async def create_api_key(self, name: str) -> str:
2048
+ """Create an API key with the given name and return the full API key."""
2049
+ if not name:
2050
+ raise BadRequest("API key name cannot be empty")
2051
+
2052
+ user_id = None
2053
+ if self._last_token_cookie_decode is not None:
2054
+ user_id = self._last_token_cookie_decode.get("userId")
2055
+ if not user_id:
2056
+ raise BadRequest("User ID not available for API key creation")
2057
+
2058
+ response = await self.api_request(
2059
+ api_path="/proxy/users/api/v2",
2060
+ url=f"/user/{user_id}/keys",
2061
+ method="post",
2062
+ json={"name": name},
2063
+ )
2064
+
2065
+ if (
2066
+ not isinstance(response, dict)
2067
+ or "data" not in response
2068
+ or not isinstance(response["data"], dict)
2069
+ or "full_api_key" not in response["data"]
2070
+ ):
2071
+ raise BadRequest("Failed to create API key")
2072
+
2073
+ return response["data"]["full_api_key"]
uiprotect/cli/__init__.py CHANGED
@@ -320,3 +320,21 @@ def release_versions(ctx: typer.Context) -> None:
320
320
 
321
321
  Path(RELEASE_CACHE).write_bytes(output)
322
322
  typer.echo(output.decode("utf-8"))
323
+
324
+
325
+ @app.command()
326
+ def create_api_key(
327
+ ctx: typer.Context,
328
+ name: str = typer.Argument(..., help="Name for the API key"),
329
+ ) -> None:
330
+ """Create a new API key for the current user."""
331
+ protect = cast(ProtectApiClient, ctx.obj.protect)
332
+
333
+ async def callback() -> str:
334
+ api_key = await protect.create_api_key(name)
335
+ await protect.close_session()
336
+ return api_key
337
+
338
+ _setup_logger()
339
+ result = run_async(callback())
340
+ typer.echo(result)
uiprotect/cli/base.py CHANGED
@@ -223,7 +223,6 @@ def init_common_commands(
223
223
  device_commands: dict[str, Callable[..., Any]] = {}
224
224
 
225
225
  deviceless_commands["list-ids"] = app.command()(list_ids)
226
- device_commands["protect-url"] = app.command()(protect_url)
227
226
  device_commands["is-wired"] = app.command()(is_wired)
228
227
  device_commands["is-wifi"] = app.command()(is_wifi)
229
228
  device_commands["is-bluetooth"] = app.command()(is_bluetooth)
uiprotect/cli/lights.py CHANGED
@@ -117,3 +117,12 @@ def set_duration(
117
117
  obj: Light = ctx.obj.device
118
118
 
119
119
  base.run(ctx, obj.set_duration(timedelta(seconds=duration)))
120
+
121
+
122
+ @app.command()
123
+ def set_flood_light(ctx: typer.Context, enabled: bool) -> None:
124
+ """Sets flood light (force on) for light device."""
125
+ base.require_device_id(ctx)
126
+ obj: Light = ctx.obj.device
127
+
128
+ base.run(ctx, obj.set_flood_light(enabled))
uiprotect/data/devices.py CHANGED
@@ -160,6 +160,14 @@ class Light(ProtectMotionDeviceModel):
160
160
  self.camera_id = camera.id
161
161
  await self.save_device(data_before_changes, force_emit=True)
162
162
 
163
+ async def set_flood_light(self, enabled: bool) -> None:
164
+ """Sets the flood light (force on) for the light"""
165
+
166
+ def callback() -> None:
167
+ self.light_on_settings.is_led_force_on = enabled
168
+
169
+ await self.queue_update(callback)
170
+
163
171
  async def set_status_light(self, enabled: bool) -> None:
164
172
  """Sets the status indicator light for the light"""
165
173
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: uiprotect
3
- Version: 7.7.0
3
+ Version: 7.9.0
4
4
  Summary: Python API for Unifi Protect (Unofficial)
5
5
  License: MIT
6
6
  Author: UI Protect Maintainers
@@ -1,16 +1,16 @@
1
1
  uiprotect/__init__.py,sha256=Oz6i1tonIz4QWVnEPkbielJDJ3WQdwZVgYtjY4IwGAQ,636
2
2
  uiprotect/__main__.py,sha256=C_bHCOkv5qj6WMy-6ELoY3Y6HDhLxOa1a30CzmbZhsg,462
3
3
  uiprotect/_compat.py,sha256=HThmb1zQZCEssCxYYbQzFhJq8zYYlVaSnIEZabKc-6U,302
4
- uiprotect/api.py,sha256=hP6jeAh6K21KFAH6YiFLDlajEyb7UTdCM8vJzhGr_Z8,70477
5
- uiprotect/cli/__init__.py,sha256=gHo9G2WusvrWgnHhecT8Q2NLRXG0VS-rc9TKy4V5Kw8,8951
4
+ uiprotect/api.py,sha256=1rNElQNITuhXeRAOxLXBS0vIcASvYTxuQOY0FuGwGU8,71606
5
+ uiprotect/cli/__init__.py,sha256=B70Zdwq4cdw3wyu39uY0lMkjk5EoWLRIfVncuTOZ4AE,9423
6
6
  uiprotect/cli/aiports.py,sha256=wpEr2w_hY18CGpFiQM2Yc0FiVwG_1l2CzZhZLGNigvI,1576
7
7
  uiprotect/cli/backup.py,sha256=ZiS7RZnJGKI8TJKLW2cOUzkRM8nyTvE5Ov_jZZGtvSM,36708
8
- uiprotect/cli/base.py,sha256=GVHQMrI3thQ-4ixJlunTCfEMF90xCnt-bvRPMDupDss,7588
8
+ uiprotect/cli/base.py,sha256=5-z-IS8g9iQqhR_YbjxaJAFiMMAY_7cCtNAtvLdRCoM,7524
9
9
  uiprotect/cli/cameras.py,sha256=YvvMccQEYG3Wih0Ix8tan1R1vfaJ6cogg6YKWLzMUV8,16973
10
10
  uiprotect/cli/chimes.py,sha256=XANn21bQVkestkKOm9HjxSM8ZGrRrqvUXLouaQ3LTqs,5326
11
11
  uiprotect/cli/doorlocks.py,sha256=Go_Tn68bAcmrRAnUIi4kBiR7ciKQsu_R150ubPTjUAs,3523
12
12
  uiprotect/cli/events.py,sha256=D5SRejKzsPpKlZ9O2J4wkJRigFRVEymiLyU8VQ43fqI,7186
13
- uiprotect/cli/lights.py,sha256=RxP1ebYEn2o5812OfrovmJLaNuIDoSNWiX1FvCbcdDw,3314
13
+ uiprotect/cli/lights.py,sha256=Eoc6H6fyguxqi5P1x3CjLUmhkyi-zYdBj-mxmTVJJyY,3564
14
14
  uiprotect/cli/liveviews.py,sha256=GU5z-ZLRBXHyspDKiJpiv-kbaBcvxK_-K70rPoqx2Ms,1863
15
15
  uiprotect/cli/nvr.py,sha256=TwxEg2XT8jXAbOqv6gc7KFXELKadeItEDYweSL4_-e8,4260
16
16
  uiprotect/cli/sensors.py,sha256=fQtcDJCVxs4VbAqcavgBy2ABiVxAW3GXtna6_XFBp2k,8153
@@ -19,7 +19,7 @@ uiprotect/data/__init__.py,sha256=audwJBjxRiYdNPeYlP6iofFIOq3gyQzh6VpDsOCM2dQ,29
19
19
  uiprotect/data/base.py,sha256=CXIxaJCJNpavadn6uF7vlhI4wxkfD8MNBGgR-smRA7k,35401
20
20
  uiprotect/data/bootstrap.py,sha256=ddNaKrTprN7Zq0ZE3O_F5whepUh6z9GqyrUWxLyZ0HE,23570
21
21
  uiprotect/data/convert.py,sha256=xEN878_hm0HZZCVYGwJSxcSp2as9zpkvsemVIibReOA,2628
22
- uiprotect/data/devices.py,sha256=hGiyglHcsmMa0-9vrO8Usmf4WBtrR1GFo6pvaHoh3BA,115581
22
+ uiprotect/data/devices.py,sha256=akNyLQKCNI8SiA7oUW1cSvE-IZ9Oav8iv9PfESpjits,115839
23
23
  uiprotect/data/nvr.py,sha256=CPmqp3wQouTAGQxUDFghCHsYVWEFSrga1Hf2_HmHDgA,47707
24
24
  uiprotect/data/types.py,sha256=TDZwSKELUN0smXLB8uQkyNsHlB61j2ByijeblEt2Css,19220
25
25
  uiprotect/data/user.py,sha256=Del5LUmt5uCfAQMI9-kl_GaKm085oTLjxmcCrlEKXxc,10526
@@ -32,8 +32,8 @@ uiprotect/test_util/__init__.py,sha256=HlQBgIgdtrvT-gQ5OWP92LbgVr_YzsD5NFImLRonU
32
32
  uiprotect/test_util/anonymize.py,sha256=f-8ijU-_y9r-uAbhIPn0f0I6hzJpAkvJzc8UpWihObI,8478
33
33
  uiprotect/utils.py,sha256=5Z30chqnQhQdtD1vabRtZXjBpeiJagL5KDuALQlWxk8,20559
34
34
  uiprotect/websocket.py,sha256=tEyenqblNXHcjWYuf4oRP1E7buNwx6zoECMwpBr-jig,8191
35
- uiprotect-7.7.0.dist-info/LICENSE,sha256=INx18jhdbVXMEiiBANeKEbrbz57ckgzxk5uutmmcxGk,1111
36
- uiprotect-7.7.0.dist-info/METADATA,sha256=IyYYadmmc57eAitIgqA3mr6KoJ7FeJYL_nVXe8hXBrM,11108
37
- uiprotect-7.7.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
38
- uiprotect-7.7.0.dist-info/entry_points.txt,sha256=J78AUTPrTTxgI3s7SVgrmGqDP7piX2wuuEORzhDdVRA,47
39
- uiprotect-7.7.0.dist-info/RECORD,,
35
+ uiprotect-7.9.0.dist-info/LICENSE,sha256=INx18jhdbVXMEiiBANeKEbrbz57ckgzxk5uutmmcxGk,1111
36
+ uiprotect-7.9.0.dist-info/METADATA,sha256=ne29AflkRuWI3sEicYeWB7xt9IUGLE4MYCoT97g3C4c,11108
37
+ uiprotect-7.9.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
38
+ uiprotect-7.9.0.dist-info/entry_points.txt,sha256=J78AUTPrTTxgI3s7SVgrmGqDP7piX2wuuEORzhDdVRA,47
39
+ uiprotect-7.9.0.dist-info/RECORD,,