Skip to content

Commit d1d7e2e

Browse files
authored
Merge branch 'main' into Ledvance_Zigbee_EM_EU_PLUG
2 parents 70b6187 + 42a6a23 commit d1d7e2e

416 files changed

Lines changed: 17343 additions & 6630 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
---
2+
name: dev-workflow
3+
description: Setting up the development environment, deploying Edge Drivers to hubs, and sharing drivers with other users via channels and invites
4+
---
5+
6+
# SmartThings Edge Driver Development Workflow
7+
8+
This skill covers environment setup, driver deployment to hubs, and sharing
9+
drivers with other users through channels and invite links.
10+
11+
---
12+
13+
## Environment Setup
14+
15+
### 1. Install Lua 5.3
16+
17+
Edge Drivers are Lua-based. Install the Lua 5.3 runtime for local development
18+
and linting:
19+
20+
```bash
21+
# Ubuntu / Debian
22+
sudo apt install lua5.3
23+
24+
# macOS
25+
brew install lua@5.3
26+
27+
# Windows
28+
# Download the Lua 5.3 binary from https://luabinaries.sourceforge.net/download.html
29+
# Or install via scoop:
30+
scoop install lua
31+
# Or via chocolatey:
32+
choco install lua53
33+
```
34+
35+
### 2. lua_libs Directory
36+
37+
The `lua_libs/` directory contains the SmartThings Lua libraries that are
38+
available on the hub at runtime. These correspond to the assets attached to the
39+
latest release on GitHub:
40+
41+
<https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/releases/latest>
42+
43+
Download the lua_libs archive from the release assets and
44+
extract it into the repository root if it is missing or needs updating.
45+
46+
### 3. Configure LUA_PATH
47+
48+
Set `LUA_PATH` so that `require` resolves both your driver modules and the
49+
SmartThings library modules in `lua_libs/`:
50+
51+
```bash
52+
export LUA_PATH="./?.lua;./?/init.lua;$(pwd)/lua_libs/?.lua;$(pwd)/lua_libs/?/init.lua;;"
53+
```
54+
55+
Run it from the repository root so `$(pwd)` resolves correctly.
56+
57+
58+
### 4. Install the SmartThings CLI
59+
60+
The CLI is required for packaging, deploying, and managing drivers and
61+
channels on the platform.
62+
63+
```bash
64+
# Via npm (requires Node.js >= 24.8.0)
65+
npm install -g @smartthings/cli
66+
67+
# macOS via Homebrew
68+
brew install smartthingscommunity/smartthings/smartthings
69+
70+
# Linux / Windows
71+
# Download the binary or installer from:
72+
# https://github.com/SmartThingsCommunity/smartthings-cli/releases
73+
```
74+
75+
Verify the installation:
76+
77+
```bash
78+
smartthings --version
79+
```
80+
81+
The CLI uses browser-based OAuth login by default. Run `smartthings devices` to trigger
82+
the login flow.
83+
84+
### 5. Python Requirements (Testing)
85+
86+
Some test and tooling scripts require Python dependencies:
87+
88+
```bash
89+
pip install -r tools/requirements.txt
90+
```
91+
92+
### 6. Install Luacheck (Linting)
93+
94+
Luacheck provides static analysis for Lua source files. It requires LuaRocks
95+
(the Lua package manager).
96+
97+
**Install LuaRocks first:**
98+
99+
```bash
100+
# Ubuntu / Debian
101+
sudo apt install luarocks
102+
103+
# macOS
104+
brew install luarocks
105+
106+
# Windows
107+
# Download the installer from https://luarocks.org/releases/
108+
# Or via chocolatey:
109+
choco install luarocks
110+
```
111+
112+
**Then install Luacheck:**
113+
114+
```bash
115+
# Via LuaRocks (all platforms)
116+
luarocks install luacheck
117+
118+
# macOS alternative (installs both luarocks and luacheck)
119+
brew install luacheck
120+
```
121+
122+
Run it against a driver directory:
123+
124+
```bash
125+
luacheck --config .github/workflows/.luacheckrc drivers/SmartThings/zigbee-switch/
126+
```
127+
128+
---
129+
130+
## Deploying Drivers
131+
132+
### Overview
133+
134+
Deploying a driver to a physical hub requires three things:
135+
136+
1. A **channel** you own.
137+
2. The hub **enrolled** in that channel.
138+
3. The driver **packaged and uploaded** through the CLI.
139+
140+
### Step 1: Create a Channel
141+
142+
```bash
143+
smartthings edge:channels:create
144+
```
145+
146+
You will be prompted for a name and description. Note the returned channel ID.
147+
148+
### Step 2: Enroll Your Hub
149+
150+
```bash
151+
smartthings edge:channels:enroll <hub-id>
152+
```
153+
154+
Select the channel when prompted, or pass `--channel <channel-id>`.
155+
156+
Find your hub ID with:
157+
158+
```bash
159+
smartthings devices --type HUB
160+
```
161+
162+
### Step 3: Package and Install the Driver
163+
164+
The `edge:drivers:package` command can build, upload, assign to a channel, and
165+
install in one step:
166+
167+
```bash
168+
smartthings edge:drivers:package <path-to-driver-dir> \
169+
--hub=<hub-uuid> \
170+
--channel=<channel-id>
171+
```
172+
173+
For example:
174+
175+
```bash
176+
smartthings edge:drivers:package drivers/SmartThings/zwave-switch \
177+
--hub=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee \
178+
--channel=11111111-2222-3333-4444-555555555555
179+
```
180+
181+
### Other Useful Deployment Commands
182+
183+
```bash
184+
# List drivers installed on a hub
185+
smartthings edge:drivers:installed --hub=<hub-uuid>
186+
187+
# Stream logs from a driver on the hub
188+
smartthings edge:drivers:logcat <driver-id> --hub=<hub-uuid>
189+
190+
# Uninstall a driver from a hub
191+
smartthings edge:drivers:uninstall <driver-id> --hub=<hub-uuid>
192+
193+
# Remove unused drivers from a hub
194+
smartthings edge:drivers:prune --hub=<hub-uuid>
195+
196+
# Switch a device to a different driver
197+
smartthings edge:drivers:switch <device-id>
198+
```
199+
200+
---
201+
202+
## Sharing Drivers
203+
204+
### Creating an Invite Link
205+
206+
Invite links let other users install your driver from your channel without
207+
giving them ownership of the driver or channel.
208+
209+
```bash
210+
smartthings edge:channels:invites:create
211+
```
212+
213+
You will be prompted to select a channel and a driver. The command returns an
214+
invite URL of the form:
215+
216+
```
217+
https://bestow-regional.api.smartthings.com/invite/<invite-id>
218+
```
219+
220+
Share this URL with users. They open it in a browser or the SmartThings mobile
221+
app to accept the invitation.
222+
223+
### Enrollment Flow for Recipients
224+
225+
1. The recipient opens the invite link.
226+
2. They log in to their Samsung / SmartThings account.
227+
3. They select a hub to enroll in the channel.
228+
4. The driver can be selected to install to that hub.
229+
230+
### Managing Invites
231+
232+
```bash
233+
# List existing invites
234+
smartthings edge:channels:invites
235+
236+
# Delete an invite
237+
smartthings edge:channels:invites:delete <invite-id>
238+
```
239+
240+
### Managing Channel Assignments
241+
242+
```bash
243+
# Assign a specific driver version to a channel
244+
smartthings edge:channels:assign <driver-id> <version>
245+
246+
# List drivers assigned to a channel
247+
smartthings edge:channels:drivers <channel-id>
248+
249+
# Remove a driver from a channel
250+
smartthings edge:channels:unassign <driver-id>
251+
```
252+
253+
---
254+
255+
## Quick Reference
256+
257+
| Task | Command |
258+
|------|---------|
259+
| Create channel | `smartthings edge:channels:create` |
260+
| Enroll hub | `smartthings edge:channels:enroll <hub-id>` |
261+
| Package & deploy | `smartthings edge:drivers:package <dir> --hub=<id> --channel=<id>` |
262+
| Stream logs | `smartthings edge:drivers:logcat <driver-id> --hub=<id>` |
263+
| Create invite | `smartthings edge:channels:invites:create` |
264+
| List installed drivers | `smartthings edge:drivers:installed --hub=<id>` |
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
name: linting-and-style
3+
description: Running luacheck for Lua linting and following code style conventions in Edge Driver development
4+
---
5+
6+
# Linting and Code Style for Edge Drivers
7+
8+
## Running Luacheck
9+
10+
```bash
11+
luacheck --config .github/workflows/.luacheckrc <path>
12+
```
13+
14+
### Examples
15+
16+
```bash
17+
# Lint a specific driver
18+
luacheck --config .github/workflows/.luacheckrc drivers/SmartThings/zigbee-switch/
19+
20+
# Lint a single file
21+
luacheck --config .github/workflows/.luacheckrc drivers/SmartThings/zigbee-switch/src/init.lua
22+
23+
# Lint the entire repo
24+
luacheck --config .github/workflows/.luacheckrc .
25+
```
26+
27+
Luacheck runs automatically in CI on pull requests that modify files under `drivers/` (see `.github/workflows/luacheck.yml`).
28+
29+
## Code Style Conventions
30+
31+
These conventions are observed across the Edge Driver codebase:
32+
33+
### General
34+
35+
- **Indentation**: 2 spaces, no tabs
36+
- **Strings**: Use double quotes `"string"` for module requires and general strings
37+
- **Local variables**: Always use `local` for variables and functions at module scope
38+
- **Line length**: No enforced limit, but most code stays under 120 characters
39+
40+
### Naming
41+
42+
- **Variables and functions**: `snake_case` (e.g., `local mock_device`, `local function test_init()`)
43+
- **Constants**: `UPPER_SNAKE_CASE` for true constants (e.g., `SENSOR_BINARY`)
44+
- **Modules**: Return a table at the end of the file (`return module_name`)
45+
46+
### Requires and Imports
47+
48+
```lua
49+
-- Standard library requires first
50+
local capabilities = require "st.capabilities"
51+
local zw = require "st.zwave"
52+
53+
-- Then test/integration requires
54+
local test = require "integration_test"
55+
local t_utils = require "integration_test.utils"
56+
57+
-- Then protocol-specific requires
58+
local SensorBinary = (require "st.zwave.CommandClass.SensorBinary")({ version = 2 })
59+
```
60+
61+
### Function Style
62+
63+
- Prefer `local function name()` over `local name = function()`
64+
- Handler functions typically receive `(driver, device, ...)` arguments
65+
- Use early returns for guard clauses
66+
67+
### Tables
68+
69+
- Trailing commas are common and acceptable in multi-line tables
70+
- Align table entries for readability in test manifests
71+
72+
### Comments
73+
74+
- Use `--` for single-line comments
75+
- Minimal inline comments; code should be self-documenting
76+
77+
Copyright header at the top of every file:
78+
```lua
79+
-- Copyright 2026 SmartThings, Inc.
80+
-- Licensed under the Apache License, Version 2.0
81+
```
82+
83+
### File Organization for Drivers
84+
85+
```
86+
driver-name/
87+
src/
88+
init.lua -- Main driver entry point
89+
<sub_modules>.lua -- Additional driver modules
90+
test/
91+
test_*.lua -- Test files (must start with test_)
92+
profiles/
93+
*.yml -- Device profiles
94+
fingerprints.yml -- Device fingerprints
95+
config.yml -- Driver configuration
96+
```

0 commit comments

Comments
 (0)