3434 - name : Install SmartThings CLI
3535 run : |
3636 npm install -g @smartthings/cli@latest
37- # Add npm global bin directory to PATH (works for both npm and npx)
38- NPM_GLOBAL_BIN=$(npm config get prefix)/bin
39- echo "$NPM_GLOBAL_BIN" >> $GITHUB_PATH
40- export PATH="$NPM_GLOBAL_BIN:$PATH"
41-
42- - name : Verify SmartThings CLI installation
43- run : |
44- npx @smartthings/cli --version
45-
46- - name : Verify SmartThings CLI authentication
47- run : |
48- # SmartThings CLI uses ST_TOKEN environment variable for authentication
49- if [[ -z "$ST_TOKEN" ]]; then
50- echo "ERROR: ST_TOKEN environment variable is not set"
51- exit 1
52- fi
53- echo "SmartThings CLI authentication configured via ST_TOKEN"
5437
5538 - name : Setup dependencies
5639 run : |
7154
7255 - name : Update device profiles
7356 run : |
57+ # Define smartthings function to run with node
58+ smartthings() {
59+ node "$(npm config get prefix)/bin/smartthings" "$@"
60+ }
61+
7462 IFS=',' read -ra FOLDERS <<< "${{ steps.find-drivers.outputs.folders }}"
7563 for folder in "${FOLDERS[@]}"; do
7664 echo "Processing profiles for: $folder"
@@ -94,27 +82,27 @@ jobs:
9482 PROFILE_NAME=$(basename "$file" .yml)
9583 echo "Processing profile: $PROFILE_NAME"
9684
97- PROFILE_ID=$(npx @ smartthings/cli deviceprofiles --json 2>/dev/null | jq -r '.[] | select(.name=="'"$PROFILE_NAME"'") | .id' 2>/dev/null || echo "")
85+ PROFILE_ID=$(smartthings deviceprofiles --json 2>/dev/null | jq -r '.[] | select(.name=="'"$PROFILE_NAME"'") | .id' 2>/dev/null || echo "")
9886
9987 if [[ -n "$PROFILE_ID" && "$PROFILE_ID" != "null" ]]; then
10088 echo "Deleting existing profile: $PROFILE_NAME ($PROFILE_ID)"
101- npx @ smartthings/cli deviceprofiles:delete "$PROFILE_ID" >/dev/null 2>&1 || true
89+ smartthings deviceprofiles:delete "$PROFILE_ID" >/dev/null 2>&1 || true
10290 fi
10391
10492 echo "Creating profile from file: $file"
105- if ! npx @ smartthings/cli deviceprofiles:create --input "$file" 2>&1; then
93+ if ! smartthings deviceprofiles:create --input "$file" 2>&1; then
10694 echo "ERROR: Failed to create profile $PROFILE_NAME"
10795 continue
10896 fi
10997
110- NEW_ID=$(npx @ smartthings/cli deviceprofiles --json 2>/dev/null | jq -r '.[] | select(.name=="'"$PROFILE_NAME"'") | .id' 2>/dev/null || echo "")
98+ NEW_ID=$(smartthings deviceprofiles --json 2>/dev/null | jq -r '.[] | select(.name=="'"$PROFILE_NAME"'") | .id' 2>/dev/null || echo "")
11199 if [[ -z "$NEW_ID" || "$NEW_ID" == "null" ]]; then
112100 echo "ERROR: Failed to find created profile $PROFILE_NAME"
113101 continue
114102 fi
115103
116104 echo "Publishing profile: $PROFILE_NAME ($NEW_ID)"
117- if ! npx @ smartthings/cli deviceprofiles:publish "$NEW_ID" 2>&1; then
105+ if ! smartthings deviceprofiles:publish "$NEW_ID" 2>&1; then
118106 echo "ERROR: Failed to publish profile $PROFILE_NAME"
119107 continue
120108 fi
@@ -176,6 +164,11 @@ jobs:
176164
177165 - name : Package and deploy drivers
178166 run : |
167+ # Define smartthings function to run with node
168+ smartthings() {
169+ node "$(npm config get prefix)/bin/smartthings" "$@"
170+ }
171+
179172 IFS=',' read -ra FOLDERS <<< "${{ steps.find-drivers.outputs.folders }}"
180173
181174 CHANNEL_ID="${{ steps.channel.outputs.channel_id }}"
@@ -186,7 +179,7 @@ jobs:
186179
187180 # Package driver
188181 echo "Packaging driver in $folder..."
189- if ! npx @ smartthings/cli edge:drivers:package "$folder" 2>&1; then
182+ if ! smartthings edge:drivers:package "$folder" 2>&1; then
190183 echo "ERROR: Failed to package driver $folder"
191184 continue
192185 fi
@@ -198,7 +191,7 @@ jobs:
198191 echo "Looking for driver with packageKey: $PACKAGE_KEY or name: $DRIVER_NAME"
199192
200193 # Find driver ID by packageKey or name
201- DRIVER_ID=$(npx @ smartthings/cli edge:drivers --json 2>/dev/null | jq -r --arg pk "$PACKAGE_KEY" --arg name "$DRIVER_NAME" '.[] | select(.packageKey == $pk or .name == $name) | .driverId' 2>/dev/null | head -n1)
194+ DRIVER_ID=$(smartthings edge:drivers --json 2>/dev/null | jq -r --arg pk "$PACKAGE_KEY" --arg name "$DRIVER_NAME" '.[] | select(.packageKey == $pk or .name == $name) | .driverId' 2>/dev/null | head -n1)
202195
203196 if [[ -z "$DRIVER_ID" || "$DRIVER_ID" == "null" ]]; then
204197 echo "WARNING: Driver not found in existing drivers list"
@@ -211,7 +204,7 @@ jobs:
211204
212205 # Assign driver to channel
213206 echo "Assigning driver $DRIVER_ID to channel $CHANNEL_ID..."
214- if ! npx @ smartthings/cli edge:channels:assign --channel "$CHANNEL_ID" "$DRIVER_ID" 2>&1; then
207+ if ! smartthings edge:channels:assign --channel "$CHANNEL_ID" "$DRIVER_ID" 2>&1; then
215208 echo "ERROR: Failed to assign driver $DRIVER_ID to channel $CHANNEL_ID"
216209 continue
217210 fi
0 commit comments