@@ -70,13 +70,14 @@ import asyncio
7070
7171from aiohttp import ClientSession
7272
73- from simplipy import get_systems
73+ from simplipy import API
7474
7575
7676async def main () -> None :
7777 """ Create the aiohttp session and run."""
7878 async with ClientSession() as websession:
79- systems = await get_systems(" <EMAIL>" , " <PASSWORD>" , websession)
79+ simplisafe = API .login_via_credentials(" <EMAIL>" , " <PASSWORD>" , websession)
80+ systems = await simplisafe.get_systems()
8081 # >>> [<simplipy.system.SystemV2 object at 0x10661e3c8>, ...]
8182
8283
@@ -97,19 +98,20 @@ these objects, meaning the same properties and methods are available to both.
9798### Properties and Methods
9899
99100``` python
100- from simplipy import get_systems
101+ from simplipy import API
101102
102103
103104async def main () -> None :
104105 """ Create the aiohttp session and run."""
105106 async with ClientSession() as websession:
106- systems = await get_systems(" <EMAIL>" , " <PASSWORD>" , websession)
107+ simplisafe = API .login_via_credentials(" <EMAIL>" , " <PASSWORD>" , websession)
108+ systems = await simplisafe.get_systems()
107109 # >>> [<simplipy.system.SystemV2 object at 0x10661e3c8>]
108110
109111 for system in systems:
110- # Return a reference to a SimpliSafe™ account object (detailed later):
111- system.account
112- # >>> <simplipy.account.SimpliSafe™ object at 0x12aba2321>
112+ # Return a reference to a SimpliSafe™ API object (detailed later):
113+ system.api
114+ # >>> <simplipy.api.API object at 0x12aba2321>
113115
114116 # Return whether the alarm is currently going off:
115117 system.alarm_going_off
@@ -191,13 +193,14 @@ differences are outlined below.
191193### Base Properties
192194
193195``` python
194- from simplipy import get_systems
196+ from simplipy import API
195197
196198
197199async def main () -> None :
198200 """ Create the aiohttp session and run."""
199201 async with ClientSession() as websession:
200- systems = await get_systems(" <EMAIL>" , " <PASSWORD>" , websession)
202+ simplisafe = API .login_via_credentials(" <EMAIL>" , " <PASSWORD>" , websession)
203+ systems = await simplisafe.get_systems()
201204 for system in systems:
202205 for serial, sensor_attrs in system.sensors.items():
203206 # Return the sensor's name:
@@ -234,13 +237,14 @@ asyncio.get_event_loop().run_until_complete(main())
234237### V2 Properties
235238
236239``` python
237- from simplipy import get_systems
240+ from simplipy import API
238241
239242
240243async def main () -> None :
241244 """ Create the aiohttp session and run."""
242245 async with ClientSession() as websession:
243- systems = await get_systems(" <EMAIL>" , " <PASSWORD>" , websession)
246+ simplisafe = API .login_via_credentials(" <EMAIL>" , " <PASSWORD>" , websession)
247+ systems = await simplisafe.get_systems()
244248 for system in systems:
245249 for serial, sensor_attrs in system.sensors.items():
246250 # Return the sensor's data as a currently non-understood integer:
@@ -258,13 +262,14 @@ asyncio.get_event_loop().run_until_complete(main())
258262### V3 Properties
259263
260264``` python
261- from simplipy import get_systems
265+ from simplipy import API
262266
263267
264268async def main () -> None :
265269 """ Create the aiohttp session and run."""
266270 async with ClientSession() as websession:
267- systems = await get_systems(" <EMAIL>" , " <PASSWORD>" , websession)
271+ simplisafe = API .login_via_credentials(" <EMAIL>" , " <PASSWORD>" , websession)
272+ systems = await simplisafe.get_systems()
268273 for system in systems:
269274 for sensor in system.sensors:
270275 # Return whether the sensor is offline:
@@ -283,37 +288,37 @@ async def main() -> None:
283288asyncio.get_event_loop().run_until_complete(main())
284289```
285290
286- ## The ` Account ` Object
291+ ## The ` API ` Object
287292
288- Each ` System ` object has a reference to an ` Account ` object. This object
289- contains properties and a method useful for authentication and ongoing
290- access.
293+ Each ` System ` object has a reference to an ` API ` object. This object contains
294+ properties and a method useful for authentication and ongoing access.
291295
292- ** VERY IMPORTANT NOTE:** the ` Account ` object contains references to
296+ ** VERY IMPORTANT NOTE:** the ` API ` object contains references to
293297SimpliSafe™ access and refresh tokens. ** It is vitally important that you do
294298not let these tokens leave your control.** If exposed, savvy attackers could
295299use them to view and alter your system's state. ** You have been warned; proper
296300usage of these properties is solely your responsibility.**
297301
298302``` python
299- from simplipy import get_systems
303+ from simplipy import API
300304
301305
302306async def main () -> None :
303307 """ Create the aiohttp session and run."""
304308 async with ClientSession() as websession:
305- systems = await get_systems(" <EMAIL>" , " <PASSWORD>" , websession)
309+ simplisafe = API .login_via_credentials(" <EMAIL>" , " <PASSWORD>" , websession)
310+ systems = await simplisafe.get_systems()
306311 for system in systems:
307312 # Return the current access token:
308- system.account.access_token
313+ system.api._access_token
309314 # >>> 7s9yasdh9aeu21211add
310315
311316 # Return the current refresh token:
312- system.account .refresh_token
317+ system.api .refresh_token
313318 # >>> 896sad86gudas87d6asd
314319
315320 # Return the SimpliSafe™ user ID associated with this account:
316- system.account .user_id
321+ system.api .user_id
317322 # >>> 1234567
318323
319324
@@ -328,40 +333,34 @@ asyncio.get_event_loop().run_until_complete(main())
328333 errors inherit from
329334* ` simplipy.errors.RequestError ` : an error related to HTTP requests that return
330335 something other than a ` 200 ` response code
331- * ` simplipy.errors.TokenExpiredError ` : an error related to an expired access
332- token
333336
334337# Refreshing the Access Token
335338
336- When ` simplipy.get_systems() ` is run, everything is set to make repeated
337- authorized requests against the SimpliSafe™ cloud. At some point, however, the
338- access token will expire and any future requests will raise
339- ` simplipy.errors.TokenExpiredError ` .
340-
341- When this occurs, a new access token can easily be generated:
339+ It may be desirable to re-authenticate to the SimpliSafe™ API without using
340+ a user's email and password again. In that case, it is recommended that you
341+ save the ` refresh_token ` property somewhere; when it comes time to
342+ re-authenticate, simply:
342343
343344``` python
344- await system.account.refresh_access_token()
345- ```
345+ from simplipy import API
346346
347- This will use the "on-file" refresh token to request a new access token; once
348- the call is complete, you're good to go.
349347
350- In some instances, it may be desirable to store the "on-file" refresh token for
351- later use (for example, if your app/script/etc. stops and needs to restart at
352- some indeterminate point in the future). In that case, the
353- ` refresh_access_token() ` method can take an optional ` refresh_token ` parameter:
348+ async def main () -> None :
349+ """ Create the aiohttp session and run."""
350+ async with ClientSession() as websession:
351+ simplisafe = API .login_via_token(" <REFRESH TOKEN>" , websession)
352+ systems = await simplisafe.get_systems()
353+
354354
355- ``` python
356- await system.account.refresh_access_token(refresh_token = ' abcdefg987665' )
355+ asyncio.get_event_loop().run_until_complete(main())
357356```
358357
359358Although no official documentation exists, basic testing appears to confirm the
360359hypothesis that the refresh token is both long-lived and single-use. This means
361360that theoretically, it should be possible to use it to create an access token
362361long into the future. If ` refresh_access_token() ` should throw an error,
363362however, the system object(s) will need to be recreated via
364- ` simplipy.get_systems ` .
363+ ` simplipy.API.login_via_credentials ` .
365364
366365# Contributing
367366
0 commit comments