Skip to content

Commit

Permalink
replace invalid chars in state id's
Browse files Browse the repository at this point in the history
  • Loading branch information
DEV2DEV-DE committed Nov 29, 2023
1 parent 352ba02 commit 2d4b32b
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ class Jablotron extends utils.Adapter {
* @param {string} name
*/
async createFolder(id, name) {
if (!this.existsState(id)) {
await this.extendObjectAsync(id, { type: 'folder', common: { name: `${name}` }, native: {}, });
this.states.push(id);
const stateId = this.name2id(id);
if (!this.existsState(stateId)) {
await this.extendObjectAsync(stateId, { type: 'folder', common: { name: `${name}` }, native: {}, });
this.states.push(stateId);
}
}

Expand All @@ -302,9 +303,10 @@ class Jablotron extends utils.Adapter {
* @param {string} name
*/
async createChannel(id, name) {
if (!this.existsState(id)) {
await this.extendObjectAsync(id, { type: 'channel', common: { name: `${name}` }, native: {}, });
this.states.push(id);
const stateId = this.name2id(id);
if (!this.existsState(stateId)) {
await this.extendObjectAsync(stateId, { type: 'channel', common: { name: `${name}` }, native: {}, });
this.states.push(stateId);
}
}

Expand Down Expand Up @@ -334,11 +336,12 @@ class Jablotron extends utils.Adapter {
break;
default: throw new Error('Unknown type for value "' + name + '"');
}
if (!this.existsState(id)) {
await this.extendObjectAsync(id, { type: 'state', common: { name: `${name}`, type: `${type}`, role: role, read: read, write: write }, native: {}, });
this.states.push(id);
const stateId = this.name2id(id);
if (!this.existsState(stateId)) {
await this.extendObjectAsync(stateId, { type: 'state', common: { name: `${name}`, type: `${type}`, role: role, read: read, write: write }, native: {}, });
this.states.push(stateId);
}
await this.setStateAsync(id, value, true);
await this.setStateAsync(stateId, value, true);
}

/**
Expand All @@ -350,6 +353,16 @@ class Jablotron extends utils.Adapter {
return this.states.indexOf(id) >= 0;
}

/**
* Replaces forbidden characters in a name with underscores.
*

Check failure on line 358 in main.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Trailing spaces not allowed
* @param {string} name - The name to be processed.
* @returns {string} - The processed name with forbidden characters replaced by underscores.
*/
name2id (name) {
return name.replace(adapter.FORBIDDEN_CHARS, '_');

Check failure on line 363 in main.js

View workflow job for this annotation

GitHub Actions / check-and-lint

'adapter' is not defined
}

/**
* Is called when adapter shuts down - callback has to be called under any circumstances!
* @param {() => void} callback
Expand Down

0 comments on commit 2d4b32b

Please sign in to comment.