Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PTVO device converter improvements. #6318

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/devices/custom_devices_diy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,22 +535,43 @@ const definitions: Definition[] = [
} else {
// device configuration description from a device
const deviceConfigArray = deviceConfig.split(/[\r\n]+/);
let prevEp = -1;
const allEndpoints: { [key: number]: string } = {};
const allEndpointsSorted = [];
for (let i = 0; i < deviceConfigArray.length; i++) {
const epConfig = deviceConfigArray[i];
const epId = parseInt(epConfig.substr(0, 1), 16);
if (epId <= 0) {
continue;
}
allEndpoints[epId] = epConfig;
allEndpointsSorted.push(epId);
}

for (const endpoint of device.endpoints) {
if (allEndpoints.hasOwnProperty(endpoint.ID)) {
continue;
}
allEndpointsSorted.push(endpoint.ID);
allEndpoints[endpoint.ID] = '';
}
allEndpointsSorted.sort();

let prevEp = -1;
for (let i = 0; i < allEndpointsSorted.length; i++) {
const epId = allEndpointsSorted[i];
const epConfig = allEndpoints[epId];
if (epId <= 0) {
continue;
}
const epName = `l${epId}`;
const epValueAccessRights = epConfig.substr(1, 1);
const epStateType = ((epValueAccessRights === 'W') || (epValueAccessRights === '*'))?
ea.STATE_SET: ea.STATE;
let valueConfig = epConfig.substr(2);
valueConfig = valueConfig.split(',');
let valueId = (valueConfig[0])? valueConfig[0]: '';
let valueDescription = (valueConfig[1])? valueConfig[1]: '';
let valueUnit = (valueConfig[2] !== undefined)? valueConfig[2]: '';
const valueConfig = epConfig.substr(2);
const valueConfigItems = (valueConfig)? valueConfig.split(','): [];
let valueId = (valueConfigItems[0])? valueConfigItems[0]: '';
let valueDescription = (valueConfigItems[1])? valueConfigItems[1]: '';
let valueUnit = (valueConfigItems[2] !== undefined)? valueConfigItems[2]: '';
const exposeEpOptions: KeyValue = {};
if (valueId === '*') {
// GPIO output (Generic)
Expand All @@ -574,7 +595,7 @@ const definitions: Definition[] = [
exposeObj = e.contact();
}
expose.push(exposeObj.withEndpoint(epName));
} else if (valueConfig) {
} else if (valueConfigItems.length > 0) {
let valueName = undefined; // name in Z2M
let valueNumIndex = undefined;
const idxPos = valueId.search(/(\d+)$/);
Expand All @@ -590,7 +611,7 @@ const definitions: Definition[] = [
// 1: value name (if empty, use the EP name)
// 2: description (if empty or undefined, use the value name)
// 3: units (if undefined, use the key name)
const infoLookup: KeyValue = {
const infoLookup: { [key: string]: string } = {
'C': 'temperature',
'%': 'humidity',
'm': 'altitude',
Expand Down