Skip to content

Commit 1b79c24

Browse files
paulr34cursoragent
andcommitted
fix UC missing-component warning for pre-enabled clusters
When you open a sample .zap that already had clusters enabled, the "Required SLC Component not installed" warning was showing for every one of them even though Studio had the components installed. The install-requested gate I added in 9cee621 covers the case where ZAP itself just clicked Install, but pre-existing clusters never go through that path, so they fell through to the older id comparison. That comparison was inconsistent about how it stripped Studio's id prefixes. getClusterIdsByUcComponents would take everything after the last `-` for anything containing "zigbee", but it would keep the full `%extension-...%name` prefix for matter and only strip a leading `%` in normalizeUcDependencyId. So: tree leaf studiocomproot-...-zigbee_basic -> "zigbee_basic" required %extension-zigbee%zigbee_basic -> "extension-zigbee%zigbee_basic" Different strings, no match, warning shown. The matter path only worked because both sides happened to keep the same `%extension-...%` form, so the bad logic was symmetric for that one case. Pull the id-shortening into a single extractUcClusterCode helper that strips a leading `%`, takes everything after the last remaining `%` if there is one, then takes everything after the last `-`. Run both selected ids and required ids through it. Now both sides reduce to the same cluster code regardless of which delimiter Studio used: studiocomproot-...-zigbee_basic -> "zigbee_basic" %extension-zigbee%zigbee_basic -> "zigbee_basic" matter:1.0.0-...-%extension-matter%matter_level_control -> "matter_level_control" zigbee_basic -> "zigbee_basic" Matter still matches the way it did before (both sides reduce identically), zigbee with the %-prefixed required value now matches too, and the install-requested short-circuit from 9cee621 keeps covering the freshly-installed flow. Also adds a JSDoc on the inner applyAdded helper in applyUcComponentUpdate -- eslint's require-jsdoc was failing the build with this rule on. Functional code unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9cee621 commit 1b79c24

2 files changed

Lines changed: 45 additions & 25 deletions

File tree

src/store/zap/mutations.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,11 @@ export function applyUcComponentUpdate(state, payload) {
10261026
prevAll.filter((x) => x && x.id != null).map((x) => [String(x.id), x])
10271027
)
10281028

1029+
/**
1030+
* Upsert a component into the selected and catalog maps for this mutation.
1031+
* @param {*} id Component id to add.
1032+
* @param {*} node Optional node payload to store; falls back to a stub.
1033+
*/
10291034
function applyAdded(id, node) {
10301035
if (id == null) return
10311036
const key = String(id)

src/util/util.js

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -152,48 +152,63 @@ export function getUcComponents(ucComponentTreeResponse) {
152152
return selectedComponents
153153
}
154154

155+
/**
156+
* Reduce any UC component id (Studio tree leaf, %extension-...%component, raw
157+
* short code) to its lowercase short cluster code form, so both sides of the
158+
* missing-component comparison line up regardless of which delimiter Studio
159+
* happens to use.
160+
*
161+
* Examples:
162+
* "studiocomproot-Zigbee-Cluster_Library-Common-zigbee_basic" -> "zigbee_basic"
163+
* "matter:1.0.0-Matter-Clusters-%extension-matter%matter_level_control"
164+
* -> "matter_level_control"
165+
* "%extension-zigbee%zigbee_basic" -> "zigbee_basic"
166+
* "zigbee_basic" -> "zigbee_basic"
167+
*
168+
* @param {*} id
169+
* @returns {string}
170+
*/
171+
export function extractUcClusterCode(id) {
172+
if (id == null) return ''
173+
let s = String(id).toLowerCase().replace(/^%+/, '')
174+
const lastPct = s.lastIndexOf('%')
175+
if (lastPct >= 0 && lastPct < s.length - 1) {
176+
s = s.substring(lastPct + 1)
177+
}
178+
const lastDash = s.lastIndexOf('-')
179+
if (lastDash >= 0 && lastDash < s.length - 1) {
180+
s = s.substring(lastDash + 1)
181+
}
182+
return s
183+
}
184+
155185
/**
156186
* Extract a list of cluster id from a list of Uc component id
157187
*
158-
* return: a list of ids
159-
* id value example:
160-
* "zigbee_basic" from "studiocomproot-Zigbee-Cluster_Library-Common-zigbee_basic"
161-
"%extension-matter%matter_level_control" from "matter:1.0.0-Matter-Clusters-%extension-matter%matter_level_control"
162-
* @param {*} ucComponentIds - an array of ids
188+
* return: a list of ids in their short cluster-code form (see extractUcClusterCode).
189+
*
190+
* @param {*} ucComponents - an array of UC component objects with `id`
163191
*/
164192
export function getClusterIdsByUcComponents(ucComponents) {
165193
if (!Array.isArray(ucComponents)) return []
166194
return ucComponents
167195
.map((component) => component?.id)
168196
.filter((id) => id != null && String(id).length > 0)
169-
.map((id) => {
170-
id = String(id)
171-
const lower = id.toLowerCase()
172-
if (lower.includes('zigbee')) {
173-
return id.substring(id.lastIndexOf('-') + 1)
174-
}
175-
const pct = id.lastIndexOf('%extension-')
176-
if (pct >= 0) {
177-
return id.substring(pct)
178-
}
179-
const ext = lower.lastIndexOf('extension-')
180-
if (ext >= 0) {
181-
return id.substring(ext)
182-
}
183-
return id
184-
})
197+
.map((id) => extractUcClusterCode(id))
185198
.filter((id) => id != null && id !== '')
186199
}
187200

188201
/**
189-
* Normalize UC dependency id for comparing ZCL extension values to Studio node ids.
202+
* Normalize an id from the ZCL extension's `value` so it can be compared
203+
* against entries produced by getClusterIdsByUcComponents. Applies the same
204+
* delimiter-aware extraction so e.g. "%extension-zigbee%zigbee_basic" reduces
205+
* to "zigbee_basic" instead of leaving the prefix intact.
206+
*
190207
* @param {string} id
191208
* @returns {string}
192209
*/
193210
export function normalizeUcDependencyId(id) {
194-
return String(id || '')
195-
.toLowerCase()
196-
.replace(/^%+/, '')
211+
return extractUcClusterCode(id)
197212
}
198213

199214
/**

0 commit comments

Comments
 (0)