Skip to content

Commit

Permalink
Merge pull request #387 from athombv/master
Browse files Browse the repository at this point in the history
Merge master into production (#minor)
  • Loading branch information
RobinBol authored Apr 18, 2024
2 parents dda5af7 + 00c7cc8 commit f01938d
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 3 deletions.
94 changes: 93 additions & 1 deletion assets/app/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,94 @@
]
}
},
"matterDevice": {
"type": "object",
"required": ["vendorId", "productId"],
"properties": {
"vendorId": {
"oneOf": [
{
"type": "number",
"minimum": 1,
"maximum": 65520
},
{
"type": "array",
"items": {
"type": "number",
"minimum": 1,
"maximum": 65520
}
}
]
},
"productId": {
"oneOf": [
{
"type": "number",
"minimum": 1,
"maximum": 65535
},
{
"type": "array",
"items": {
"type": "number",
"minimum": 1,
"maximum": 65535
}
}
]
},
"deviceVendorId": {
"oneOf": [
{
"type": "number",
"minimum": 1,
"maximum": 65520
},
{
"type": "array",
"items": {
"type": "number",
"minimum": 1,
"maximum": 65520
}
}
]
},
"deviceProductName": {
"oneOf": [
{
"type": "string",
"minLength": 1,
"maxLength": 32
},
{
"type": "array",
"items": {
"type": "string",
"minLength": 1,
"maxLength": 32
}
}
]
},
"learnmode": {
"type": "object",
"required": [
"instruction"
],
"properties": {
"image": {
"type": "string"
},
"instruction": {
"$ref": "#/definitions/i18nObject"
}
}
}
}
},
"zigbeeDevice": {
"type": "object",
"required": [
Expand Down Expand Up @@ -1322,6 +1410,9 @@
}
]
},
"matter": {
"$ref": "#/definitions/matterDevice"
},
"zwave": {
"$ref": "#/definitions/zwaveDevice"
},
Expand Down Expand Up @@ -1368,7 +1459,8 @@
"zigbee",
"infrared",
"rf433",
"rf868"
"rf868",
"matter"
]
}
}
Expand Down
39 changes: 37 additions & 2 deletions lib/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ class App {
}

// validate `appJson.drivers[].connectivity`
if (driver.connectivity && (driver.connectivity.includes('lan') || driver.connectivity.includes('rf868'))) {
if (driver.connectivity && (driver.connectivity.includes('lan') || driver.connectivity.includes('rf868') || driver.connectivity.includes('matter'))) {
if (driver.platforms && driver.platforms.includes('cloud')) {
throw new Error(`drivers.${driver.id} invalid 'connectivity': Platform 'cloud' does not support 'lan' or 'rf868'.`);
throw new Error(`drivers.${driver.id} invalid 'connectivity': Platform 'cloud' does not support 'lan', 'matter' or 'rf868'.`);
}
}

Expand All @@ -365,6 +365,41 @@ class App {
});
}
}

if (driver.connectivity && driver.connectivity.includes('matter')) {
if (!driver.matter) {
throw new Error(`drivers.${driver.id} has 'connectivity': 'matter' and therefore requires a 'matter' object.`);
}

if (driver.pair) {
throw new Error(`drivers.${driver.id} invalid 'pair' configuration, Matter drivers do not support custom pairing views.`);
}

if (
(driver.matter.deviceVendorId === undefined && driver.matter.deviceProductName !== undefined) ||
(driver.matter.deviceVendorId !== undefined && driver.matter.deviceProductName === undefined)
) {
throw new Error(`drivers.${driver.id} invalid 'matter': 'deviceVendorId' and 'deviceProductName' must be defined together.`);
}

const deviceJsExists = await this._fileExistsCaseSensitive(join('drivers', driver.id, 'device.js'));
const deviceMjsExists = await this._fileExistsCaseSensitive(join('drivers', driver.id, 'device.mjs'));

if (deviceJsExists || deviceMjsExists) {
throw new Error(`drivers.${driver.id}: using a device.${deviceJsExists ? 'js' : 'mjs'} file is not supported for Matter drivers.`);
}

const driverJsExists = await this._fileExistsCaseSensitive(join('drivers', driver.id, 'driver.js'));
const driverMjsExists = await this._fileExistsCaseSensitive(join('drivers', driver.id, 'driver.mjs'));

if (driverJsExists || driverMjsExists) {
throw new Error(`drivers.${driver.id}: using a driver.${driverJsExists ? 'js' : 'mjs'} file is not supported for Matter drivers.`);
}
}

if (driver.matter && !(driver.connectivity && driver.connectivity.includes('matter'))) {
throw new Error(`drivers.${driver.id} Matter drivers require 'connectivity' to include 'matter'.`);
}
}
}

Expand Down

0 comments on commit f01938d

Please sign in to comment.