Created
January 4, 2021 16:15
-
-
Save agmangas/94cc5c3d9d5dcb473cff774b3522bbb6 to your computer and use it in GitHub Desktop.
WoTemu quickstart app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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