Metadata
Metadata generators are device APIs or device description languages. One can either create a Thing in code and generate metadata (code-first), or create a Thing from a metadata (API-first). The interface required to do this is defined here.
A specific metadata format is a bundle of five classes: one per core component - Property, Action, Event and a common base class for common metadata among them, and a class that puts them together.
The W3C Web of Things bundle in hololinked.metadata.td is the reference implementation, and maps
onto the five slots as:
| slot | W3C WoT class |
|---|---|
thing |
ThingModel |
property |
PropertyAffordance |
action |
ActionAffordance |
event |
EventAffordance |
interaction |
InteractionAffordance |
Have a look at their code by using the links above.
hololinked.core.interfaces.metadata.MetadataFormat
dataclass
Metadata class for each core component.
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
hololinked.core.interfaces.metadata.Metadata
Bases: BaseModel
A base class to generate device or Thing metadata and conversely produce a Thing instance from the metadata.
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
Attributes
skip_properties
instance-attribute
List of default property names to skip when generating the metadata. Different from skip_names as
this list is supposed to be used as a builtin blacklist.
skip_actions
instance-attribute
List of default action names to skip when generating the metadata. Different from skip_names as
this list is supposed to be used as a builtin blacklist.
skip_events
instance-attribute
List of default event names to skip when generating the metadata. Different from skip_names as
this list is supposed to be used as a builtin blacklist.
Functions
generate
produce
add_interactions
Add interaction(-affordances) to the metadata - properties, actions and events.
This is to be tailored for the specific standard.
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
json
Return the JSON string representation.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON string representation. |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
hololinked.core.interfaces.metadata.InteractionMetadata
Bases: BaseModel
Generate metadata for a property, action or event.
A property, action or event is called as an interaction(-affordance), and the metadata generated for it is named here as interaction metadata. This base class defines metadata methods common to all of properties, actions or events, and could be common to different metadata or device description standards. Specific standards need to extend this class.
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
Functions
what
Whether it is a property, action or event.
name
Name of the interaction that could be used as a key in the metadata.
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the metadata is not bound to any interaction object. This usually happens
when the metadata is not generated from an interaction object, but created manually or from a
different source. Use |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
objekt
Object instance of the interaction, instance of Property, Action or Event.
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the metadata is not bound to any interaction object.
Use |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
owner
Owning Thing instance or Thing class of the interaction.
Depending on how this object was created, returns either an instance or a class.
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the owner is not set, which means this interaction is not properly bound to a |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
owner_cls
Return the owning Thing class of the interaction.
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the owner is not set, which means this interaction is not properly bound to a |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
thing_cls
Thing class owning the interaction.
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the metadata is not bound to any |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
thing_id
ID of the Thing instance owning the interaction, if available, otherwise None.
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the metadata is not bound to any |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
build
Populate the fields of the metadata for the specific interaction.
build_non_compliant_metadata
If there is additional non standard metadata to be added, they can be added here.
from_descriptor
classmethod
Instantitate and build the metadata for the specific interaction.
Use the json() method to get the JSON representation of the metadata.
Note that this method is different from build() method as its supposed to be used as a classmethod
to create an instance. Although, it internally calls build(), and some additional steps can be included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Property | Action | Event
|
interaction object for which the metadata is to be built |
required |
|
Thing | ThingMeta
|
owner of the interaction |
required |
Returns:
| Type | Description |
|---|---|
PropertyMetadata | ActionMetadata | EventMetadata
|
Instance of this class with the metadata fields populated. |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
to_descriptor
Convert the metadata back to a Property, Action or Event descriptor object.
Returns:
| Type | Description |
|---|---|
Property | Action | Event
|
The corresponding descriptor object of the interaction. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented in the subclass, or if the metadata cannot be converted to any of the descriptor objects. |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
from_metadata
classmethod
Populate the metadata from the provided JSON and return it as an instance of this class.
It is assumed that the interaction is a key in the provided JSON, so one needs to supply the name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
name of the interaction used as key in the metadata |
required |
|
dict[str, Any]
|
metadata JSON dictionary (the entire one, not just the component of the interaction) |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Instance of this class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the interaction type cannot be determined from the metadata. |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
override_defaults
Override default values with provided keyword arguments, especially thing_id, owner name, object name etc.
Any logic to trigger side effects while setting those values should be handled here, either by reimplementing the method in the subclass or calling the super().override_defaults(**kwargs).
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
register_descriptor
classmethod
register_descriptor(descriptor: Property | Action | Event, metadata_generator: type[InteractionMetadata]) -> None
Register a custom metadata generator for a descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Property | Action | Event
|
The descriptor class |
required |
|
type[InteractionMetadata]
|
|
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the descriptor is not an instance of |
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
json
Return the JSON representation.
hololinked.core.interfaces.metadata.PropertyMetadata
Bases: InteractionMetadata
Generate property metadata from Property descriptor object.
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
hololinked.core.interfaces.metadata.ActionMetadata
Bases: InteractionMetadata
Generate action metadata from Action descriptor object.
Source code in repo/hololinked/hololinked/core/interfaces/metadata.py
hololinked.core.interfaces.metadata.EventMetadata
Bases: InteractionMetadata
Generate event metadata from Event descriptor object.