@cutos/device-hello
v4.0.2
Published
CUTOS 4.0 Hello Device Capability SDK.
Readme
@cutos/device-hello
Hello Device Capability SDK for CUTOS 4.0 LWA applications.
This package is the consumer-side SDK for the hello Device Capability:
deviceType: hello
capabilityId: capability.device.hello
SDK version: 4.0.2
Contract: 0.1.0The SDK communicates with a compatible CUTOS Runtime Provider such as device-hello-provider.
Install
npm install @cutos/core @cutos/device-helloQuick start
import { CoreAPI } from "@cutos/core"
import { DeviceCapabilityHello } from "@cutos/device-hello"
await CoreAPI.init("localhost")
const device = new DeviceCapabilityHello()
await device.init()
await device.connect()
const info = await device.readDeviceInfo()
const result = await device.echo({ message: "Hello, CUTOS!" })
console.log(info)
console.log(result)Standard Device API
DeviceCapabilityHello extends DeviceCapabilityBase and inherits:
await device.init()
await device.connect()
await device.disconnect()
await device.readDeviceInfo()It also inherits the standard Device event subscriptions:
const offData = device.onData(data => console.log("data", data))
const offStatus = device.onStatus(status => console.log("status", status))
const offError = device.onError(error => console.error("error", error))
// Remove subscriptions when the LWA no longer needs them.
offData()
offStatus()
offError()Hello extensions
echo
Send a message through the Provider and receive a Promise result:
const result = await device.echo({ message: "Hello, CUTOS!" })
// {
// message: "Hello, CUTOS!",
// timeStamp: 1710000000000
// }simulateData
Ask the example Provider to emit one normal Device data event:
device.onData(data => console.log(data))
await device.simulateData()simulateStatus
Ask the example Provider to emit a temporary running status and return to online:
device.onStatus(status => console.log(status))
await device.simulateStatus()simulateError
Ask the example Provider to emit one asynchronous system error:
device.onError(error => console.error(error))
await device.simulateError()The three simulate*() methods are demonstration extensions. Production Device Capability SDKs replace them with hardware-specific operations.
Cleanup
await device.disconnect()
device.dispose()Versioning
The SDK, Capability Contract, and Provider have independent lifecycles:
- SDK npm package:
@cutos/device-hello 4.0.2 - Capability Contract:
0.1.0 - Example Provider:
device-hello-provider 0.1.3
An SDK release may improve packaging, types, or documentation without changing the Capability Contract. A Provider can also release implementation updates while continuing to implement the same Contract.
