-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevices.py
More file actions
57 lines (41 loc) · 1.65 KB
/
Copy pathdevices.py
File metadata and controls
57 lines (41 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from m2x.v2.resource import Resource
from m2x.v2.streams import Stream
from m2x.v2.triggers import Trigger
from m2x.v2.keys import Key
class Device(Resource):
COLLECTION_PATH = 'devices'
ITEM_PATH = 'devices/{id}'
ITEMS_KEY = 'devices'
def streams(self):
return Stream.list(self.api, self)
def stream(self, name):
return Stream.get(self.api, self, name)
def create_stream(self, name, **params):
return Stream.create(self.api, self, name, **params)
def update_stream(self, name, **params):
return Stream.item_update(self.api, self, name, **params)
def keys(self):
return Key.list(self.api, device=self.id)
def create_key(self, **params):
return Key.create(self.api, device=self.id, **params)
def location(self, **location):
return self.data.get('location') or \
self.api.get(self.subpath('/location')) or {}
def update_location(self, **params):
return self.api.put(self.subpath('/location'), data=params)
def log(self):
return self.api.get(self.subpath('/log'))
def triggers(self, **params):
return Trigger.list(self.api, self, **params)
def create_trigger(self, **params):
return Trigger.create(self.api, self, **params)
def post_updates(self, **values):
return self.api.post(self.subpath('/updates'), data=values)
@classmethod
def by_tags(cls, api):
response = api.get('devices/tags') or {}
return response.get('tags') or []
@classmethod
def catalog(cls, api, **params):
response = api.get('devices/catalog', **params)
return cls.itemize(api, response)