Created
October 8, 2021 18:39
-
-
Save nayelyzarazua-bluetrail/b1b29607c758512cc95a65d1d4ac7568 to your computer and use it in GitHub Desktop.
Hello_World_customCapabilities
This file contains 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
-- require st provided libraries | |
local capabilities = require "st.capabilities" | |
local Driver = require "st.driver" | |
local log = require "log" | |
-- require custom handlers from driver package | |
local discovery = require "discovery" | |
--construct the custom capability to use it in the driver | |
--This is the result of the command >> smartthings capabilities namespace.oneiteminlist -j | |
local oneiteminlist = capabilities.build_cap_from_json_string([[ | |
{ | |
"id": "namespace.oneiteminlist", | |
"version": 1, | |
"status": "proposed", | |
"name": "OneItemInlist", | |
"attributes": { | |
"itemValue": { | |
"schema": { | |
"type": "object", | |
"properties": { | |
"value": { | |
"type": "string", | |
"enum": [ | |
"itemOne", | |
"itemTwo", | |
"itemThree", | |
"itemFour" | |
] | |
} | |
}, | |
"additionalProperties": false, | |
"required": [ | |
"value" | |
] | |
}, | |
"setter": "setItemValue", | |
"enumCommands": [] | |
} | |
}, | |
"commands": { | |
"setItemValue": { | |
"name": "setItemValue", | |
"arguments": [ | |
{ | |
"name": "value", | |
"optional": false, | |
"schema": { | |
"type": "string" | |
} | |
} | |
] | |
} | |
} | |
} | |
]]) | |
--Add the capability to the lookup table | |
capabilities["namespace.oneiteminlist"] = oneiteminlist | |
----------------------------------------------------------------- | |
-- local functions | |
----------------------------------------------------------------- | |
-- this is called once a device is added by the cloud and synchronized down to the hub | |
local function device_added(driver, device) | |
log.info("[" .. device.id .. "] Adding new Hello World device") | |
end | |
-- this is called both when a device is added (but after `added`) and after a hub reboots. | |
local function device_init(driver, device) | |
log.info("[" .. device.id .. "] Initializing Hello World device") | |
-- mark device as online so it can be controlled from the app | |
device:online() | |
end | |
-- this is called when a device is removed by the cloud and synchronized down to the hub | |
local function device_removed(driver, device) | |
log.info("[" .. device.id .. "] Removing Hello World device") | |
end | |
local function info_changed(driver, device) | |
log.trace("infochanged value below...") | |
end | |
--Capability handler for the custom capability | |
local function setItemValue(driver, device, command) | |
device:emit_event(capabilities["namespace.oneiteminlist"].itemValue(command.args.value)) | |
end | |
-- create the driver object | |
local hello_world_driver = Driver("Color temp device", { | |
supported_capabilities = { | |
oneiteminlist --variable of the constructed capability | |
}, | |
discovery = discovery.handle_discovery, | |
lifecycle_handlers = { | |
added = device_added, | |
init = device_init_incorrect, | |
infoChanged = info_changed, | |
removed = device_removed | |
}, | |
capability_handlers = { | |
[oneiteminlist.ID] = { | |
[oneiteminlist.commands.setItemValue.NAME] = setItemValue --set the capability handler | |
} | |
} | |
}) | |
-- run the driver | |
hello_world_driver:run() |
This file contains 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
name: profileName | |
components: | |
- id: main | |
capabilities: | |
- id: namespace.oneiteminlist | |
version: 1 | |
- id: refresh | |
version: 1 | |
categories: | |
- name: Switch | |
metadata: | |
mnmn: SmartThingsCommunity | |
vid: xxxx-xxxxx-xxxxx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment