You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you do not yet have a Crownstone account, go to (My Crownstone)[my.crownstone.rocks] to set one up.
88
+
The email and password are used to re-login after an access token has expired.
89
+
```Python
90
+
cloud = CrownstoneCloud('email', 'password')
91
+
```
92
+
if already have an access token and you want to skip to first login for speed you can use:
93
+
```Python
94
+
cloud.set_access_token('myAccessToken')
95
+
```
96
+
to initialize all the cloud data into the lib use
97
+
```Python
98
+
await cloud.initialize()
99
+
```
100
+
for async usage, or use
101
+
```Python
102
+
cloud.initialize_sync()
68
103
```
104
+
for sync usage.<br>
105
+
It is only required to call initialize once at the beginning of the program.
69
106
70
107
## Data structure
71
108
@@ -83,35 +120,29 @@ The cloud can be displayed with the following structure:
83
120
The user is the to whom the data belongs.<br>
84
121
The user is the one that logs in using email and password.<br>
85
122
By getting a user specific access token after login, the data for that specific user can be requested.
86
-
```python
87
-
await cloud.login('email', 'password')
88
-
```
89
123
90
124
### Keys
91
125
92
126
The keys are user specific.<br>
93
127
They are required to connect to the crownstone bluetooth mesh.<br>
94
128
The most common used keys are the sphere keys. They are located within each individual sphere.<br>
95
-
Getting the keys is optional and not included in the general sync.<br>
96
-
The keys are returned as a dictionary.
97
-
To get the keys for a sphere:
98
-
```python
99
-
sphere = cloud.spheres.find('MySphere')
100
-
keys =await sphere.get_keys()
101
-
```
102
129
103
130
### Spheres
104
131
105
-
Spheres can be seen as a house, apartement or office. They have rooms (locations), Crownstones and users in them.<br>
106
-
Note that the spheres need to be synced **FIRST** before the other data can be synced.<br>
107
-
To get spheres for the user without any data (only name and id) use:
108
-
```python
109
-
await cloud.spheres.sync()
110
-
```
111
-
To get the spheres and all their data at once use:
112
-
```python
113
-
await cloud.sync()
114
-
```
132
+
Spheres are the main data entry. They have rooms (locations), Crownstones and users in them.<br>
133
+
Example spheres:
134
+
* House
135
+
* Office
136
+
* Apartement
137
+
138
+
A Sphere has the following fields in the cloud lib:
139
+
* crownstones: Crownstones
140
+
* locations: Locations
141
+
* users: Users
142
+
* keys: Dict (optional, default = None)
143
+
* name: String
144
+
* cloud_id: String
145
+
* unique_id: String
115
146
116
147
### Locations
117
148
@@ -122,48 +153,29 @@ For example for a house:
122
153
* Garage
123
154
* Bathroom
124
155
125
-
To get the locations for your sphere use:
126
-
```python
127
-
sphere = cloud.spheres.find('MySphere')
128
-
await sphere.locations.sync()
129
-
```
130
-
For the presence tracking, an advanced algorithm detects whenever a user is on a specific location.<br>
131
-
The presence is saved for each location in a list. The list contains names of the people who are present.<br>
132
-
To print the present people list:
133
-
```python
134
-
location = sphere.locations.find('MyLocation')
135
-
print(location.present_people)
136
-
```
156
+
A Location has the following fields in the cloud lib:
157
+
* present_people: List
158
+
* name: String
159
+
* cloud_id: String
160
+
* unique_id: String
137
161
138
162
### Crownstones
139
163
140
164
Crownstones are smart plugs that can make every device that isn't smart, way smarter!<br>
141
165
Crownstones are located within a sphere.<br>
142
-
Example Crownstones:
166
+
Example names of Crownstones:
143
167
* Lamp
144
168
* Charger
145
169
* Television
146
170
147
-
to get the crownstones for your sphere:
148
-
```python
149
-
sphere = cloud.spheres.find('MySphere')
150
-
await sphere.crownstones.sync()
151
-
```
152
-
Crownstones can also be turned on/off remotely.<br>
153
-
Since this is a command sent to your phone, it is required to have Bluetooth on and to be present in your sphere.<br>
154
-
To switch a crownstone on/off:
155
-
```python
156
-
crownstone = cloud.get_crownstone('MyCrownstone')
157
-
await crownstone.turn_on()
158
-
await crownstone.turn_off()
159
-
```
160
-
It is also possible to set the brightness(dimming) of a crownstone.<br>
161
-
For this to work, you need to enable dimming in your crownstone app for that specific crownstone. Dimming only works with lights and it is **not** recommended to use it for any other device.<br>
162
-
For the brightness use a percentage between 0% and 100%. To set the brightness:
163
-
```python
164
-
crownstone = cloud.get_crownstone('MyCrownstone')
165
-
await crownstone.set_brightness(50)
166
-
```
171
+
A Crownstone has the following fields in the cloud lib:
172
+
* state: Float (0..1)
173
+
* dimming_enabled: Bool (default = False)
174
+
* name: String
175
+
* unique_id: String
176
+
* cloud_id: String
177
+
* type: String
178
+
* sw_version: String
167
179
168
180
### Users
169
181
@@ -173,16 +185,106 @@ A user can have 3 roles:
173
185
* Member
174
186
* Guest
175
187
176
-
Each role has different privileges.<br>
177
-
Users can have similar names. To view the info of a user's first name in a sphere:
178
-
```python
179
-
sphere = cloud.spheres.find('MySphere')
180
-
users = sphere.users.find_by_first_name('MyUser')
181
-
for username in users:
182
-
print(user.role)
183
-
print(user.last_name)
184
-
print(user.email)
188
+
A User has the following fields in the cloud lib:
189
+
* role: String
190
+
* first_name: String
191
+
* last_name: String
192
+
* email: String
193
+
* cloud_id: String
194
+
* email_verified: Bool
195
+
196
+
## Function list
197
+
198
+
### Cloud
199
+
200
+
#### initialize()
201
+
> Login if no access token available, and sync all data for the user from the cloud.
202
+
203
+
#### set_access_token(access_token: String)
204
+
> Set an access token to skip the login part, if you already have one
> Return a Crownstone object if one exists by that id.
238
+
239
+
### Crownstone
240
+
241
+
#### turn_on()
242
+
> 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.
243
+
244
+
#### turn_off()
245
+
> 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.
246
+
247
+
#### set_brightness(percentage: int)
248
+
> 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.
249
+
250
+
### Locations
251
+
252
+
#### update()
253
+
> 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.
254
+
255
+
#### find(location_name: String) -> Location
256
+
> Return a location object if one exists by that name.
257
+
258
+
#### find_by_id(location_id: String) -> Location
259
+
> Return a location object if one exists by that id.
260
+
261
+
### Users
262
+
263
+
#### update()
264
+
> 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.
265
+
266
+
#### find_by_first_name(first_name: String) -> list
267
+
> Returns a list of all users with that first name, as duplicate first names can exist.
268
+
269
+
#### find_by_last_name(last_name: String) -> list
270
+
> Return a list of all users with that last name, as duplicate last names can exist.
271
+
272
+
#### find_by_id(user_id: String) -> Location
273
+
> Return a location object if one exists by that id.
274
+
275
+
## Async vs sync
276
+
The lib can be used synchonously and asynchronously.<br>
277
+
Async functions need to be awaited:
278
+
```Python
279
+
await cloud.spheres.update()
280
+
```
281
+
All the async functions mentioned above can also be used synchronously.<br>
282
+
Simply type the same function name, but with underscore sync at the end. for example:
0 commit comments