Skip to content

Commit

Permalink
Set element conformance notifications on file opening (#1513)
Browse files Browse the repository at this point in the history
* add element conform warning on file opening
* fix expression parsing
* print warnings to console
  • Loading branch information
ethanzhouyc authored Feb 4, 2025
1 parent 016b3b8 commit d2e48db
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 76 deletions.
48 changes: 16 additions & 32 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3658,6 +3658,7 @@ This module provides queries for features.
* [~processElements(elementType)](#module_DB API_ feature related queries..getOutdatedElementWarning..processElements)
* [~filterRequiredElements(elements, elementMap, featureMap)](#module_DB API_ feature related queries..filterRequiredElements) ⇒
* [~checkIfConformanceDataExist(db)](#module_DB API_ feature related queries..checkIfConformanceDataExist) ⇒
* [~getEndpointTypeElements(db, endpointTypeClusterId, deviceTypeClusterId)](#module_DB API_ feature related queries..getEndpointTypeElements) ⇒

<a name="module_DB API_ feature related queries..getFeaturesByDeviceTypeRefs"></a>

Expand Down Expand Up @@ -3866,6 +3867,21 @@ and DEVICE_TYPE_FEATURE table.
| --- | --- |
| db | <code>\*</code> |

<a name="module_DB API_ feature related queries..getEndpointTypeElements"></a>

### DB API: feature related queries~getEndpointTypeElements(db, endpointTypeClusterId, deviceTypeClusterId) ⇒
Get all attributes, commands and events in an endpoint type cluster.

**Kind**: inner method of [<code>DB API: feature related queries</code>](#module_DB API_ feature related queries)
**Returns**: elements object containing all attributes, commands and events
in an endpoint type cluster

| Param | Type |
| --- | --- |
| db | <code>\*</code> |
| endpointTypeClusterId | <code>\*</code> |
| deviceTypeClusterId | <code>\*</code> |

<a name="module_DB API_ package-based queries."></a>

## DB API: package-based queries.
Expand Down Expand Up @@ -14582,7 +14598,6 @@ This module provides the API to access zcl specific information.
* [~httpGetSessionKeyValues(db)](#module_REST API_ user data..httpGetSessionKeyValues) ⇒
* [~httpGetEndpointIds(db)](#module_REST API_ user data..httpGetEndpointIds) ⇒
* [~httpGetDeviceTypeFeatures(db)](#module_REST API_ user data..httpGetDeviceTypeFeatures) ⇒
* [~getEndpointTypeElements(db, endpointTypeClusterId, deviceTypeClusterId)](#module_REST API_ user data..getEndpointTypeElements) ⇒
* [~httpPostCheckConformOnFeatureUpdate(db)](#module_REST API_ user data..httpPostCheckConformOnFeatureUpdate) ⇒
* [~httpGetRequiredElements(db)](#module_REST API_ user data..httpGetRequiredElements) ⇒
* [~httpGetSessionNotifications(db)](#module_REST API_ user data..httpGetSessionNotifications) ⇒
Expand Down Expand Up @@ -14670,21 +14685,6 @@ HTTP GET: device type features
| --- | --- |
| db | <code>\*</code> |

<a name="module_REST API_ user data..getEndpointTypeElements"></a>

### REST API: user data~getEndpointTypeElements(db, endpointTypeClusterId, deviceTypeClusterId) ⇒
Get all attributes, commands and events in an endpoint type cluster.

**Kind**: inner method of [<code>REST API: user data</code>](#module_REST API_ user data)
**Returns**: elements object containing all attributes, commands and events
in an endpoint type cluster

| Param | Type |
| --- | --- |
| db | <code>\*</code> |
| endpointTypeClusterId | <code>\*</code> |
| deviceTypeClusterId | <code>\*</code> |

<a name="module_REST API_ user data..httpPostCheckConformOnFeatureUpdate"></a>

### REST API: user data~httpPostCheckConformOnFeatureUpdate(db) ⇒
Expand Down Expand Up @@ -15921,7 +15921,6 @@ This module provides the REST API to the user specific data.
* [~httpGetSessionKeyValues(db)](#module_REST API_ user data..httpGetSessionKeyValues) ⇒
* [~httpGetEndpointIds(db)](#module_REST API_ user data..httpGetEndpointIds) ⇒
* [~httpGetDeviceTypeFeatures(db)](#module_REST API_ user data..httpGetDeviceTypeFeatures) ⇒
* [~getEndpointTypeElements(db, endpointTypeClusterId, deviceTypeClusterId)](#module_REST API_ user data..getEndpointTypeElements) ⇒
* [~httpPostCheckConformOnFeatureUpdate(db)](#module_REST API_ user data..httpPostCheckConformOnFeatureUpdate) ⇒
* [~httpGetRequiredElements(db)](#module_REST API_ user data..httpGetRequiredElements) ⇒
* [~httpGetSessionNotifications(db)](#module_REST API_ user data..httpGetSessionNotifications) ⇒
Expand Down Expand Up @@ -16009,21 +16008,6 @@ HTTP GET: device type features
| --- | --- |
| db | <code>\*</code> |

<a name="module_REST API_ user data..getEndpointTypeElements"></a>

### REST API: user data~getEndpointTypeElements(db, endpointTypeClusterId, deviceTypeClusterId) ⇒
Get all attributes, commands and events in an endpoint type cluster.

**Kind**: inner method of [<code>REST API: user data</code>](#module_REST API_ user data)
**Returns**: elements object containing all attributes, commands and events
in an endpoint type cluster

| Param | Type |
| --- | --- |
| db | <code>\*</code> |
| endpointTypeClusterId | <code>\*</code> |
| deviceTypeClusterId | <code>\*</code> |

<a name="module_REST API_ user data..httpPostCheckConformOnFeatureUpdate"></a>

### REST API: user data~httpPostCheckConformOnFeatureUpdate(db) ⇒
Expand Down
49 changes: 43 additions & 6 deletions src-electron/db/query-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
const dbApi = require('./db-api')
const dbMapping = require('./db-mapping')
const queryAttribute = require('./query-attribute')
const queryCommand = require('./query-command')
const queryEvent = require('./query-event')

/**
* Get all device type features associated with a list of device type refs and an endpoint.
Expand Down Expand Up @@ -134,7 +137,7 @@ function evaluateConformanceExpression(expression, elementMap) {
*/
function evaluateBooleanExpression(expr) {
// Replace terms with their actual values from elementMap
expr = expr.replace(/[A-Za-z][A-Za-z0-9]*/g, (term) => {
expr = expr.replace(/[A-Za-z][A-Za-z0-9_]*/g, (term) => {
if (elementMap[term]) {
return 'true'
} else {
Expand Down Expand Up @@ -167,7 +170,7 @@ function evaluateConformanceExpression(expression, elementMap) {
let parts = expression.split(',')
// if any term is desc, the conformance is too complex to parse
for (let part of parts) {
let terms = part.match(/[A-Za-z][A-Za-z0-9]*/g)
let terms = part.match(/[A-Za-z][A-Za-z0-9_]*/g)
if (terms && terms.includes('desc')) {
return 'desc'
}
Expand Down Expand Up @@ -214,7 +217,7 @@ function evaluateConformanceExpression(expression, elementMap) {
* @returns all missing terms in an array
*/
function checkMissingTerms(expression, elementMap) {
let terms = expression.match(/[A-Za-z][A-Za-z0-9]*/g)
let terms = expression.match(/[A-Za-z][A-Za-z0-9_]*/g)
let missingTerms = []
let abbreviations = ['M', 'O', 'P', 'D', 'X']
for (let term of terms) {
Expand All @@ -234,7 +237,7 @@ function checkMissingTerms(expression, elementMap) {
*/
function filterElementsContainingDesc(elements) {
return elements.filter((element) => {
let terms = element.conformance.match(/[A-Za-z][A-Za-z0-9]*/g)
let terms = element.conformance.match(/[A-Za-z][A-Za-z0-9_]*/g)
return terms && terms.includes('desc')
})
}
Expand All @@ -248,7 +251,7 @@ function filterElementsContainingDesc(elements) {
*/
function filterRelatedDescElements(elements, featureCode) {
return elements.filter((element) => {
let terms = element.conformance.match(/[A-Za-z][A-Za-z0-9]*/g)
let terms = element.conformance.match(/[A-Za-z][A-Za-z0-9_]*/g)
return terms && terms.includes('desc') && terms.includes(featureCode)
})
}
Expand Down Expand Up @@ -554,7 +557,7 @@ function filterRequiredElements(elements, elementMap, featureMap) {
elementMap
)
let expression = element.conformance
let terms = expression ? expression.match(/[A-Za-z][A-Za-z0-9]*/g) : []
let terms = expression ? expression.match(/[A-Za-z][A-Za-z0-9_]*/g) : []
let featureTerms = terms.filter((term) => term in featureMap).join(', ')
let elementTerms = terms.filter((term) => !(term in featureMap)).join(', ')
let conformToElement = terms.some((term) =>
Expand Down Expand Up @@ -626,10 +629,44 @@ async function checkIfConformanceDataExist(db) {
}
}

/**
* Get all attributes, commands and events in an endpoint type cluster.
* @param {*} db
* @param {*} endpointTypeClusterId
* @param {*} deviceTypeClusterId
* @returns elements object containing all attributes, commands and events
* in an endpoint type cluster
*/
async function getEndpointTypeElements(
db,
endpointTypeClusterId,
deviceTypeClusterId
) {
let [attributes, commands, events] = await Promise.all([
queryAttribute.selectAttributesByEndpointTypeClusterIdAndDeviceTypeClusterId(
db,
endpointTypeClusterId,
deviceTypeClusterId
),
queryCommand.selectCommandsByEndpointTypeClusterIdAndDeviceTypeClusterId(
db,
endpointTypeClusterId,
deviceTypeClusterId
),
queryEvent.selectEventsByEndpointTypeClusterIdAndDeviceTypeClusterId(
db,
endpointTypeClusterId,
deviceTypeClusterId
)
])
return { attributes, commands, events }
}

exports.getFeaturesByDeviceTypeRefs = getFeaturesByDeviceTypeRefs
exports.checkElementConformance = checkElementConformance
exports.evaluateConformanceExpression = evaluateConformanceExpression
exports.filterElementsContainingDesc = filterElementsContainingDesc
exports.filterRelatedDescElements = filterRelatedDescElements
exports.checkIfConformanceDataExist = checkIfConformanceDataExist
exports.getOutdatedElementWarning = getOutdatedElementWarning
exports.getEndpointTypeElements = getEndpointTypeElements
Loading

0 comments on commit d2e48db

Please # to comment.