| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,12 @@ | |||
| 1 | 1 | # webthing Changelog | |
| 2 | 2 | ||
| 3 | 3 | ## [Unreleased] | |
| 4 | - ### Added | ||
| 5 | - - Ability to set a base URL path on server. | ||
| 6 | 4 | ### Changed | |
| 7 | 5 | - Things now use `title` rather than `name`. | |
| 6 | + - Things now require a unique ID in the form of a URI. | ||
| 7 | + ### Added | ||
| 8 | + - Ability to set a base URL path on server. | ||
| 9 | + - Support for `id`, `base`, `security`, and `securityDefinitions` keys in thing description. | ||
| 8 | 10 | ||
| 9 | 11 | ## [0.11.3] - 2019-04-10 | |
| 10 | 12 | ### Changed | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,7 +54,12 @@ First we create a new Thing: | |||
| 54 | 54 | ||
| 55 | 55 | .. code:: python | |
| 56 | 56 | ||
| 57 | - light = Thing('My Lamp', ['OnOffSwitch', 'Light'], 'A web connected lamp') | ||
| 57 | + light = Thing( | ||
| 58 | + 'urn:dev:ops:my-lamp-1234', | ||
| 59 | + 'My Lamp', | ||
| 60 | + ['OnOffSwitch', 'Light'], | ||
| 61 | + 'A web connected lamp' | ||
| 62 | + ) | ||
| 58 | 63 | ||
| 59 | 64 | Now we can add the required properties. | |
| 60 | 65 | ||
@@ -122,9 +127,12 @@ First we create a new Thing: | |||
| 122 | 127 | ||
| 123 | 128 | .. code:: python | |
| 124 | 129 | ||
| 125 | - sensor = Thing('My Humidity Sensor', | ||
| 126 | - ['MultiLevelSensor'], | ||
| 127 | - 'A web connected humidity sensor') | ||
| 130 | + sensor = Thing( | ||
| 131 | + 'urn:dev:ops:my-humidity-sensor-1234', | ||
| 132 | + 'My Humidity Sensor', | ||
| 133 | + ['MultiLevelSensor'], | ||
| 134 | + 'A web connected humidity sensor' | ||
| 135 | + ) | ||
| 128 | 136 | ||
| 129 | 137 | Then we create and add the appropriate property: | |
| 130 | 138 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,10 +29,13 @@ class ExampleDimmableLight(Thing): | |||
| 29 | 29 | """A dimmable light that logs received commands to stdout.""" | |
| 30 | 30 | ||
| 31 | 31 | def __init__(self): | |
| 32 | - Thing.__init__(self, | ||
| 33 | - 'My Lamp', | ||
| 34 | - ['OnOffSwitch', 'Light'], | ||
| 35 | - 'A web connected lamp') | ||
| 32 | + Thing.__init__( | ||
| 33 | + self, | ||
| 34 | + 'urn:dev:ops:my-lamp-1234', | ||
| 35 | + 'My Lamp', | ||
| 36 | + ['OnOffSwitch', 'Light'], | ||
| 37 | + 'A web connected lamp' | ||
| 38 | + ) | ||
| 36 | 39 | ||
| 37 | 40 | self.add_property( | |
| 38 | 41 | Property(self, | |
@@ -101,10 +104,13 @@ class FakeGpioHumiditySensor(Thing): | |||
| 101 | 104 | """A humidity sensor which updates its measurement every few seconds.""" | |
| 102 | 105 | ||
| 103 | 106 | def __init__(self): | |
| 104 | - Thing.__init__(self, | ||
| 105 | - 'My Humidity Sensor', | ||
| 106 | - ['MultiLevelSensor'], | ||
| 107 | - 'A web connected humidity sensor') | ||
| 107 | + Thing.__init__( | ||
| 108 | + self, | ||
| 109 | + 'urn:dev:ops:my-humidity-sensor-1234', | ||
| 110 | + 'My Humidity Sensor', | ||
| 111 | + ['MultiLevelSensor'], | ||
| 112 | + 'A web connected humidity sensor' | ||
| 113 | + ) | ||
| 108 | 114 | ||
| 109 | 115 | self.level = Value(0.0) | |
| 110 | 116 | self.add_property( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,12 @@ def perform_action(self): | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | def make_thing(): | |
| 27 | - thing = Thing('My Lamp', ['OnOffSwitch', 'Light'], 'A web connected lamp') | ||
| 27 | + thing = Thing( | ||
| 28 | + 'urn:dev:ops:my-lamp-1234', | ||
| 29 | + 'My Lamp', | ||
| 30 | + ['OnOffSwitch', 'Light'], | ||
| 31 | + 'A web connected lamp' | ||
| 32 | + ) | ||
| 28 | 33 | ||
| 29 | 34 | thing.add_property( | |
| 30 | 35 | Property(thing, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,6 +144,17 @@ def get(self): | |||
| 144 | 144 | 'rel': 'alternate', | |
| 145 | 145 | 'href': '{}{}'.format(ws_href, thing.get_href()), | |
| 146 | 146 | }) | |
| 147 | + description['base'] = '{}://{}{}'.format( | ||
| 148 | + self.request.protocol, | ||
| 149 | + self.request.headers.get('Host', ''), | ||
| 150 | + thing.get_href() | ||
| 151 | + ) | ||
| 152 | + description['securityDefinitions'] = { | ||
| 153 | + 'nosec_sc': { | ||
| 154 | + 'scheme': 'nosec', | ||
| 155 | + }, | ||
| 156 | + } | ||
| 157 | + description['security'] = 'nosec_sc' | ||
| 147 | 158 | descriptions.append(description) | |
| 148 | 159 | ||
| 149 | 160 | self.write(json.dumps(descriptions)) | |
@@ -216,6 +227,17 @@ def get(self, thing_id='0'): | |||
| 216 | 227 | 'rel': 'alternate', | |
| 217 | 228 | 'href': '{}{}'.format(ws_href, self.thing.get_href()), | |
| 218 | 229 | }) | |
| 230 | + description['base'] = '{}://{}{}'.format( | ||
| 231 | + self.request.protocol, | ||
| 232 | + self.request.headers.get('Host', ''), | ||
| 233 | + self.thing.get_href() | ||
| 234 | + ) | ||
| 235 | + description['securityDefinitions'] = { | ||
| 236 | + 'nosec_sc': { | ||
| 237 | + 'scheme': 'nosec', | ||
| 238 | + }, | ||
| 239 | + } | ||
| 240 | + description['security'] = 'nosec_sc' | ||
| 219 | 241 | ||
| 220 | 242 | self.write(json.dumps(description)) | |
| 221 | 243 | self.finish() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,17 +9,19 @@ | |||
| 9 | 9 | class Thing: | |
| 10 | 10 | """A Web Thing.""" | |
| 11 | 11 | ||
| 12 | - def __init__(self, title, type_=[], description=''): | ||
| 12 | + def __init__(self, id_, title, type_=[], description=''): | ||
| 13 | 13 | """ | |
| 14 | 14 | Initialize the object. | |
| 15 | 15 | ||
| 16 | + id_ -- the thing's unique ID - must be a URI | ||
| 16 | 17 | title -- the thing's title | |
| 17 | 18 | type_ -- the thing's type(s) | |
| 18 | 19 | description -- description of the thing | |
| 19 | 20 | """ | |
| 20 | 21 | if not isinstance(type_, list): | |
| 21 | 22 | type_ = [type_] | |
| 22 | 23 | ||
| 24 | + self.id = id_ | ||
| 23 | 25 | self.context = 'https://iot.mozilla.org/schemas' | |
| 24 | 26 | self.type = type_ | |
| 25 | 27 | self.title = title | |
@@ -40,8 +42,8 @@ def as_thing_description(self): | |||
| 40 | 42 | Returns the state as a dictionary. | |
| 41 | 43 | """ | |
| 42 | 44 | thing = { | |
| 45 | + 'id': self.id, | ||
| 43 | 46 | 'title': self.title, | |
| 44 | - 'href': self.href_prefix if self.href_prefix else '/', | ||
| 45 | 47 | '@context': self.context, | |
| 46 | 48 | '@type': self.type, | |
| 47 | 49 | 'properties': self.get_property_descriptions(), | |
@@ -127,6 +129,14 @@ def set_ui_href(self, href): | |||
| 127 | 129 | """ | |
| 128 | 130 | self.ui_href = href | |
| 129 | 131 | ||
| 132 | + def get_id(self): | ||
| 133 | + """ | ||
| 134 | + Get the ID of the thing. | ||
| 135 | + | ||
| 136 | + Returns the ID as a string. | ||
| 137 | + """ | ||
| 138 | + return self.id | ||
| 139 | + | ||
| 130 | 140 | def get_title(self): | |
| 131 | 141 | """ | |
| 132 | 142 | Get the title of the thing. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments