Skip to content

Instantly share code, notes, and snippets.

@agmangas
Created January 4, 2021 16:15
Show Gist options
  • Save agmangas/94cc5c3d9d5dcb473cff774b3522bbb6 to your computer and use it in GitHub Desktop.
Save agmangas/94cc5c3d9d5dcb473cff774b3522bbb6 to your computer and use it in GitHub Desktop.
WoTemu quickstart app
import json
import logging
import pprint
import random
import time
from wotpy.wot.enums import DataType
_logger = logging.getLogger("wotemu.quickstart.thing")
_DESCRIPTION = {
"id": "urn:wotemu:quickstart:thing",
"name": "Quickstart Thing",
"properties": {
"temperature": {
"type": DataType.NUMBER,
"readOnly": True
},
"timeMillis": {
"type": DataType.INTEGER,
"readOnly": True
}
}
}
async def _time_millis():
return int(time.time() * 1e3)
async def _temperature():
return round(random.uniform(18.0, 22.0), 2)
async def app(wot, conf, loop):
_logger.info(
"Producing Thing:\n%s",
pprint.pformat(_DESCRIPTION))
exposed_thing = wot.produce(json.dumps(_DESCRIPTION))
exposed_thing.set_property_read_handler("temperature", _temperature)
exposed_thing.set_property_read_handler("timeMillis", _time_millis)
exposed_thing.expose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment