hidaris / thingtalk

WebThings framework.
Mozilla Public License 2.0
21 stars 4 forks source link

Refactor: new api #13

Open hidaris opened 2 years ago

hidaris commented 2 years ago
  1. Thing => ExposedThing
  2. add CosumedThing
  3. add Servient to support ExposedThing and CosumedThing
  4. move thing container to Sevient

example:

servient = Servient()
servient.addServer(
    HttpServer({
        port: 8081
    })
)

wot = await servient.start()

thing = wot.produce({
        "@context": "https://www.w3.org/2019/wot/td/v1",
        title: "MyCounter",
        properties: {
            count: {
                type: "integer",
            },
        },
    })

logger.info("Produced " + thing.getThingDescription().title)
thing.writeProperty("count", 0)

await thing.expose()

logger.info(thing.getThingDescription().title + " ready")
logger.info("TD : " + json.dumps(thing.getThingDescription()))

c = thing.readProperty("count")
logger.info("cound is " + c)