Skip to content

Commit 2b7ccab

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 1cac6b4 + 9ac44d0 commit 2b7ccab

1 file changed

Lines changed: 55 additions & 40 deletions

File tree

README.md

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Asynchronous Python library to get data from the cloud, and switch Crownstones.
1212
## Requirements
1313

1414
* Python 3.7 (only version that it's tested on currently)
15-
* Aiohttp 3.6.2
15+
* Aiohttp 3.6.1
1616

1717
## Standard installation
1818

@@ -45,26 +45,28 @@ $ python setup.py install
4545

4646
```Python
4747
from crownstone_cloud.lib.cloud import CrownstoneCloud
48+
import logging
4849
import asyncio
4950

51+
# enable logging
52+
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
53+
5054

5155
async def main():
5256
# init cloud
5357
cloud = CrownstoneCloud('email', 'password')
54-
await cloud.initialize()
58+
await cloud.async_initialize()
59+
60+
# get a crownstone by name that can dim, and put it on 50% brightness
61+
crownstone_lamp = cloud.get_crownstone('Lamp')
62+
await crownstone_lamp.async_set_brightness(0.5)
5563

56-
# get a crownstone by name and switch it on
57-
crownstone = cloud.get_crownstone('awesomeCrownstone')
58-
await crownstone.turn_on()
64+
# get a crownstone by name and turn it on
65+
crownstone_tv = cloud.get_crownstone('TV')
66+
await crownstone_tv.async_turn_on()
5967

60-
# switch all crownstones in a sphere to on:
61-
sphere = cloud.spheres.find('awesomeSphere')
62-
for crownstone in sphere.crownstones:
63-
await crownstone.turn_on()
64-
65-
# close session
66-
# required when ran as standalone program, optional if ran in integration.
67-
await cloud.close_session()
68+
# close the session after we are done
69+
await cloud.async_close_session()
6870

6971
asyncio.run(main())
7072
```
@@ -73,18 +75,20 @@ asyncio.run(main())
7375

7476
```Python
7577
from crownstone_cloud.lib.cloud import CrownstoneCloud
78+
import logging
79+
80+
# enable logging
81+
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
7682

7783
# init cloud
7884
cloud = CrownstoneCloud('email', 'password')
79-
cloud.initialize_sync()
85+
cloud.initialize()
8086

81-
# get a crownstone and turn it on
82-
crownstone = cloud.get_crownstone('awesomeCrownstone')
83-
crownstone.turn_on_sync()
87+
# get a crownstone by name and turn it on
88+
crownstone_coffee_machine = cloud.get_crownstone('Coffee machine')
89+
crownstone_coffee_machine.turn_on()
8490

85-
# close session
86-
# required when ran as standalone program, optional if ran in integration.
87-
cloud.close_session_sync()
91+
cloud.close_session()
8892
```
8993

9094
### Initialization
@@ -103,11 +107,11 @@ cloud.set_access_token('myAccessToken')
103107
```
104108
to initialize all the cloud data into the lib, for async usage use:
105109
```Python
106-
await cloud.initialize()
110+
await cloud.async_initialize()
107111
```
108112
Or for sync usage use:
109113
```Python
110-
cloud.initialize_sync()
114+
cloud.initialize()
111115
```
112116
It is only required to call initialize once at the beginning of the program.
113117

@@ -150,6 +154,7 @@ A Sphere has the following fields in the cloud lib:
150154
* name: String
151155
* cloud_id: String
152156
* unique_id: String
157+
* present_people: List
153158

154159
### Locations
155160

@@ -176,8 +181,8 @@ Example names of Crownstones:
176181
* Television
177182

178183
A Crownstone has the following fields in the cloud lib:
184+
* abilities: Dict
179185
* state: Float (0..1)
180-
* dimming_enabled: Bool (default = False)
181186
* name: String
182187
* unique_id: String
183188
* cloud_id: String
@@ -204,7 +209,7 @@ A User has the following fields in the cloud lib:
204209

205210
### Cloud
206211

207-
#### initialize()
212+
#### async_initialize()
208213
> Login if no access token available, and sync all data for the user from the cloud.
209214
210215
#### set_access_token(access_token: String)
@@ -216,10 +221,16 @@ A User has the following fields in the cloud lib:
216221
#### get_crownstone_by_id(crownstone_id: String) -> Crownstone
217222
> Get a Crownstone object by it's id, it's it exists.
218223
224+
#### async_close_session()
225+
> Async function. This will close the websession in requestHandler to cleanup nicely after the program has finished.
226+
227+
#### reset()
228+
> Reset the requestHandler parameters in case the cloud instance was cleaned up and needs to be recreated.
229+
219230
### Spheres
220231

221-
#### update()
222-
> Async function. Sync the Spheres with the cloud. Doing this will replace all current sphere data with that of the cloud.
232+
#### async_update_sphere_data()
233+
> Async function. Sync the Spheres with the cloud. Calling the function again after init will update the current data.
223234
224235
#### find(sphere_name: String) -> Sphere
225236
> Returns a sphere object if one exists by that name.
@@ -229,13 +240,13 @@ A User has the following fields in the cloud lib:
229240
230241
### Sphere
231242

232-
#### get_keys() -> Dict
243+
#### async_get_keys() -> Dict
233244
> Async function. Returns a dict with the keys of this sphere. The keys can be used for BLE connectivity with the Crownstones.
234245
235246
### Crownstones
236247

237-
#### update()
238-
> Async function. Sync the Crownstones with the cloud for a sphere. Doing this will replace all the current crownstone data with that of the cloud.
248+
#### async_update_crownstone_data()
249+
> Async function. Sync the Crownstones with the cloud for a sphere. Calling the function again after init will update the current data.
239250
240251
#### find(crownstone_name: String) -> Crownstone
241252
> Return a Crownstone object if one exists by that name.
@@ -245,19 +256,22 @@ A User has the following fields in the cloud lib:
245256
246257
### Crownstone
247258

248-
#### turn_on()
259+
#### async_turn_on()
249260
> Async function. Send a command to turn a Crownstone on. To make this work make sure to be in the selected sphere and have Bluetooth enabled on your phone.
250261
251-
#### turn_off()
262+
#### async_turn_off()
252263
> Async function. Send a command to turn a Crownstone off. To make this work make sure to be in the selected sphere and have Bluetooth enabled on your phone.
253264
254-
#### set_brightness(percentage: Int)
265+
#### async_set_brightness(value: Float)
255266
> Async function. Send a command to set a Crownstone to a given brightness level. To make this work make sure to be in the selected sphere and have Bluetooth enabled on your phone.
256267
257268
### Locations
258269

259-
#### update()
260-
> Async function. Sync the Locations en present people in that location with the cloud for a sphere. Doing this will replace all the current location data with that of the cloud.
270+
#### async_update_location_data()
271+
> Async function. Sync the Locations with the cloud for a sphere. Calling the function again after init will update the current data.
272+
273+
#### async_update_location_presence()
274+
> Async function. Sync the presence with the cloud. This will replace the current presence with the new presence.
261275
262276
#### find(location_name: String) -> Location
263277
> Return a location object if one exists by that name.
@@ -267,8 +281,8 @@ A User has the following fields in the cloud lib:
267281
268282
### Users
269283

270-
#### update()
271-
> Async function. Sync the Users with the cloud for a sphere. Doing this will replace all the current user data with that of the cloud.
284+
#### async_update_user_data()
285+
> Async function. Sync the Users with the cloud for a sphere. Calling the function again after init will update the current data.
272286
273287
#### find_by_first_name(first_name: String) -> List
274288
> Returns a list of all users with that first name, as duplicate first names can exist.
@@ -281,15 +295,16 @@ A User has the following fields in the cloud lib:
281295
282296
## Async vs sync
283297
The lib can be used synchonously and asynchronously.<br>
298+
All async functions in the library API functions in this library have the prefix **async_**
284299
Async functions need to be awaited:
285300
```Python
286-
await cloud.spheres.update()
301+
await cloud.spheres.async_update_sphere_data()
287302
```
288303
All the async functions mentioned above can also be used synchronously.<br>
289-
Simply type the same function name, but with underscore sync at the end. for example:
304+
Sync functions don't have the async prefix. for example:
290305
```Python
291-
cloud.initialize_sync()
292-
cloud.spheres.update_sync()
306+
cloud.initialize()
307+
cloud.spheres.update_sphere_data()
293308
```
294309
Make sure to see the examples above!
295310

0 commit comments

Comments
 (0)