diff --git a/.github/create_templates.ts b/.github/create_templates.ts index 993941c2..1fdee8cc 100644 --- a/.github/create_templates.ts +++ b/.github/create_templates.ts @@ -1,5 +1,5 @@ import { blue, green, red } from "ansi-colors"; -import { execSync, ExecSyncOptions } from "child_process"; +import { ExecSyncOptions, execSync } from "child_process"; import * as fs from "fs-extra"; import * as path from "path"; import { createAdapter } from "../src"; @@ -46,7 +46,6 @@ const adapterAnswers: Answers = { startMode: "daemon", features: ["adapter"], connectionIndicator: "no", - es6class: "yes", type: "general", adminFeatures: ["custom", "tab"], adminUi: "json", diff --git a/CHANGELOG.md b/CHANGELOG.md index cda5da11..a7107e2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * (theknut) Make ioBroker types available in the test directory (#1091) * (theknut) Add `licenseInformation` field to `io-package.json` (#1092) * (AlCalzone) Remove the `subscribe` start mode (#1093) +* (AlCalzone) Remove the legacy way of creating adapters without classes (#1094) ## 2.6.1 (2024-01-15) * (AlCalzone) Fixed an issue with TypeScript tests caused by #1082 (fixes #1084) diff --git a/src/lib/core/questions.ts b/src/lib/core/questions.ts index 8354a4f7..f85593fb 100644 --- a/src/lib/core/questions.ts +++ b/src/lib/core/questions.ts @@ -770,31 +770,6 @@ export const questionGroups: QuestionGroup[] = [ migrate: async (ctx) => (await ctx.analyzeCode('"', "'")) ? "double" : "single", }, - { - condition: { name: "features", contains: "adapter" }, - type: "select", - name: "es6class", - label: "ES6 Class", - expert: true, - message: "How should the main adapter file be structured?", - initial: "yes", - choices: [ - { - message: "As an ES6 class", - hint: "(recommended)", - value: "yes", - }, - { - message: "With some methods", - hint: "(like legacy code)", - value: "no", - }, - ], - migrate: async (ctx) => - (await ctx.getMainFileContent()).match(/^[ \t]*class/gm) - ? "yes" - : "no", - }, ], }, { @@ -1017,7 +992,6 @@ export interface Answers { devServerPort?: number; indentation?: "Tab" | "Space (4)"; quotes?: "single" | "double"; - es6class?: "yes" | "no"; gitRemoteProtocol: "HTTPS" | "SSH"; gitCommit?: "yes" | "no"; defaultBranch?: "main" | "master"; diff --git a/templates/index.ts b/templates/index.ts index 72e5566e..254536a1 100644 --- a/templates/index.ts +++ b/templates/index.ts @@ -68,12 +68,10 @@ const templates: { name: string, templateFunction: TemplateFunction }[] = [ { name: "io-package.json.ts", templateFunction: require("./io-package.json") }, { name: "lib/adapter-config.dts.ts", templateFunction: require("./lib/adapter-config.dts") }, { name: "LICENSE.ts", templateFunction: require("./LICENSE") }, - { name: "main.es6.js.ts", templateFunction: require("./main.es6.js") }, { name: "main.js.ts", templateFunction: require("./main.js") }, { name: "main.test.js.ts", templateFunction: require("./main.test.js") }, { name: "package.json.ts", templateFunction: require("./package.json") }, { name: "README.md.ts", templateFunction: require("./README.md") }, - { name: "src/main.es6.ts", templateFunction: require("./src/main.es6") }, { name: "src/main.test.ts.ts", templateFunction: require("./src/main.test.ts") }, { name: "src/main.ts.ts", templateFunction: require("./src/main.ts") }, { name: "test/_eslintrc.json.ts", templateFunction: require("./test/_eslintrc.json") }, diff --git a/templates/main.es6.js.ts b/templates/main.es6.js.ts deleted file mode 100644 index 8d26f634..00000000 --- a/templates/main.es6.js.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { AdapterSettings, getDefaultAnswer } from "../src/lib/core/questions"; -import type { TemplateFunction } from "../src/lib/createAdapter"; -import { kebabCaseToUpperCamelCase } from "../src/lib/tools"; - -const templateFunction: TemplateFunction = async answers => { - - const useJavaScript = answers.language === "JavaScript"; - const useES6Class = answers.es6class === "yes"; - if (!useJavaScript || !useES6Class) return; - - const className = kebabCaseToUpperCamelCase(answers.adapterName); - const adapterSettings: AdapterSettings[] = answers.adapterSettings || getDefaultAnswer("adapterSettings")!; - const quote = answers.quotes === "double" ? '"' : "'"; - const t = answers.indentation === "Space (4)" ? " " : "\t"; - - const template = ` -"use strict"; - -/* - * Created with @iobroker/create-adapter v${answers.creatorVersion} - */ - -// The adapter-core module gives you access to the core ioBroker functions -// you need to create an adapter -const utils = require("@iobroker/adapter-core"); - -// Load your modules here, e.g.: -// const fs = require("fs"); - -class ${className} extends utils.Adapter { - - /** - * @param {Partial} [options={}] - */ - constructor(options) { - super({ - ...options, - name: "${answers.adapterName}", - }); - this.on("ready", this.onReady.bind(this)); - this.on("stateChange", this.onStateChange.bind(this)); - // this.on(${quote}objectChange${quote}, this.onObjectChange.bind(this)); - // this.on(${quote}message${quote}, this.onMessage.bind(this)); - this.on("unload", this.onUnload.bind(this)); - } - - /** - * Is called when databases are connected and adapter received configuration. - */ - async onReady() { - // Initialize your adapter here - -${answers.connectionIndicator === "yes" ? ` - // Reset the connection indicator during startup - this.setState("info.connection", false, true); -` : ""} - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // this.config: -${adapterSettings.map(s => `\t\tthis.log.info("config ${s.key}: " + this.config.${s.key});`).join("\n")} - - /* - For every state in the system there has to be also an object of type state - Here a simple template for a boolean variable named "testVariable" - Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await this.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - this.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // this.subscribeStates(${quote}lights.*${quote}); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // this.subscribeStates(${quote}*${quote}); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await this.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await this.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - let result = await this.checkPasswordAsync("admin", "iobroker"); - this.log.info("check user admin pw iobroker: " + result); - - result = await this.checkGroupAsync("admin", "admin"); - this.log.info("check group user admin group admin: " + result); - } - - /** - * Is called when adapter shuts down - callback has to be called under any circumstances! - * @param {() => void} callback - */ - onUnload(callback) { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - } - - // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. - // You also need to subscribe to the objects with \`this.subscribeObjects\`, similar to \`this.subscribeStates\`. - // /** - // * Is called if a subscribed object changes - // * @param {string} id - // * @param {ioBroker.Object | null | undefined} obj - // */ - // onObjectChange(id, obj) { - // ${t}if (obj) { - // ${t}${t}// The object was changed - // ${t}${t}this.log.info(\`object \${id} changed: \${JSON.stringify(obj)}\`); - // ${t}} else { - // ${t}${t}// The object was deleted - // ${t}${t}this.log.info(\`object \${id} deleted\`); - // ${t}} - // } - - /** - * Is called if a subscribed state changes - * @param {string} id - * @param {ioBroker.State | null | undefined} state - */ - onStateChange(id, state) { - if (state) { - // The state was changed - this.log.info(\`state \${id} changed: \${state.val} (ack = \${state.ack})\`); - } else { - // The state was deleted - this.log.info(\`state \${id} deleted\`); - } - } - - // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // * @param {ioBroker.Message} obj - // */ - // onMessage(obj) { - // ${t}if (typeof obj === ${quote}object${quote} && obj.message) { - // ${t}${t}if (obj.command === ${quote}send${quote}) { - // ${t}${t}${t}// e.g. send email or pushover or whatever - // ${t}${t}${t}this.log.info(${quote}send command${quote}); - - // ${t}${t}${t}// Send response in callback if required - // ${t}${t}${t}if (obj.callback) this.sendTo(obj.from, obj.command, ${quote}Message received${quote}, obj.callback); - // ${t}${t}} - // ${t}} - // } - -} - -if (require.main !== module) { - // Export the constructor in compact mode - /** - * @param {Partial} [options={}] - */ - module.exports = (options) => new ${className}(options); -} else { - // otherwise start the instance directly - new ${className}(); -} -`; - return template.trim(); -}; -templateFunction.customPath = "main.js"; -export = templateFunction; diff --git a/templates/main.js.ts b/templates/main.js.ts index 7ee73541..57d951f0 100644 --- a/templates/main.js.ts +++ b/templates/main.js.ts @@ -1,12 +1,13 @@ import { AdapterSettings, getDefaultAnswer } from "../src/lib/core/questions"; import type { TemplateFunction } from "../src/lib/createAdapter"; +import { kebabCaseToUpperCamelCase } from "../src/lib/tools"; -export = (async answers => { +const templateFunction: TemplateFunction = async answers => { const useJavaScript = answers.language === "JavaScript"; - const useES6Class = answers.es6class === "yes"; - if (!useJavaScript || useES6Class) return; + if (!useJavaScript) return; + const className = kebabCaseToUpperCamelCase(answers.adapterName); const adapterSettings: AdapterSettings[] = answers.adapterSettings || getDefaultAnswer("adapterSettings")!; const quote = answers.quotes === "double" ? '"' : "'"; const t = answers.indentation === "Space (4)" ? " " : "\t"; @@ -25,148 +26,166 @@ const utils = require("@iobroker/adapter-core"); // Load your modules here, e.g.: // const fs = require("fs"); -/** - * The adapter instance - * @type {ioBroker.Adapter} - */ -let adapter; - -/** - * Starts the adapter instance - * @param {Partial} [options] - */ -function startAdapter(options) { - // Create the adapter and define its methods - return adapter = utils.adapter(Object.assign({}, options, { - name: "${answers.adapterName}", - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with \`adapter.subscribeObjects\`, similar to \`adapter.subscribeStates\`. - // objectChange: (id, obj) => { - // ${t}if (obj) { - // ${t}${t}// The object was changed - // ${t}${t}adapter.log.info(\`object \$\{id} changed: \$\{JSON.stringify(obj)}\`); - // ${t}} else { - // ${t}${t}// The object was deleted - // ${t}${t}adapter.log.info(\`object \$\{id} deleted\`); - // ${t}} - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(\`state \$\{id} changed: \$\{state.val} (ack = \$\{state.ack})\`); - } else { - // The state was deleted - adapter.log.info(\`state \$\{id} deleted\`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // ${t}if (typeof obj === ${quote}object${quote} && obj.message) { - // ${t}${t}if (obj.command === ${quote}send${quote}) { - // ${t}${t}${t}// e.g. send email or pushover or whatever - // ${t}${t}${t}adapter.log.info(${quote}send command${quote}); - - // ${t}${t}${t}// Send response in callback if required - // ${t}${t}${t}if (obj.callback) adapter.sendTo(obj.from, obj.command, ${quote}Message received${quote}, obj.callback); - // ${t}${t}} - // ${t}} - // }, - })); -} - -async function main() { +class ${className} extends utils.Adapter { + + /** + * @param {Partial} [options={}] + */ + constructor(options) { + super({ + ...options, + name: "${answers.adapterName}", + }); + this.on("ready", this.onReady.bind(this)); + this.on("stateChange", this.onStateChange.bind(this)); + // this.on(${quote}objectChange${quote}, this.onObjectChange.bind(this)); + // this.on(${quote}message${quote}, this.onMessage.bind(this)); + this.on("unload", this.onUnload.bind(this)); + } + + /** + * Is called when databases are connected and adapter received configuration. + */ + async onReady() { + // Initialize your adapter here ${answers.connectionIndicator === "yes" ? ` - // Reset the connection indicator during startup - await adapter.setStateAsync("info.connection", false, true); + // Reset the connection indicator during startup + this.setState("info.connection", false, true); ` : ""} - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: -${adapterSettings.map(s => `\tadapter.log.info("config ${s.key}: " + adapter.config.${s.key});`).join("\n")} + // The adapters config (in the instance object everything under the attribute "native") is accessible via + // this.config: +${adapterSettings.map(s => `\t\tthis.log.info("config ${s.key}: " + this.config.${s.key});`).join("\n")} - /* + /* For every state in the system there has to be also an object of type state Here a simple template for a boolean variable named "testVariable" Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates(${quote}lights.*${quote}); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates(${quote}*${quote}); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword("admin", "iobroker", (res) => { - adapter.log.info("check user admin pw iobroker: " + res); - }); - - adapter.checkGroup("admin", "admin", (res) => { - adapter.log.info("check group user admin group admin: " + res); - }); + */ + await this.setObjectNotExistsAsync("testVariable", { + type: "state", + common: { + name: "testVariable", + type: "boolean", + role: "indicator", + read: true, + write: true, + }, + native: {}, + }); + + // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. + this.subscribeStates("testVariable"); + // You can also add a subscription for multiple states. The following line watches all states starting with "lights." + // this.subscribeStates(${quote}lights.*${quote}); + // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: + // this.subscribeStates(${quote}*${quote}); + + /* + setState examples + you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) + */ + // the variable testVariable is set to true as command (ack=false) + await this.setStateAsync("testVariable", true); + + // same thing, but the value is flagged "ack" + // ack should be always set to true if the value is received from or acknowledged from the target system + await this.setStateAsync("testVariable", { val: true, ack: true }); + + // same thing, but the state is deleted after 30s (getState will return null afterwards) + await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); + + // examples for the checkPassword/checkGroup functions + let result = await this.checkPasswordAsync("admin", "iobroker"); + this.log.info("check user admin pw iobroker: " + result); + + result = await this.checkGroupAsync("admin", "admin"); + this.log.info("check group user admin group admin: " + result); + } + + /** + * Is called when adapter shuts down - callback has to be called under any circumstances! + * @param {() => void} callback + */ + onUnload(callback) { + try { + // Here you must clear all timeouts or intervals that may still be active + // clearTimeout(timeout1); + // clearTimeout(timeout2); + // ... + // clearInterval(interval1); + + callback(); + } catch (e) { + callback(); + } + } + + // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. + // You also need to subscribe to the objects with \`this.subscribeObjects\`, similar to \`this.subscribeStates\`. + // /** + // * Is called if a subscribed object changes + // * @param {string} id + // * @param {ioBroker.Object | null | undefined} obj + // */ + // onObjectChange(id, obj) { + // ${t}if (obj) { + // ${t}${t}// The object was changed + // ${t}${t}this.log.info(\`object \${id} changed: \${JSON.stringify(obj)}\`); + // ${t}} else { + // ${t}${t}// The object was deleted + // ${t}${t}this.log.info(\`object \${id} deleted\`); + // ${t}} + // } + + /** + * Is called if a subscribed state changes + * @param {string} id + * @param {ioBroker.State | null | undefined} state + */ + onStateChange(id, state) { + if (state) { + // The state was changed + this.log.info(\`state \${id} changed: \${state.val} (ack = \${state.ack})\`); + } else { + // The state was deleted + this.log.info(\`state \${id} deleted\`); + } + } + + // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. + // /** + // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... + // * Using this method requires "common.messagebox" property to be set to true in io-package.json + // * @param {ioBroker.Message} obj + // */ + // onMessage(obj) { + // ${t}if (typeof obj === ${quote}object${quote} && obj.message) { + // ${t}${t}if (obj.command === ${quote}send${quote}) { + // ${t}${t}${t}// e.g. send email or pushover or whatever + // ${t}${t}${t}this.log.info(${quote}send command${quote}); + + // ${t}${t}${t}// Send response in callback if required + // ${t}${t}${t}if (obj.callback) this.sendTo(obj.from, obj.command, ${quote}Message received${quote}, obj.callback); + // ${t}${t}} + // ${t}} + // } + } if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; + // Export the constructor in compact mode + /** + * @param {Partial} [options={}] + */ + module.exports = (options) => new ${className}(options); } else { // otherwise start the instance directly - startAdapter(); + new ${className}(); } `; return template.trim(); -}) as TemplateFunction; +}; +templateFunction.customPath = "main.js"; +export = templateFunction; diff --git a/templates/src/main.es6.ts b/templates/src/main.es6.ts deleted file mode 100644 index b2851df0..00000000 --- a/templates/src/main.es6.ts +++ /dev/null @@ -1,179 +0,0 @@ -import { AdapterSettings, getDefaultAnswer } from "../../src/lib/core/questions"; -import type { TemplateFunction } from "../../src/lib/createAdapter"; -import { kebabCaseToUpperCamelCase } from "../../src/lib/tools"; - -const templateFunction: TemplateFunction = async answers => { - - const useTypeScript = answers.language === "TypeScript"; - const useES6Class = answers.es6class === "yes"; - if (!useTypeScript || !useES6Class) return; - - const className = kebabCaseToUpperCamelCase(answers.adapterName); - const adapterSettings: AdapterSettings[] = answers.adapterSettings || getDefaultAnswer("adapterSettings")!; - const quote = answers.quotes === "double" ? '"' : "'"; - const t = answers.indentation === "Space (4)" ? " " : "\t"; - - const template = ` -/* - * Created with @iobroker/create-adapter v${answers.creatorVersion} - */ - -// The adapter-core module gives you access to the core ioBroker functions -// you need to create an adapter -import * as utils from "@iobroker/adapter-core"; - -// Load your modules here, e.g.: -// import * as fs from "fs"; - -class ${className} extends utils.Adapter { - - public constructor(options: Partial = {}) { - super({ - ...options, - name: "${answers.adapterName}", - }); - this.on("ready", this.onReady.bind(this)); - this.on("stateChange", this.onStateChange.bind(this)); - // this.on(${quote}objectChange${quote}, this.onObjectChange.bind(this)); - // this.on(${quote}message${quote}, this.onMessage.bind(this)); - this.on("unload", this.onUnload.bind(this)); - } - - /** - * Is called when databases are connected and adapter received configuration. - */ - private async onReady(): Promise { - // Initialize your adapter here - - -${answers.connectionIndicator === "yes" ? ` - // Reset the connection indicator during startup - this.setState("info.connection", false, true); -` : ""} - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // this.config: -${adapterSettings.map(s => `\t\tthis.log.info("config ${s.key}: " + this.config.${s.key});`).join("\n")} - - /* - For every state in the system there has to be also an object of type state - Here a simple template for a boolean variable named "testVariable" - Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await this.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - this.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // this.subscribeStates(${quote}lights.*${quote}); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // this.subscribeStates(${quote}*${quote}); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await this.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await this.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - let result = await this.checkPasswordAsync("admin", "iobroker"); - this.log.info("check user admin pw iobroker: " + result); - - result = await this.checkGroupAsync("admin", "admin"); - this.log.info("check group user admin group admin: " + result); - } - - /** - * Is called when adapter shuts down - callback has to be called under any circumstances! - */ - private onUnload(callback: () => void): void { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - } - - // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. - // You also need to subscribe to the objects with \`this.subscribeObjects\`, similar to \`this.subscribeStates\`. - // /** - // * Is called if a subscribed object changes - // */ - // private onObjectChange(id: string, obj: ioBroker.Object | null | undefined): void { - // ${t}if (obj) { - // ${t}${t}// The object was changed - // ${t}${t}this.log.info(\`object \${id} changed: \${JSON.stringify(obj)}\`); - // ${t}} else { - // ${t}${t}// The object was deleted - // ${t}${t}this.log.info(\`object \${id} deleted\`); - // ${t}} - // } - - /** - * Is called if a subscribed state changes - */ - private onStateChange(id: string, state: ioBroker.State | null | undefined): void { - if (state) { - // The state was changed - this.log.info(\`state \${id} changed: \${state.val} (ack = \${state.ack})\`); - } else { - // The state was deleted - this.log.info(\`state \${id} deleted\`); - } - } - - // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // private onMessage(obj: ioBroker.Message): void { - // ${t}if (typeof obj === ${quote}object${quote} && obj.message) { - // ${t}${t}if (obj.command === ${quote}send${quote}) { - // ${t}${t}${t}// e.g. send email or pushover or whatever - // ${t}${t}${t}this.log.info(${quote}send command${quote}); - - // ${t}${t}${t}// Send response in callback if required - // ${t}${t}${t}if (obj.callback) this.sendTo(obj.from, obj.command, ${quote}Message received${quote}, obj.callback); - // ${t}${t}} - // ${t}} - // } - -} - -if (require.main !== module) { - // Export the constructor in compact mode - module.exports = (options: Partial | undefined) => new ${className}(options); -} else { - // otherwise start the instance directly - (() => new ${className}())(); -} -`; - return template.trim(); -}; -templateFunction.customPath = "src/main.ts"; -export = templateFunction; diff --git a/templates/src/main.ts.ts b/templates/src/main.ts.ts index 498e2fa9..490564ac 100644 --- a/templates/src/main.ts.ts +++ b/templates/src/main.ts.ts @@ -1,12 +1,13 @@ import { AdapterSettings, getDefaultAnswer } from "../../src/lib/core/questions"; import type { TemplateFunction } from "../../src/lib/createAdapter"; +import { kebabCaseToUpperCamelCase } from "../../src/lib/tools"; -export = (answers => { +const templateFunction: TemplateFunction = async answers => { const useTypeScript = answers.language === "TypeScript"; - const useES6Class = answers.es6class === "yes"; - if (!useTypeScript || useES6Class) return; + if (!useTypeScript) return; + const className = kebabCaseToUpperCamelCase(answers.adapterName); const adapterSettings: AdapterSettings[] = answers.adapterSettings || getDefaultAnswer("adapterSettings")!; const quote = answers.quotes === "double" ? '"' : "'"; const t = answers.indentation === "Space (4)" ? " " : "\t"; @@ -23,146 +24,155 @@ import * as utils from "@iobroker/adapter-core"; // Load your modules here, e.g.: // import * as fs from "fs"; -let adapter: ioBroker.Adapter; +class ${className} extends utils.Adapter { -/** - * Starts the adapter instance - */ -function startAdapter(options: Partial = {}): ioBroker.Adapter { - // Create the adapter and define its methods - return adapter = utils.adapter({ - // Default options - ...options, - // custom options - name: "${answers.adapterName}", - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with \`adapter.subscribeObjects\`, similar to \`adapter.subscribeStates\`. - // objectChange: (id, obj) => { - // ${t}if (obj) { - // ${t}${t}// The object was changed - // ${t}${t}adapter.log.info(\`object \$\{id} changed: \$\{JSON.stringify(obj)}\`); - // ${t}} else { - // ${t}${t}// The object was deleted - // ${t}${t}adapter.log.info(\`object \$\{id} deleted\`); - // ${t}} - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(\`state \$\{id} changed: \$\{state.val} (ack = \$\{state.ack})\`); - } else { - // The state was deleted - adapter.log.info(\`state \$\{id} deleted\`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // ${t}if (typeof obj === ${quote}object${quote} && obj.message) { - // ${t}${t}if (obj.command === ${quote}send${quote}) { - // ${t}${t}${t}// e.g. send email or pushover or whatever - // ${t}${t}${t}adapter.log.info(${quote}send command${quote}); - - // ${t}${t}${t}// Send response in callback if required - // ${t}${t}${t}if (obj.callback) adapter.sendTo(obj.from, obj.command, ${quote}Message received${quote}, obj.callback); - // ${t}${t}} - // ${t}} - // }, - }); -} + public constructor(options: Partial = {}) { + super({ + ...options, + name: "${answers.adapterName}", + }); + this.on("ready", this.onReady.bind(this)); + this.on("stateChange", this.onStateChange.bind(this)); + // this.on(${quote}objectChange${quote}, this.onObjectChange.bind(this)); + // this.on(${quote}message${quote}, this.onMessage.bind(this)); + this.on("unload", this.onUnload.bind(this)); + } + + /** + * Is called when databases are connected and adapter received configuration. + */ + private async onReady(): Promise { + // Initialize your adapter here -async function main(): Promise { ${answers.connectionIndicator === "yes" ? ` - // Reset the connection indicator during startup - await this.setStateAsync("info.connection", false, true); + // Reset the connection indicator during startup + this.setState("info.connection", false, true); ` : ""} - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: -${adapterSettings.map(s => `\tadapter.log.info("config ${s.key}: " + adapter.config.${s.key});`).join("\n")} + // The adapters config (in the instance object everything under the attribute "native") is accessible via + // this.config: +${adapterSettings.map(s => `\t\tthis.log.info("config ${s.key}: " + this.config.${s.key});`).join("\n")} - /* + /* For every state in the system there has to be also an object of type state Here a simple template for a boolean variable named "testVariable" Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates(${quote}lights.*${quote}); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates(${quote}*${quote}); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword("admin", "iobroker", (res) => { - adapter.log.info("check user admin pw iobroker: " + res); - }); - - adapter.checkGroup("admin", "admin", (res) => { - adapter.log.info("check group user admin group admin: " + res); - }); + */ + await this.setObjectNotExistsAsync("testVariable", { + type: "state", + common: { + name: "testVariable", + type: "boolean", + role: "indicator", + read: true, + write: true, + }, + native: {}, + }); + + // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. + this.subscribeStates("testVariable"); + // You can also add a subscription for multiple states. The following line watches all states starting with "lights." + // this.subscribeStates(${quote}lights.*${quote}); + // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: + // this.subscribeStates(${quote}*${quote}); + + /* + setState examples + you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) + */ + // the variable testVariable is set to true as command (ack=false) + await this.setStateAsync("testVariable", true); + + // same thing, but the value is flagged "ack" + // ack should be always set to true if the value is received from or acknowledged from the target system + await this.setStateAsync("testVariable", { val: true, ack: true }); + + // same thing, but the state is deleted after 30s (getState will return null afterwards) + await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); + + // examples for the checkPassword/checkGroup functions + let result = await this.checkPasswordAsync("admin", "iobroker"); + this.log.info("check user admin pw iobroker: " + result); + + result = await this.checkGroupAsync("admin", "admin"); + this.log.info("check group user admin group admin: " + result); + } + + /** + * Is called when adapter shuts down - callback has to be called under any circumstances! + */ + private onUnload(callback: () => void): void { + try { + // Here you must clear all timeouts or intervals that may still be active + // clearTimeout(timeout1); + // clearTimeout(timeout2); + // ... + // clearInterval(interval1); + + callback(); + } catch (e) { + callback(); + } + } + + // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. + // You also need to subscribe to the objects with \`this.subscribeObjects\`, similar to \`this.subscribeStates\`. + // /** + // * Is called if a subscribed object changes + // */ + // private onObjectChange(id: string, obj: ioBroker.Object | null | undefined): void { + // ${t}if (obj) { + // ${t}${t}// The object was changed + // ${t}${t}this.log.info(\`object \${id} changed: \${JSON.stringify(obj)}\`); + // ${t}} else { + // ${t}${t}// The object was deleted + // ${t}${t}this.log.info(\`object \${id} deleted\`); + // ${t}} + // } + + /** + * Is called if a subscribed state changes + */ + private onStateChange(id: string, state: ioBroker.State | null | undefined): void { + if (state) { + // The state was changed + this.log.info(\`state \${id} changed: \${state.val} (ack = \${state.ack})\`); + } else { + // The state was deleted + this.log.info(\`state \${id} deleted\`); + } + } + + // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. + // /** + // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... + // * Using this method requires "common.messagebox" property to be set to true in io-package.json + // */ + // private onMessage(obj: ioBroker.Message): void { + // ${t}if (typeof obj === ${quote}object${quote} && obj.message) { + // ${t}${t}if (obj.command === ${quote}send${quote}) { + // ${t}${t}${t}// e.g. send email or pushover or whatever + // ${t}${t}${t}this.log.info(${quote}send command${quote}); + + // ${t}${t}${t}// Send response in callback if required + // ${t}${t}${t}if (obj.callback) this.sendTo(obj.from, obj.command, ${quote}Message received${quote}, obj.callback); + // ${t}${t}} + // ${t}} + // } + } if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; + // Export the constructor in compact mode + module.exports = (options: Partial | undefined) => new ${className}(options); } else { // otherwise start the instance directly - startAdapter(); + (() => new ${className}())(); } `; return template.trim(); -}) as TemplateFunction; +}; + +export = templateFunction; diff --git a/test/baselines/JS_LegacyMain/main.js b/test/baselines/JS_LegacyMain/main.js deleted file mode 100644 index 985e2105..00000000 --- a/test/baselines/JS_LegacyMain/main.js +++ /dev/null @@ -1,154 +0,0 @@ -"use strict"; - -/* - * Created with @iobroker/create-adapter v2.6.1 - */ - -// The adapter-core module gives you access to the core ioBroker functions -// you need to create an adapter -const utils = require("@iobroker/adapter-core"); - -// Load your modules here, e.g.: -// const fs = require("fs"); - -/** - * The adapter instance - * @type {ioBroker.Adapter} - */ -let adapter; - -/** - * Starts the adapter instance - * @param {Partial} [options] - */ -function startAdapter(options) { - // Create the adapter and define its methods - return adapter = utils.adapter(Object.assign({}, options, { - name: "test-adapter", - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with `adapter.subscribeObjects`, similar to `adapter.subscribeStates`. - // objectChange: (id, obj) => { - // if (obj) { - // // The object was changed - // adapter.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // adapter.log.info(`object ${id} deleted`); - // } - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - adapter.log.info(`state ${id} deleted`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // if (typeof obj === "object" && obj.message) { - // if (obj.command === "send") { - // // e.g. send email or pushover or whatever - // adapter.log.info("send command"); - - // // Send response in callback if required - // if (obj.callback) adapter.sendTo(obj.from, obj.command, "Message received", obj.callback); - // } - // } - // }, - })); -} - -async function main() { - - // Reset the connection indicator during startup - await adapter.setStateAsync("info.connection", false, true); - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: - adapter.log.info("config option1: " + adapter.config.option1); - adapter.log.info("config option2: " + adapter.config.option2); - - /* - For every state in the system there has to be also an object of type state - Here a simple template for a boolean variable named "testVariable" - Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates("lights.*"); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates("*"); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword("admin", "iobroker", (res) => { - adapter.log.info("check user admin pw iobroker: " + res); - }); - - adapter.checkGroup("admin", "admin", (res) => { - adapter.log.info("check group user admin group admin: " + res); - }); -} - -if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; -} else { - // otherwise start the instance directly - startAdapter(); -} \ No newline at end of file diff --git a/test/baselines/TS_SingleQuotes/src/main.ts b/test/baselines/TS_SingleQuotes/src/main.ts index 08f86a79..efe8ebce 100644 --- a/test/baselines/TS_SingleQuotes/src/main.ts +++ b/test/baselines/TS_SingleQuotes/src/main.ts @@ -9,139 +9,145 @@ import * as utils from '@iobroker/adapter-core'; // Load your modules here, e.g.: // import * as fs from "fs"; -let adapter: ioBroker.Adapter; - -/** - * Starts the adapter instance - */ -function startAdapter(options: Partial = {}): ioBroker.Adapter { - // Create the adapter and define its methods - return adapter = utils.adapter({ - // Default options - ...options, - // custom options - name: 'test-adapter', - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with `adapter.subscribeObjects`, similar to `adapter.subscribeStates`. - // objectChange: (id, obj) => { - // if (obj) { - // // The object was changed - // adapter.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // adapter.log.info(`object ${id} deleted`); - // } - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - adapter.log.info(`state ${id} deleted`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // if (typeof obj === 'object' && obj.message) { - // if (obj.command === 'send') { - // // e.g. send email or pushover or whatever - // adapter.log.info('send command'); - - // // Send response in callback if required - // if (obj.callback) adapter.sendTo(obj.from, obj.command, 'Message received', obj.callback); - // } - // } - // }, - }); -} - -async function main(): Promise { - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: - adapter.log.info('config option1: ' + adapter.config.option1); - adapter.log.info('config option2: ' + adapter.config.option2); - - /* +class TestAdapter extends utils.Adapter { + + public constructor(options: Partial = {}) { + super({ + ...options, + name: 'test-adapter', + }); + this.on('ready', this.onReady.bind(this)); + this.on('stateChange', this.onStateChange.bind(this)); + // this.on('objectChange', this.onObjectChange.bind(this)); + // this.on('message', this.onMessage.bind(this)); + this.on('unload', this.onUnload.bind(this)); + } + + /** + * Is called when databases are connected and adapter received configuration. + */ + private async onReady(): Promise { + // Initialize your adapter here + + // The adapters config (in the instance object everything under the attribute "native") is accessible via + // this.config: + this.log.info('config option1: ' + this.config.option1); + this.log.info('config option2: ' + this.config.option2); + + /* For every state in the system there has to be also an object of type state Here a simple template for a boolean variable named "testVariable" Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync('testVariable', { - type: 'state', - common: { - name: 'testVariable', - type: 'boolean', - role: 'indicator', - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates('testVariable'); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates('lights.*'); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates('*'); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync('testVariable', true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync('testVariable', { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync('testVariable', { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword('admin', 'iobroker', (res) => { - adapter.log.info('check user admin pw iobroker: ' + res); - }); - - adapter.checkGroup('admin', 'admin', (res) => { - adapter.log.info('check group user admin group admin: ' + res); - }); + */ + await this.setObjectNotExistsAsync('testVariable', { + type: 'state', + common: { + name: 'testVariable', + type: 'boolean', + role: 'indicator', + read: true, + write: true, + }, + native: {}, + }); + + // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. + this.subscribeStates('testVariable'); + // You can also add a subscription for multiple states. The following line watches all states starting with "lights." + // this.subscribeStates('lights.*'); + // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: + // this.subscribeStates('*'); + + /* + setState examples + you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) + */ + // the variable testVariable is set to true as command (ack=false) + await this.setStateAsync('testVariable', true); + + // same thing, but the value is flagged "ack" + // ack should be always set to true if the value is received from or acknowledged from the target system + await this.setStateAsync('testVariable', { val: true, ack: true }); + + // same thing, but the state is deleted after 30s (getState will return null afterwards) + await this.setStateAsync('testVariable', { val: true, ack: true, expire: 30 }); + + // examples for the checkPassword/checkGroup functions + let result = await this.checkPasswordAsync('admin', 'iobroker'); + this.log.info('check user admin pw iobroker: ' + result); + + result = await this.checkGroupAsync('admin', 'admin'); + this.log.info('check group user admin group admin: ' + result); + } + + /** + * Is called when adapter shuts down - callback has to be called under any circumstances! + */ + private onUnload(callback: () => void): void { + try { + // Here you must clear all timeouts or intervals that may still be active + // clearTimeout(timeout1); + // clearTimeout(timeout2); + // ... + // clearInterval(interval1); + + callback(); + } catch (e) { + callback(); + } + } + + // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. + // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. + // /** + // * Is called if a subscribed object changes + // */ + // private onObjectChange(id: string, obj: ioBroker.Object | null | undefined): void { + // if (obj) { + // // The object was changed + // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); + // } else { + // // The object was deleted + // this.log.info(`object ${id} deleted`); + // } + // } + + /** + * Is called if a subscribed state changes + */ + private onStateChange(id: string, state: ioBroker.State | null | undefined): void { + if (state) { + // The state was changed + this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); + } else { + // The state was deleted + this.log.info(`state ${id} deleted`); + } + } + + // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. + // /** + // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... + // * Using this method requires "common.messagebox" property to be set to true in io-package.json + // */ + // private onMessage(obj: ioBroker.Message): void { + // if (typeof obj === 'object' && obj.message) { + // if (obj.command === 'send') { + // // e.g. send email or pushover or whatever + // this.log.info('send command'); + + // // Send response in callback if required + // if (obj.callback) this.sendTo(obj.from, obj.command, 'Message received', obj.callback); + // } + // } + // } + } if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; + // Export the constructor in compact mode + module.exports = (options: Partial | undefined) => new TestAdapter(options); } else { // otherwise start the instance directly - startAdapter(); + (() => new TestAdapter())(); } \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.create-adapter.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.create-adapter.json deleted file mode 100644 index e089adb1..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.create-adapter.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cli": true, - "target": "directory", - "adapterName": "test-adapter", - "title": "Is used to test the creator", - "startMode": "daemon", - "features": [ - "adapter" - ], - "connectionIndicator": "no", - "connectionType": "local", - "dataSource": "push", - "adminFeatures": [], - "type": "general", - "language": "JavaScript", - "adminUi": "html", - "tabReact": "no", - "releaseScript": "no", - "tools": [ - "ESLint", - "type checking" - ], - "indentation": "Space (4)", - "quotes": "single", - "es6class": "yes", - "authorName": "Al Calzone", - "authorGithub": "AlCalzone", - "authorEmail": "al@calzo.ne", - "gitRemoteProtocol": "HTTPS", - "dependabot": "yes", - "gitCommit": "no", - "defaultBranch": "main", - "license": "Apache License 2.0", - "licenseInformation": { - "type": "free", - "license": "Apache-2.0" - }, - "creatorVersion": "2.6.1" -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.eslintignore b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.eslintignore deleted file mode 100644 index 396d8e17..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -**/.eslintrc.js -admin/words.js \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.eslintrc.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.eslintrc.json deleted file mode 100644 index 6e461e9d..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.eslintrc.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "root": true, - "env": { - "es6": true, - "node": true, - "mocha": true - }, - "extends": [ - "eslint:recommended" - ], - "plugins": [], - "rules": { - "indent": [ - "error", - 4, - { - "SwitchCase": 1 - } - ], - "no-console": "off", - "no-unused-vars": [ - "error", - { - "ignoreRestSiblings": true, - "argsIgnorePattern": "^_" - } - ], - "no-var": "error", - "no-trailing-spaces": "error", - "prefer-const": "error", - "quotes": [ - "error", - "single", - { - "avoidEscape": true, - "allowTemplateLiterals": true - } - ], - "semi": [ - "error", - "always" - ] - }, - "parserOptions": { - "ecmaVersion": "latest" - } -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/ISSUE_TEMPLATE/bug_report.md b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 89561395..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Bug report -about: Something is not working as it should -title: '' -labels: '' -assignees: '' ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '...' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots & Logfiles** -If applicable, add screenshots and logfiles to help explain your problem. - -**Versions:** - - Adapter version: - - JS-Controller version: - - Node version: - - Operating system: - -**Additional context** -Add any other context about the problem here. diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/auto-merge.yml b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/auto-merge.yml deleted file mode 100644 index 4f6d185f..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/auto-merge.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Configure here which dependency updates should be merged automatically. -# The recommended configuration is the following: -- match: - # Only merge patches for production dependencies - dependency_type: production - update_type: "semver:patch" -- match: - # Except for security fixes, here we allow minor patches - dependency_type: production - update_type: "security:minor" -- match: - # and development dependencies can have a minor update, too - dependency_type: development - update_type: "semver:minor" - -# The syntax is based on the legacy dependabot v1 automerged_updates syntax, see: -# https://dependabot.com/docs/config-file/#automerged_updates diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/dependabot.yml b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/dependabot.yml deleted file mode 100644 index c165a6a4..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/dependabot.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: 2 -updates: - - package-ecosystem: npm - directory: "/" - schedule: - interval: monthly - time: "04:00" - timezone: Europe/Berlin - open-pull-requests-limit: 5 - assignees: - - AlCalzone - versioning-strategy: increase - - - package-ecosystem: github-actions - directory: "/" - schedule: - interval: monthly - time: "04:00" - timezone: Europe/Berlin - open-pull-requests-limit: 5 - assignees: - - AlCalzone diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/workflows/dependabot-auto-merge.yml b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/workflows/dependabot-auto-merge.yml deleted file mode 100644 index c9b5329b..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/workflows/dependabot-auto-merge.yml +++ /dev/null @@ -1,27 +0,0 @@ -# Automatically merge Dependabot PRs when version comparison is within the range -# that is configured in .github/auto-merge.yml - -name: Auto-Merge Dependabot PRs - -on: - # WARNING: This needs to be run in the PR base, DO NOT build untrusted code in this action - # details under https://github.blog/changelog/2021-02-19-github-actions-workflows-triggered-by-dependabot-prs-will-run-with-read-only-permissions/ - pull_request_target: - -jobs: - auto-merge: - if: github.actor == 'dependabot[bot]' - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Check if PR should be auto-merged - uses: ahmadnassri/action-dependabot-auto-merge@v2 - with: - # In order to use this, you need to go to https://github.com/settings/tokens and - # create a Personal Access Token with the permission "public_repo". - # Enter this token in your repository settings under "Secrets" and name it AUTO_MERGE_TOKEN - github-token: ${{ secrets.AUTO_MERGE_TOKEN }} - # By default, squash and merge, so Github chooses nice commit messages - command: squash and merge diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/workflows/test-and-release.yml b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/workflows/test-and-release.yml deleted file mode 100644 index febfb1ed..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.github/workflows/test-and-release.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Test and Release - -# Run this job on all pushes and pull requests -# as well as tags with a semantic version -on: - push: - branches: - - "main" - tags: - # normal versions - - "v[0-9]+.[0-9]+.[0-9]+" - # pre-releases - - "v[0-9]+.[0-9]+.[0-9]+-**" - pull_request: {} - -# Cancel previous PR/branch runs when a new commit is pushed -concurrency: - group: ${{ github.ref }} - cancel-in-progress: true - -jobs: - # Performs quick checks before the expensive test runs - check-and-lint: - if: contains(github.event.head_commit.message, '[skip ci]') == false - - runs-on: ubuntu-latest - - steps: - - uses: ioBroker/testing-action-check@v1 - with: - node-version: '18.x' - # Uncomment the following line if your adapter cannot be installed using 'npm ci' - # install-command: 'npm install' - lint: true - - # Runs adapter tests on all supported node versions and OSes - adapter-tests: - if: contains(github.event.head_commit.message, '[skip ci]') == false - - runs-on: ${{ matrix.os }} - strategy: - matrix: - node-version: [18.x, 20.x] - os: [ubuntu-latest, windows-latest, macos-latest] - - steps: - - uses: ioBroker/testing-action-adapter@v1 - with: - node-version: ${{ matrix.node-version }} - os: ${{ matrix.os }} - # Uncomment the following line if your adapter cannot be installed using 'npm ci' - # install-command: 'npm install' - -# TODO: To enable automatic npm releases, create a token on npmjs.org -# Enter this token as a GitHub secret (with name NPM_TOKEN) in the repository options -# Then uncomment the following block: - -# # Deploys the final package to NPM -# deploy: -# needs: [check-and-lint, adapter-tests] -# -# # Trigger this step only when a commit on any branch is tagged with a version number -# if: | -# contains(github.event.head_commit.message, '[skip ci]') == false && -# github.event_name == 'push' && -# startsWith(github.ref, 'refs/tags/v') -# -# runs-on: ubuntu-latest -# -# # Write permissions are required to create Github releases -# permissions: -# contents: write -# -# steps: -# - uses: ioBroker/testing-action-deploy@v1 -# with: -# node-version: '18.x' -# # Uncomment the following line if your adapter cannot be installed using 'npm ci' -# # install-command: 'npm install' -# npm-token: ${{ secrets.NPM_TOKEN }} -# github-token: ${{ secrets.GITHUB_TOKEN }} -# -# # When using Sentry for error reporting, Sentry can be informed about new releases -# # To enable create a API-Token in Sentry (User settings, API keys) -# # Enter this token as a GitHub secret (with name SENTRY_AUTH_TOKEN) in the repository options -# # Then uncomment and customize the following block: -# sentry: true -# sentry-token: ${{ secrets.SENTRY_AUTH_TOKEN }} -# sentry-project: "iobroker-test-adapter" -# sentry-version-prefix: "iobroker.test-adapter" -# # If your sentry project is linked to a GitHub repository, you can enable the following option -# # sentry-github-integration: true diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.gitignore b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.gitignore deleted file mode 100644 index 3bf582ba..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# No dot-directories except github/vscode -.*/ -!.vscode/ -!.github/ - -*.code-workspace -node_modules -nbproject - -# npm package files -iobroker.*.tgz - -Thumbs.db - -# i18n intermediate files -admin/i18n/flat.txt -admin/i18n/*/flat.txt \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.vscode/extensions.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.vscode/extensions.json deleted file mode 100644 index 897af65d..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "dbaeumer.vscode-eslint" - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.vscode/settings.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.vscode/settings.json deleted file mode 100644 index 93ae1749..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.vscode/settings.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "eslint.enable": true, - "json.schemas": [ - { - "fileMatch": [ - "io-package.json" - ], - "url": "https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/schemas/io-package.json" - }, - { - "fileMatch": [ - "admin/jsonConfig.json", - "admin/jsonCustom.json", - "admin/jsonTab.json" - ], - "url": "https://raw.githubusercontent.com/ioBroker/adapter-react-v5/main/schemas/jsonConfig.json" - } - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/LICENSE b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/LICENSE deleted file mode 100644 index 8f1225dd..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2024 Al Calzone - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/README.md b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/README.md deleted file mode 100644 index 95e8c899..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/README.md +++ /dev/null @@ -1,305 +0,0 @@ -![Logo](admin/test-adapter.png) -# ioBroker.test-adapter - -[![NPM version](https://img.shields.io/npm/v/iobroker.test-adapter.svg)](https://www.npmjs.com/package/iobroker.test-adapter) -[![Downloads](https://img.shields.io/npm/dm/iobroker.test-adapter.svg)](https://www.npmjs.com/package/iobroker.test-adapter) -![Number of Installations](https://iobroker.live/badges/test-adapter-installed.svg) -![Current version in stable repository](https://iobroker.live/badges/test-adapter-stable.svg) - -[![NPM](https://nodei.co/npm/iobroker.test-adapter.png?downloads=true)](https://nodei.co/npm/iobroker.test-adapter/) - -**Tests:** ![Test and Release](https://github.com/AlCalzone/ioBroker.test-adapter/workflows/Test%20and%20Release/badge.svg) - -## test-adapter adapter for ioBroker - -Describe your project here - -## Developer manual -This section is intended for the developer. It can be deleted later. - -### DISCLAIMER - -Please make sure that you consider copyrights and trademarks when you use names or logos of a company and add a disclaimer to your README. -You can check other adapters for examples or ask in the developer community. Using a name or logo of a company without permission may cause legal problems for you. - -### Getting started - -You are almost done, only a few steps left: -1. Create a new repository on GitHub with the name `ioBroker.test-adapter` -1. Initialize the current folder as a new git repository: - ```bash - git init -b main - git add . - git commit -m "Initial commit" - ``` -1. Link your local repository with the one on GitHub: - ```bash - git remote add origin https://github.com/AlCalzone/ioBroker.test-adapter - ``` - -1. Push all files to the GitHub repo: - ```bash - git push origin main - ``` -1. Add a new secret under https://github.com/AlCalzone/ioBroker.test-adapter/settings/secrets. It must be named `AUTO_MERGE_TOKEN` and contain a personal access token with push access to the repository, e.g. yours. You can create a new token under https://github.com/settings/tokens. - -1. Head over to [main.js](main.js) and start programming! - -### Best Practices -We've collected some [best practices](https://github.com/ioBroker/ioBroker.repositories#development-and-coding-best-practices) regarding ioBroker development and coding in general. If you're new to ioBroker or Node.js, you should -check them out. If you're already experienced, you should also take a look at them - you might learn something new :) - -### Scripts in `package.json` -Several npm scripts are predefined for your convenience. You can run them using `npm run ` -| Script name | Description | -|-------------|-------------| -| `test:js` | Executes the tests you defined in `*.test.js` files. | -| `test:package` | Ensures your `package.json` and `io-package.json` are valid. | -| `test:integration` | Tests the adapter startup with an actual instance of ioBroker. | -| `test` | Performs a minimal test run on package files and your tests. | -| `check` | Performs a type-check on your code (without compiling anything). | -| `lint` | Runs `ESLint` to check your code for formatting errors and potential bugs. | -| `translate` | Translates texts in your adapter to all required languages, see [`@iobroker/adapter-dev`](https://github.com/ioBroker/adapter-dev#manage-translations) for more details. | - -### Writing tests -When done right, testing code is invaluable, because it gives you the -confidence to change your code while knowing exactly if and when -something breaks. A good read on the topic of test-driven development -is https://hackernoon.com/introduction-to-test-driven-development-tdd-61a13bc92d92. -Although writing tests before the code might seem strange at first, but it has very -clear upsides. - -The template provides you with basic tests for the adapter startup and package files. -It is recommended that you add your own tests into the mix. - -### Publishing the adapter -Using GitHub Actions, you can enable automatic releases on npm whenever you push a new git tag that matches the form -`v..`. We **strongly recommend** that you do. The necessary steps are described in `.github/workflows/test-and-release.yml`. - -To get your adapter released in ioBroker, please refer to the documentation -of [ioBroker.repositories](https://github.com/ioBroker/ioBroker.repositories#requirements-for-adapter-to-get-added-to-the-latest-repository). - -### Test the adapter manually on a local ioBroker installation -In order to install the adapter locally without publishing, the following steps are recommended: -1. Create a tarball from your dev directory: - ```bash - npm pack - ``` -1. Upload the resulting file to your ioBroker host -1. Install it locally (The paths are different on Windows): - ```bash - cd /opt/iobroker - npm i /path/to/tarball.tgz - ``` - -For later updates, the above procedure is not necessary. Just do the following: -1. Overwrite the changed files in the adapter directory (`/opt/iobroker/node_modules/iobroker.test-adapter`) -1. Execute `iobroker upload test-adapter` on the ioBroker host - -## Changelog - -### 0.0.1 -* (Al Calzone) initial release - -## License - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2024 Al Calzone - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/__meta__/npm_package_files.txt b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/__meta__/npm_package_files.txt deleted file mode 100644 index 23b05f26..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/__meta__/npm_package_files.txt +++ /dev/null @@ -1,10 +0,0 @@ -admin/index_m.html -admin/style.css -admin/test-adapter.png -admin/words.js -lib/adapter-config.d.ts -io-package.json -LICENSE -main.js -package.json -README.md \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/admin.d.ts b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/admin.d.ts deleted file mode 100644 index e36c5c46..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/admin.d.ts +++ /dev/null @@ -1,93 +0,0 @@ -declare let systemDictionary: Record>; - -declare let load: (settings: Record, onChange: (hasChanges: boolean) => void) => void; -declare let save: (callback: (settings: Record) => void) => void; - -// make load and save exist on the window object -interface Window { - load: typeof load; - save: typeof save; -} - -declare const instance: number; -declare const adapter: string; -/** Translates text */ -declare function _(text: string, arg1?: string, arg2?: string, arg3?: string): string; -declare const socket: ioBrokerSocket; -declare function sendTo( - instance: any | null, - command: string, - message: any, - callback: (result: SendToResult) => void | Promise, -): void; - -interface SendToResult { - error?: string | Error; - result?: any; -} - -// tslint:disable-next-line:class-name -interface ioBrokerSocket { - emit( - command: 'subscribeObjects', - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - emit( - command: 'subscribeStates', - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - emit( - command: 'unsubscribeObjects', - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - emit( - command: 'unsubscribeStates', - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - - emit( - event: 'getObjectView', - view: 'system', - type: 'device', - options: ioBroker.GetObjectViewParams, - callback: ( - err: string | undefined, - result?: any, - ) => void | Promise, - ): void; - emit( - event: 'getStates', - callback: ( - err: string | undefined, - result?: Record, - ) => void, - ): void; - emit( - event: 'getState', - id: string, - callback: (err: string | undefined, result?: ioBroker.State) => void, - ): void; - emit( - event: 'setState', - id: string, - state: unknown, - callback: (err: string | undefined, result?: any) => void, - ): void; - - on(event: 'objectChange', handler: ioBroker.ObjectChangeHandler): void; - on(event: 'stateChange', handler: ioBroker.StateChangeHandler): void; - removeEventHandler( - event: 'objectChange', - handler: ioBroker.ObjectChangeHandler, - ): void; - removeEventHandler( - event: 'stateChange', - handler: ioBroker.StateChangeHandler, - ): void; - - // TODO: other events -} diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/index_m.html b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/index_m.html deleted file mode 100644 index ad15ac8c..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/index_m.html +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- -
-
- - - - -
-
- - -
- -
- - -
-
- -
- - - - \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/style.css b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/style.css deleted file mode 100644 index a56351f0..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/style.css +++ /dev/null @@ -1,32 +0,0 @@ -/* You can delete those if you want. I just found them very helpful */ -* { - box-sizing: border-box -} -.m { - /* Don't cut off dropdowns! */ - overflow: initial; -} -.m.adapter-container, -.m.adapter-container > div.App { - /* Fix layout/scrolling issues with tabs */ - height: 100%; - width: 100%; - position: relative; -} -.m .select-wrapper + label { - /* The positioning for dropdown labels is messed up */ - transform: none !important; -} - -label > i[title] { - /* Display the help cursor for the tooltip icons and fix their positioning */ - cursor: help; - margin-left: 0.25em; -} - -.dropdown-content { - /* Don't wrap text in dropdowns */ - white-space: nowrap; -} - -/* Add your styles here */ diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/test-adapter.png b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/test-adapter.png deleted file mode 100644 index 094ebd97..00000000 Binary files a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/test-adapter.png and /dev/null differ diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/tsconfig.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/tsconfig.json deleted file mode 100644 index e3356ce9..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../tsconfig.json", - "include": [ - "./admin.d.ts", - "./**/*.js", - // Include the adapter-config definition if it exists. - // It should be at either on of these paths: - "../lib/adapter-config.d.ts", // JS - "../src/lib/adapter-config.d.ts", // TS - ] -} diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/words.js b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/words.js deleted file mode 100644 index adcc82d0..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/admin/words.js +++ /dev/null @@ -1,46 +0,0 @@ -/* eslint no-unused-vars: off */ -/* eslint no-global-assign: off */ -/* global systemDictionary */ -'use strict'; - -systemDictionary = { - 'test-adapter adapter settings': { - 'en': 'Adapter settings for test-adapter', - 'de': 'Adaptereinstellungen für test-adapter', - 'ru': 'Настройки адаптера для test-adapter', - 'pt': 'Configurações do adaptador para test-adapter', - 'nl': 'Adapterinstellingen voor test-adapter', - 'fr': "Paramètres d'adaptateur pour test-adapter", - 'it': "Impostazioni dell'adattatore per test-adapter", - 'es': 'Ajustes del adaptador para test-adapter', - 'pl': 'Ustawienia adaptera dla test-adapter', - 'uk': 'Налаштування адаптера для test-adapter', - 'zh-cn': 'test-adapter的适配器设置' - }, - 'option1': { - 'en': 'option1', - 'de': "Mock translation of 'option1' to 'de'", - 'ru': "Mock translation of 'option1' to 'ru'", - 'pt': "Mock translation of 'option1' to 'pt'", - 'nl': "Mock translation of 'option1' to 'nl'", - 'fr': "Mock translation of 'option1' to 'fr'", - 'it': "Mock translation of 'option1' to 'it'", - 'es': "Mock translation of 'option1' to 'es'", - 'pl': "Mock translation of 'option1' to 'pl'", - 'uk': "Mock translation of 'option1' to 'uk'", - 'zh-cn': "Mock translation of 'option1' to 'zh-cn'" - }, - 'option2': { - 'en': 'option2', - 'de': "Mock translation of 'option2' to 'de'", - 'ru': "Mock translation of 'option2' to 'ru'", - 'pt': "Mock translation of 'option2' to 'pt'", - 'nl': "Mock translation of 'option2' to 'nl'", - 'fr': "Mock translation of 'option2' to 'fr'", - 'it': "Mock translation of 'option2' to 'it'", - 'es': "Mock translation of 'option2' to 'es'", - 'pl': "Mock translation of 'option2' to 'pl'", - 'uk': "Mock translation of 'option2' to 'uk'", - 'zh-cn': "Mock translation of 'option2' to 'zh-cn'" - } -}; \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/io-package.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/io-package.json deleted file mode 100644 index 6ffb4170..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/io-package.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "common": { - "name": "test-adapter", - "version": "0.0.1", - "news": { - "0.0.1": { - "en": "initial release", - "de": "Erstveröffentlichung", - "ru": "Начальная версия", - "pt": "lançamento inicial", - "nl": "Eerste uitgave", - "fr": "Première version", - "it": "Versione iniziale", - "es": "Versión inicial", - "pl": "Pierwsze wydanie", - "uk": "Початкова версія", - "zh-cn": "首次出版" - } - }, - "title": "Is used to test the creator", - "titleLang": { - "en": "Is used to test the creator", - "de": "Mock translation of 'Is used to test the creator' to 'de'", - "ru": "Mock translation of 'Is used to test the creator' to 'ru'", - "pt": "Mock translation of 'Is used to test the creator' to 'pt'", - "nl": "Mock translation of 'Is used to test the creator' to 'nl'", - "fr": "Mock translation of 'Is used to test the creator' to 'fr'", - "it": "Mock translation of 'Is used to test the creator' to 'it'", - "es": "Mock translation of 'Is used to test the creator' to 'es'", - "pl": "Mock translation of 'Is used to test the creator' to 'pl'", - "uk": "Mock translation of 'Is used to test the creator' to 'uk'", - "zh-cn": "Mock translation of 'Is used to test the creator' to 'zh-cn'" - }, - "desc": { - "en": "test-adapter", - "de": "Mock translation of 'test-adapter' to 'de'", - "ru": "Mock translation of 'test-adapter' to 'ru'", - "pt": "Mock translation of 'test-adapter' to 'pt'", - "nl": "Mock translation of 'test-adapter' to 'nl'", - "fr": "Mock translation of 'test-adapter' to 'fr'", - "it": "Mock translation of 'test-adapter' to 'it'", - "es": "Mock translation of 'test-adapter' to 'es'", - "pl": "Mock translation of 'test-adapter' to 'pl'", - "uk": "Mock translation of 'test-adapter' to 'uk'", - "zh-cn": "Mock translation of 'test-adapter' to 'zh-cn'" - }, - "authors": [ - "Al Calzone " - ], - "keywords": [ - "ioBroker", - "template", - "Smart Home", - "home automation" - ], - "license": "Apache-2.0", - "licenseInformation": { - "type": "free", - "license": "Apache-2.0" - }, - "platform": "Javascript/Node.js", - "main": "main.js", - "icon": "test-adapter.png", - "enabled": true, - "extIcon": "https://raw.githubusercontent.com/AlCalzone/ioBroker.test-adapter/main/admin/test-adapter.png", - "readme": "https://github.com/AlCalzone/ioBroker.test-adapter/blob/main/README.md", - "loglevel": "info", - "tier": 3, - "mode": "daemon", - "type": "general", - "compact": true, - "connectionType": "local", - "dataSource": "push", - "adminUI": { - "config": "materialize" - }, - "dependencies": [ - { - "js-controller": ">=3.3.22" - } - ], - "globalDependencies": [ - { - "admin": ">=5.0.0" - } - ] - }, - "native": { - "option1": true, - "option2": "42" - }, - "objects": [], - "instanceObjects": [] -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/lib/adapter-config.d.ts b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/lib/adapter-config.d.ts deleted file mode 100644 index e0fbfa96..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/lib/adapter-config.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -// This file extends the AdapterConfig type from "@types/iobroker" -// using the actual properties present in io-package.json -// in order to provide typings for adapter.config properties - -import { native } from '../io-package.json'; - -type _AdapterConfig = typeof native; - -// Augment the globally declared type ioBroker.AdapterConfig -declare global { - namespace ioBroker { - interface AdapterConfig extends _AdapterConfig { - // Do not enter anything here! - } - } -} - -// this is required so the above AdapterConfig is found by TypeScript / type checking -export {}; \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.js b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.js deleted file mode 100644 index f4622b51..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.js +++ /dev/null @@ -1,167 +0,0 @@ -'use strict'; - -/* - * Created with @iobroker/create-adapter v2.6.1 - */ - -// The adapter-core module gives you access to the core ioBroker functions -// you need to create an adapter -const utils = require('@iobroker/adapter-core'); - -// Load your modules here, e.g.: -// const fs = require("fs"); - -class TestAdapter extends utils.Adapter { - - /** - * @param {Partial} [options={}] - */ - constructor(options) { - super({ - ...options, - name: 'test-adapter', - }); - this.on('ready', this.onReady.bind(this)); - this.on('stateChange', this.onStateChange.bind(this)); - // this.on('objectChange', this.onObjectChange.bind(this)); - // this.on('message', this.onMessage.bind(this)); - this.on('unload', this.onUnload.bind(this)); - } - - /** - * Is called when databases are connected and adapter received configuration. - */ - async onReady() { - // Initialize your adapter here - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // this.config: - this.log.info('config option1: ' + this.config.option1); - this.log.info('config option2: ' + this.config.option2); - - /* - For every state in the system there has to be also an object of type state - Here a simple template for a boolean variable named "testVariable" - Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await this.setObjectNotExistsAsync('testVariable', { - type: 'state', - common: { - name: 'testVariable', - type: 'boolean', - role: 'indicator', - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - this.subscribeStates('testVariable'); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // this.subscribeStates('lights.*'); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // this.subscribeStates('*'); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await this.setStateAsync('testVariable', true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await this.setStateAsync('testVariable', { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await this.setStateAsync('testVariable', { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - let result = await this.checkPasswordAsync('admin', 'iobroker'); - this.log.info('check user admin pw iobroker: ' + result); - - result = await this.checkGroupAsync('admin', 'admin'); - this.log.info('check group user admin group admin: ' + result); - } - - /** - * Is called when adapter shuts down - callback has to be called under any circumstances! - * @param {() => void} callback - */ - onUnload(callback) { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - } - - // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. - // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. - // /** - // * Is called if a subscribed object changes - // * @param {string} id - // * @param {ioBroker.Object | null | undefined} obj - // */ - // onObjectChange(id, obj) { - // if (obj) { - // // The object was changed - // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // this.log.info(`object ${id} deleted`); - // } - // } - - /** - * Is called if a subscribed state changes - * @param {string} id - * @param {ioBroker.State | null | undefined} state - */ - onStateChange(id, state) { - if (state) { - // The state was changed - this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - this.log.info(`state ${id} deleted`); - } - } - - // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // * @param {ioBroker.Message} obj - // */ - // onMessage(obj) { - // if (typeof obj === 'object' && obj.message) { - // if (obj.command === 'send') { - // // e.g. send email or pushover or whatever - // this.log.info('send command'); - - // // Send response in callback if required - // if (obj.callback) this.sendTo(obj.from, obj.command, 'Message received', obj.callback); - // } - // } - // } - -} - -if (require.main !== module) { - // Export the constructor in compact mode - /** - * @param {Partial} [options={}] - */ - module.exports = (options) => new TestAdapter(options); -} else { - // otherwise start the instance directly - new TestAdapter(); -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.test.js b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.test.js deleted file mode 100644 index 5dc6ee4a..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.test.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -/** - * This is a dummy TypeScript test file using chai and mocha - * - * It's automatically excluded from npm and its build output is excluded from both git and npm. - * It is advised to test all your modules with accompanying *.test.js-files - */ - -// tslint:disable:no-unused-expression - -const { expect } = require('chai'); -// import { functionToTest } from "./moduleToTest"; - -describe('module to test => function to test', () => { - // initializing logic - const expected = 5; - - it(`should return ${expected}`, () => { - const result = 5; - // assign result a value from functionToTest - expect(result).to.equal(expected); - // or using the should() syntax - result.should.equal(expected); - }); - // ... more tests => it - -}); - -// ... more test suites => describe diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/package.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/package.json deleted file mode 100644 index c6551ae9..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "iobroker.test-adapter", - "version": "0.0.1", - "description": "test-adapter", - "author": { - "name": "Al Calzone", - "email": "al@calzo.ne" - }, - "homepage": "https://github.com/AlCalzone/ioBroker.test-adapter", - "license": "Apache-2.0", - "keywords": [ - "ioBroker", - "template", - "Smart Home", - "home automation" - ], - "repository": { - "type": "git", - "url": "https://github.com/AlCalzone/ioBroker.test-adapter.git" - }, - "engines": { - "node": ">= 18" - }, - "dependencies": { - "@iobroker/adapter-core": "^3.0.4" - }, - "devDependencies": { - "@iobroker/adapter-dev": "^1.2.0", - "@iobroker/testing": "^4.1.0", - "@tsconfig/node18": "^18.2.2", - "@types/chai": "^4.3.11", - "@types/chai-as-promised": "^7.1.8", - "@types/mocha": "^10.0.6", - "@types/node": "^18.19.15", - "@types/proxyquire": "^1.3.31", - "@types/sinon": "^17.0.3", - "@types/sinon-chai": "^3.2.12", - "chai-as-promised": "^7.1.1", - "chai": "^4.4.1", - "eslint": "^8.56.0", - "mocha": "^10.3.0", - "proxyquire": "^2.1.3", - "sinon": "^17.0.1", - "sinon-chai": "^3.7.0", - "typescript": "~5.0.4" - }, - "main": "main.js", - "files": [ - "admin{,/!(src)/**}/!(tsconfig|tsconfig.*|.eslintrc).{json,json5}", - "admin{,/!(src)/**}/*.{html,css,png,svg,jpg,js}", - "lib/", - "www/", - "io-package.json", - "LICENSE", - "main.js" - ], - "scripts": { - "test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"", - "test:package": "mocha test/package --exit", - "test:integration": "mocha test/integration --exit", - "test": "npm run test:js && npm run test:package", - "check": "tsc --noEmit -p tsconfig.check.json", - "lint": "eslint .", - "translate": "translate-adapter" - }, - "bugs": { - "url": "https://github.com/AlCalzone/ioBroker.test-adapter/issues" - }, - "readmeFilename": "README.md" -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/integration.js b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/integration.js deleted file mode 100644 index fa6db2e8..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/integration.js +++ /dev/null @@ -1,5 +0,0 @@ -const path = require('path'); -const { tests } = require('@iobroker/testing'); - -// Run integration tests - See https://github.com/ioBroker/testing for a detailed explanation and further options -tests.integration(path.join(__dirname, '..')); \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/mocha.setup.js b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/mocha.setup.js deleted file mode 100644 index 15b9051f..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/mocha.setup.js +++ /dev/null @@ -1,14 +0,0 @@ -// Don't silently swallow unhandled rejections -process.on('unhandledRejection', (e) => { - throw e; -}); - -// enable the should interface with sinon -// and load chai-as-promised and sinon-chai by default -const sinonChai = require('sinon-chai'); -const chaiAsPromised = require('chai-as-promised'); -const { should, use } = require('chai'); - -should(); -use(sinonChai); -use(chaiAsPromised); \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/mocharc.custom.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/mocharc.custom.json deleted file mode 100644 index 2e317d59..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/mocharc.custom.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "require": [ - "test/mocha.setup.js" - ], - "watch-files": [ - "!(node_modules|test)/**/*.test.js", - "*.test.js", - "test/**/test!(PackageFiles|Startup).js" - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/package.js b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/package.js deleted file mode 100644 index 38eacc85..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/package.js +++ /dev/null @@ -1,5 +0,0 @@ -const path = require('path'); -const { tests } = require('@iobroker/testing'); - -// Validate the package files -tests.packageFiles(path.join(__dirname, '..')); diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/tsconfig.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/tsconfig.json deleted file mode 100644 index a2308c1d..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/test/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "noImplicitAny": false - }, - "include": [ - "./**/*.js" - ] -} diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/tsconfig.check.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/tsconfig.check.json deleted file mode 100644 index 6c246298..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/tsconfig.check.json +++ /dev/null @@ -1,14 +0,0 @@ -// Specialized tsconfig for type-checking js files -{ - "extends": "./tsconfig.json", - "compilerOptions": {}, - "include": [ - "**/*.js", - "**/*.d.ts" - ], - "exclude": [ - "**/build", - "node_modules/", - "widgets/" - ] -} diff --git a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/tsconfig.json b/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/tsconfig.json deleted file mode 100644 index 2595af45..00000000 --- a/test/baselines/adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/tsconfig.json +++ /dev/null @@ -1,37 +0,0 @@ -// Root tsconfig to set the settings and power editor support for all TS files -{ - // To update the compilation target, install a different version of @tsconfig/node... and reference it here - // https://github.com/tsconfig/bases#node-18-tsconfigjson - "extends": "@tsconfig/node18/tsconfig.json", - "compilerOptions": { - // do not compile anything, this file is just to configure type checking - "noEmit": true, - - // check JS files - "allowJs": true, - "checkJs": true, - - // This is necessary for the automatic typing of the adapter config - "resolveJsonModule": true, - - // If you want to disable the stricter type checks (not recommended), uncomment the following line - // "strict": false, - // And enable some of those features for more fine-grained control - // "strictNullChecks": true, - // "strictPropertyInitialization": true, - // "strictBindCallApply": true, - "noImplicitAny": false, - // "noUnusedLocals": true, - // "noUnusedParameters": true, - "useUnknownInCatchVariables": false, - - }, - "include": [ - "**/*.js", - "**/*.d.ts" - ], - "exclude": [ - "node_modules/**", - "widgets/**" - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.create-adapter.json b/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.create-adapter.json index e213bb12..60458810 100644 --- a/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.create-adapter.json +++ b/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/.create-adapter.json @@ -22,7 +22,6 @@ ], "indentation": "Space (4)", "quotes": "single", - "es6class": "no", "authorName": "Al Calzone", "authorGithub": "AlCalzone", "authorEmail": "al@calzo.ne", diff --git a/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.js b/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.js index b19c5084..f4622b51 100644 --- a/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.js +++ b/test/baselines/adapter_JS_JsonUI_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0/main.js @@ -11,141 +11,157 @@ const utils = require('@iobroker/adapter-core'); // Load your modules here, e.g.: // const fs = require("fs"); -/** - * The adapter instance - * @type {ioBroker.Adapter} - */ -let adapter; - -/** - * Starts the adapter instance - * @param {Partial} [options] - */ -function startAdapter(options) { - // Create the adapter and define its methods - return adapter = utils.adapter(Object.assign({}, options, { - name: 'test-adapter', - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with `adapter.subscribeObjects`, similar to `adapter.subscribeStates`. - // objectChange: (id, obj) => { - // if (obj) { - // // The object was changed - // adapter.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // adapter.log.info(`object ${id} deleted`); - // } - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - adapter.log.info(`state ${id} deleted`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // if (typeof obj === 'object' && obj.message) { - // if (obj.command === 'send') { - // // e.g. send email or pushover or whatever - // adapter.log.info('send command'); - - // // Send response in callback if required - // if (obj.callback) adapter.sendTo(obj.from, obj.command, 'Message received', obj.callback); - // } - // } - // }, - })); -} - -async function main() { - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: - adapter.log.info('config option1: ' + adapter.config.option1); - adapter.log.info('config option2: ' + adapter.config.option2); - - /* +class TestAdapter extends utils.Adapter { + + /** + * @param {Partial} [options={}] + */ + constructor(options) { + super({ + ...options, + name: 'test-adapter', + }); + this.on('ready', this.onReady.bind(this)); + this.on('stateChange', this.onStateChange.bind(this)); + // this.on('objectChange', this.onObjectChange.bind(this)); + // this.on('message', this.onMessage.bind(this)); + this.on('unload', this.onUnload.bind(this)); + } + + /** + * Is called when databases are connected and adapter received configuration. + */ + async onReady() { + // Initialize your adapter here + + // The adapters config (in the instance object everything under the attribute "native") is accessible via + // this.config: + this.log.info('config option1: ' + this.config.option1); + this.log.info('config option2: ' + this.config.option2); + + /* For every state in the system there has to be also an object of type state Here a simple template for a boolean variable named "testVariable" Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync('testVariable', { - type: 'state', - common: { - name: 'testVariable', - type: 'boolean', - role: 'indicator', - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates('testVariable'); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates('lights.*'); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates('*'); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync('testVariable', true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync('testVariable', { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync('testVariable', { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword('admin', 'iobroker', (res) => { - adapter.log.info('check user admin pw iobroker: ' + res); - }); - - adapter.checkGroup('admin', 'admin', (res) => { - adapter.log.info('check group user admin group admin: ' + res); - }); + */ + await this.setObjectNotExistsAsync('testVariable', { + type: 'state', + common: { + name: 'testVariable', + type: 'boolean', + role: 'indicator', + read: true, + write: true, + }, + native: {}, + }); + + // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. + this.subscribeStates('testVariable'); + // You can also add a subscription for multiple states. The following line watches all states starting with "lights." + // this.subscribeStates('lights.*'); + // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: + // this.subscribeStates('*'); + + /* + setState examples + you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) + */ + // the variable testVariable is set to true as command (ack=false) + await this.setStateAsync('testVariable', true); + + // same thing, but the value is flagged "ack" + // ack should be always set to true if the value is received from or acknowledged from the target system + await this.setStateAsync('testVariable', { val: true, ack: true }); + + // same thing, but the state is deleted after 30s (getState will return null afterwards) + await this.setStateAsync('testVariable', { val: true, ack: true, expire: 30 }); + + // examples for the checkPassword/checkGroup functions + let result = await this.checkPasswordAsync('admin', 'iobroker'); + this.log.info('check user admin pw iobroker: ' + result); + + result = await this.checkGroupAsync('admin', 'admin'); + this.log.info('check group user admin group admin: ' + result); + } + + /** + * Is called when adapter shuts down - callback has to be called under any circumstances! + * @param {() => void} callback + */ + onUnload(callback) { + try { + // Here you must clear all timeouts or intervals that may still be active + // clearTimeout(timeout1); + // clearTimeout(timeout2); + // ... + // clearInterval(interval1); + + callback(); + } catch (e) { + callback(); + } + } + + // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. + // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. + // /** + // * Is called if a subscribed object changes + // * @param {string} id + // * @param {ioBroker.Object | null | undefined} obj + // */ + // onObjectChange(id, obj) { + // if (obj) { + // // The object was changed + // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); + // } else { + // // The object was deleted + // this.log.info(`object ${id} deleted`); + // } + // } + + /** + * Is called if a subscribed state changes + * @param {string} id + * @param {ioBroker.State | null | undefined} state + */ + onStateChange(id, state) { + if (state) { + // The state was changed + this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); + } else { + // The state was deleted + this.log.info(`state ${id} deleted`); + } + } + + // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. + // /** + // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... + // * Using this method requires "common.messagebox" property to be set to true in io-package.json + // * @param {ioBroker.Message} obj + // */ + // onMessage(obj) { + // if (typeof obj === 'object' && obj.message) { + // if (obj.command === 'send') { + // // e.g. send email or pushover or whatever + // this.log.info('send command'); + + // // Send response in callback if required + // if (obj.callback) this.sendTo(obj.from, obj.command, 'Message received', obj.callback); + // } + // } + // } + } if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; + // Export the constructor in compact mode + /** + * @param {Partial} [options={}] + */ + module.exports = (options) => new TestAdapter(options); } else { // otherwise start the instance directly - startAdapter(); + new TestAdapter(); } \ No newline at end of file diff --git a/test/baselines/adapter_JS_React/.create-adapter.json b/test/baselines/adapter_JS_React/.create-adapter.json index 7284c643..2e532ba3 100644 --- a/test/baselines/adapter_JS_React/.create-adapter.json +++ b/test/baselines/adapter_JS_React/.create-adapter.json @@ -21,7 +21,6 @@ ], "indentation": "Tab", "quotes": "double", - "es6class": "yes", "authorName": "Al Calzone", "authorGithub": "AlCalzone", "authorEmail": "al@calzo.ne", diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.create-adapter.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.create-adapter.json deleted file mode 100644 index c9b45eee..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.create-adapter.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "cli": true, - "target": "directory", - "adapterName": "test-adapter", - "title": "Is used to test the creator", - "startMode": "daemon", - "features": [ - "adapter" - ], - "connectionIndicator": "no", - "connectionType": "local", - "dataSource": "push", - "adminFeatures": [], - "type": "general", - "language": "TypeScript", - "adminUi": "html", - "tabReact": "no", - "releaseScript": "no", - "tools": [ - "ESLint" - ], - "indentation": "Tab", - "quotes": "double", - "es6class": "yes", - "authorName": "Al Calzone", - "authorGithub": "AlCalzone", - "authorEmail": "al@calzo.ne", - "gitRemoteProtocol": "HTTPS", - "dependabot": "yes", - "gitCommit": "no", - "defaultBranch": "main", - "license": "MIT License", - "licenseInformation": { - "type": "free", - "license": "MIT" - }, - "creatorVersion": "2.6.1" -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.eslintignore b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.eslintignore deleted file mode 100644 index d7b78651..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -build/ -**/.eslintrc.js -admin/words.js \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.eslintrc.js b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.eslintrc.js deleted file mode 100644 index 7f997db7..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.eslintrc.js +++ /dev/null @@ -1,69 +0,0 @@ -module.exports = { - root: true, // Don't look outside this project for inherited configs - parser: "@typescript-eslint/parser", // Specifies the ESLint parser - parserOptions: { - ecmaVersion: "latest", // Allows for the parsing of modern ECMAScript features - sourceType: "module", // Allows for the use of imports - project: "./tsconfig.json", - }, - extends: [ - "plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin - ], - plugins: [], - rules: { - "indent": "off", - "@typescript-eslint/indent": [ - "error", - "tab", - { - "SwitchCase": 1 - } - ], - "quotes": [ - "error", - "double", - { - "avoidEscape": true, - "allowTemplateLiterals": true - } - ], - "@typescript-eslint/no-parameter-properties": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-use-before-define": [ - "error", - { - functions: false, - typedefs: false, - classes: false, - }, - ], - "@typescript-eslint/no-unused-vars": [ - "error", - { - ignoreRestSiblings: true, - argsIgnorePattern: "^_", - }, - ], - "@typescript-eslint/explicit-function-return-type": [ - "warn", - { - allowExpressions: true, - allowTypedFunctionExpressions: true, - }, - ], - "@typescript-eslint/no-object-literal-type-assertion": "off", - "@typescript-eslint/interface-name-prefix": "off", - "@typescript-eslint/no-non-null-assertion": "off", // This is necessary for Map.has()/get()! - "no-var": "error", - "prefer-const": "error", - "no-trailing-spaces": "error", - }, - overrides: [ - { - files: ["*.test.ts"], - rules: { - "@typescript-eslint/explicit-function-return-type": "off", - }, - }, - ], -}; \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/ISSUE_TEMPLATE/bug_report.md b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 89561395..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Bug report -about: Something is not working as it should -title: '' -labels: '' -assignees: '' ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '...' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots & Logfiles** -If applicable, add screenshots and logfiles to help explain your problem. - -**Versions:** - - Adapter version: - - JS-Controller version: - - Node version: - - Operating system: - -**Additional context** -Add any other context about the problem here. diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/auto-merge.yml b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/auto-merge.yml deleted file mode 100644 index 4f6d185f..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/auto-merge.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Configure here which dependency updates should be merged automatically. -# The recommended configuration is the following: -- match: - # Only merge patches for production dependencies - dependency_type: production - update_type: "semver:patch" -- match: - # Except for security fixes, here we allow minor patches - dependency_type: production - update_type: "security:minor" -- match: - # and development dependencies can have a minor update, too - dependency_type: development - update_type: "semver:minor" - -# The syntax is based on the legacy dependabot v1 automerged_updates syntax, see: -# https://dependabot.com/docs/config-file/#automerged_updates diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/dependabot.yml b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/dependabot.yml deleted file mode 100644 index c165a6a4..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/dependabot.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: 2 -updates: - - package-ecosystem: npm - directory: "/" - schedule: - interval: monthly - time: "04:00" - timezone: Europe/Berlin - open-pull-requests-limit: 5 - assignees: - - AlCalzone - versioning-strategy: increase - - - package-ecosystem: github-actions - directory: "/" - schedule: - interval: monthly - time: "04:00" - timezone: Europe/Berlin - open-pull-requests-limit: 5 - assignees: - - AlCalzone diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/workflows/dependabot-auto-merge.yml b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/workflows/dependabot-auto-merge.yml deleted file mode 100644 index c9b5329b..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/workflows/dependabot-auto-merge.yml +++ /dev/null @@ -1,27 +0,0 @@ -# Automatically merge Dependabot PRs when version comparison is within the range -# that is configured in .github/auto-merge.yml - -name: Auto-Merge Dependabot PRs - -on: - # WARNING: This needs to be run in the PR base, DO NOT build untrusted code in this action - # details under https://github.blog/changelog/2021-02-19-github-actions-workflows-triggered-by-dependabot-prs-will-run-with-read-only-permissions/ - pull_request_target: - -jobs: - auto-merge: - if: github.actor == 'dependabot[bot]' - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Check if PR should be auto-merged - uses: ahmadnassri/action-dependabot-auto-merge@v2 - with: - # In order to use this, you need to go to https://github.com/settings/tokens and - # create a Personal Access Token with the permission "public_repo". - # Enter this token in your repository settings under "Secrets" and name it AUTO_MERGE_TOKEN - github-token: ${{ secrets.AUTO_MERGE_TOKEN }} - # By default, squash and merge, so Github chooses nice commit messages - command: squash and merge diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/workflows/test-and-release.yml b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/workflows/test-and-release.yml deleted file mode 100644 index e0cf5e75..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.github/workflows/test-and-release.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: Test and Release - -# Run this job on all pushes and pull requests -# as well as tags with a semantic version -on: - push: - branches: - - "main" - tags: - # normal versions - - "v[0-9]+.[0-9]+.[0-9]+" - # pre-releases - - "v[0-9]+.[0-9]+.[0-9]+-**" - pull_request: {} - -# Cancel previous PR/branch runs when a new commit is pushed -concurrency: - group: ${{ github.ref }} - cancel-in-progress: true - -jobs: - # Performs quick checks before the expensive test runs - check-and-lint: - if: contains(github.event.head_commit.message, '[skip ci]') == false - - runs-on: ubuntu-latest - - steps: - - uses: ioBroker/testing-action-check@v1 - with: - node-version: '18.x' - # Uncomment the following line if your adapter cannot be installed using 'npm ci' - # install-command: 'npm install' - type-checking: true - lint: true - - # Runs adapter tests on all supported node versions and OSes - adapter-tests: - if: contains(github.event.head_commit.message, '[skip ci]') == false - - runs-on: ${{ matrix.os }} - strategy: - matrix: - node-version: [18.x, 20.x] - os: [ubuntu-latest, windows-latest, macos-latest] - - steps: - - uses: ioBroker/testing-action-adapter@v1 - with: - node-version: ${{ matrix.node-version }} - os: ${{ matrix.os }} - # Uncomment the following line if your adapter cannot be installed using 'npm ci' - # install-command: 'npm install' - build: true - -# TODO: To enable automatic npm releases, create a token on npmjs.org -# Enter this token as a GitHub secret (with name NPM_TOKEN) in the repository options -# Then uncomment the following block: - -# # Deploys the final package to NPM -# deploy: -# needs: [check-and-lint, adapter-tests] -# -# # Trigger this step only when a commit on any branch is tagged with a version number -# if: | -# contains(github.event.head_commit.message, '[skip ci]') == false && -# github.event_name == 'push' && -# startsWith(github.ref, 'refs/tags/v') -# -# runs-on: ubuntu-latest -# -# # Write permissions are required to create Github releases -# permissions: -# contents: write -# -# steps: -# - uses: ioBroker/testing-action-deploy@v1 -# with: -# node-version: '18.x' -# # Uncomment the following line if your adapter cannot be installed using 'npm ci' -# # install-command: 'npm install' -# build: true -# npm-token: ${{ secrets.NPM_TOKEN }} -# github-token: ${{ secrets.GITHUB_TOKEN }} -# -# # When using Sentry for error reporting, Sentry can be informed about new releases -# # To enable create a API-Token in Sentry (User settings, API keys) -# # Enter this token as a GitHub secret (with name SENTRY_AUTH_TOKEN) in the repository options -# # Then uncomment and customize the following block: -# sentry: true -# sentry-token: ${{ secrets.SENTRY_AUTH_TOKEN }} -# sentry-project: "iobroker-test-adapter" -# sentry-version-prefix: "iobroker.test-adapter" -# sentry-sourcemap-paths: "build/" -# # If your sentry project is linked to a GitHub repository, you can enable the following option -# # sentry-github-integration: true diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.gitignore b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.gitignore deleted file mode 100644 index 3bf582ba..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# No dot-directories except github/vscode -.*/ -!.vscode/ -!.github/ - -*.code-workspace -node_modules -nbproject - -# npm package files -iobroker.*.tgz - -Thumbs.db - -# i18n intermediate files -admin/i18n/flat.txt -admin/i18n/*/flat.txt \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.vscode/extensions.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.vscode/extensions.json deleted file mode 100644 index a8d77849..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "dbaeumer.vscode-eslint" - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.vscode/settings.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.vscode/settings.json deleted file mode 100644 index bcddaeb2..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/.vscode/settings.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "typescript.tsdk": "node_modules/typescript/lib", - "eslint.enable": true, - "json.schemas": [ - { - "fileMatch": [ - "io-package.json" - ], - "url": "https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/schemas/io-package.json" - }, - { - "fileMatch": [ - "admin/jsonConfig.json", - "admin/jsonCustom.json", - "admin/jsonTab.json" - ], - "url": "https://raw.githubusercontent.com/ioBroker/adapter-react-v5/main/schemas/jsonConfig.json" - } - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/LICENSE b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/LICENSE deleted file mode 100644 index 4a63a453..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 Al Calzone - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/README.md b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/README.md deleted file mode 100644 index 3b3a2409..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/README.md +++ /dev/null @@ -1,132 +0,0 @@ -![Logo](admin/test-adapter.png) -# ioBroker.test-adapter - -[![NPM version](https://img.shields.io/npm/v/iobroker.test-adapter.svg)](https://www.npmjs.com/package/iobroker.test-adapter) -[![Downloads](https://img.shields.io/npm/dm/iobroker.test-adapter.svg)](https://www.npmjs.com/package/iobroker.test-adapter) -![Number of Installations](https://iobroker.live/badges/test-adapter-installed.svg) -![Current version in stable repository](https://iobroker.live/badges/test-adapter-stable.svg) - -[![NPM](https://nodei.co/npm/iobroker.test-adapter.png?downloads=true)](https://nodei.co/npm/iobroker.test-adapter/) - -**Tests:** ![Test and Release](https://github.com/AlCalzone/ioBroker.test-adapter/workflows/Test%20and%20Release/badge.svg) - -## test-adapter adapter for ioBroker - -Describe your project here - -## Developer manual -This section is intended for the developer. It can be deleted later. - -### DISCLAIMER - -Please make sure that you consider copyrights and trademarks when you use names or logos of a company and add a disclaimer to your README. -You can check other adapters for examples or ask in the developer community. Using a name or logo of a company without permission may cause legal problems for you. - -### Getting started - -You are almost done, only a few steps left: -1. Create a new repository on GitHub with the name `ioBroker.test-adapter` -1. Initialize the current folder as a new git repository: - ```bash - git init -b main - git add . - git commit -m "Initial commit" - ``` -1. Link your local repository with the one on GitHub: - ```bash - git remote add origin https://github.com/AlCalzone/ioBroker.test-adapter - ``` - -1. Push all files to the GitHub repo: - ```bash - git push origin main - ``` -1. Add a new secret under https://github.com/AlCalzone/ioBroker.test-adapter/settings/secrets. It must be named `AUTO_MERGE_TOKEN` and contain a personal access token with push access to the repository, e.g. yours. You can create a new token under https://github.com/settings/tokens. - -1. Head over to [src/main.ts](src/main.ts) and start programming! - -### Best Practices -We've collected some [best practices](https://github.com/ioBroker/ioBroker.repositories#development-and-coding-best-practices) regarding ioBroker development and coding in general. If you're new to ioBroker or Node.js, you should -check them out. If you're already experienced, you should also take a look at them - you might learn something new :) - -### Scripts in `package.json` -Several npm scripts are predefined for your convenience. You can run them using `npm run ` -| Script name | Description | -|-------------|-------------| -| `build` | Compile the TypeScript sources. | -| `watch` | Compile the TypeScript sources and watch for changes. | -| `test:ts` | Executes the tests you defined in `*.test.ts` files. | -| `test:package` | Ensures your `package.json` and `io-package.json` are valid. | -| `test:integration` | Tests the adapter startup with an actual instance of ioBroker. | -| `test` | Performs a minimal test run on package files and your tests. | -| `check` | Performs a type-check on your code (without compiling anything). | -| `lint` | Runs `ESLint` to check your code for formatting errors and potential bugs. | -| `translate` | Translates texts in your adapter to all required languages, see [`@iobroker/adapter-dev`](https://github.com/ioBroker/adapter-dev#manage-translations) for more details. | - -### Configuring the compilation -The adapter template uses [esbuild](https://esbuild.github.io/) to compile TypeScript and/or React code. You can configure many compilation settings -either in `tsconfig.json` or by changing options for the build tasks. These options are described in detail in the -[`@iobroker/adapter-dev` documentation](https://github.com/ioBroker/adapter-dev#compile-adapter-files). - -### Writing tests -When done right, testing code is invaluable, because it gives you the -confidence to change your code while knowing exactly if and when -something breaks. A good read on the topic of test-driven development -is https://hackernoon.com/introduction-to-test-driven-development-tdd-61a13bc92d92. -Although writing tests before the code might seem strange at first, but it has very -clear upsides. - -The template provides you with basic tests for the adapter startup and package files. -It is recommended that you add your own tests into the mix. - -### Publishing the adapter -Using GitHub Actions, you can enable automatic releases on npm whenever you push a new git tag that matches the form -`v..`. We **strongly recommend** that you do. The necessary steps are described in `.github/workflows/test-and-release.yml`. - -To get your adapter released in ioBroker, please refer to the documentation -of [ioBroker.repositories](https://github.com/ioBroker/ioBroker.repositories#requirements-for-adapter-to-get-added-to-the-latest-repository). - -### Test the adapter manually on a local ioBroker installation -In order to install the adapter locally without publishing, the following steps are recommended: -1. Create a tarball from your dev directory: - ```bash - npm pack - ``` -1. Upload the resulting file to your ioBroker host -1. Install it locally (The paths are different on Windows): - ```bash - cd /opt/iobroker - npm i /path/to/tarball.tgz - ``` - -For later updates, the above procedure is not necessary. Just do the following: -1. Overwrite the changed files in the adapter directory (`/opt/iobroker/node_modules/iobroker.test-adapter`) -1. Execute `iobroker upload test-adapter` on the ioBroker host - -## Changelog - -### 0.0.1 -* (Al Calzone) initial release - -## License -MIT License - -Copyright (c) 2024 Al Calzone - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/__meta__/npm_package_files.txt b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/__meta__/npm_package_files.txt deleted file mode 100644 index 7503a378..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/__meta__/npm_package_files.txt +++ /dev/null @@ -1,8 +0,0 @@ -admin/index_m.html -admin/style.css -admin/test-adapter.png -admin/words.js -io-package.json -LICENSE -package.json -README.md \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/admin.d.ts b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/admin.d.ts deleted file mode 100644 index 41f934f4..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/admin.d.ts +++ /dev/null @@ -1,93 +0,0 @@ -declare let systemDictionary: Record>; - -declare let load: (settings: Record, onChange: (hasChanges: boolean) => void) => void; -declare let save: (callback: (settings: Record) => void) => void; - -// make load and save exist on the window object -interface Window { - load: typeof load; - save: typeof save; -} - -declare const instance: number; -declare const adapter: string; -/** Translates text */ -declare function _(text: string, arg1?: string, arg2?: string, arg3?: string): string; -declare const socket: ioBrokerSocket; -declare function sendTo( - instance: any | null, - command: string, - message: any, - callback: (result: SendToResult) => void | Promise, -): void; - -interface SendToResult { - error?: string | Error; - result?: any; -} - -// tslint:disable-next-line:class-name -interface ioBrokerSocket { - emit( - command: "subscribeObjects", - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - emit( - command: "subscribeStates", - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - emit( - command: "unsubscribeObjects", - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - emit( - command: "unsubscribeStates", - pattern: string, - callback?: (err?: string) => void | Promise, - ): void; - - emit( - event: "getObjectView", - view: "system", - type: "device", - options: ioBroker.GetObjectViewParams, - callback: ( - err: string | undefined, - result?: any, - ) => void | Promise, - ): void; - emit( - event: "getStates", - callback: ( - err: string | undefined, - result?: Record, - ) => void, - ): void; - emit( - event: "getState", - id: string, - callback: (err: string | undefined, result?: ioBroker.State) => void, - ): void; - emit( - event: "setState", - id: string, - state: unknown, - callback: (err: string | undefined, result?: any) => void, - ): void; - - on(event: "objectChange", handler: ioBroker.ObjectChangeHandler): void; - on(event: "stateChange", handler: ioBroker.StateChangeHandler): void; - removeEventHandler( - event: "objectChange", - handler: ioBroker.ObjectChangeHandler, - ): void; - removeEventHandler( - event: "stateChange", - handler: ioBroker.StateChangeHandler, - ): void; - - // TODO: other events -} diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/index_m.html b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/index_m.html deleted file mode 100644 index f11dc3c1..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/index_m.html +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- -
-
- - - - -
-
- - -
- -
- - -
-
- -
- - - - \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/style.css b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/style.css deleted file mode 100644 index 57d4549e..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/style.css +++ /dev/null @@ -1,32 +0,0 @@ -/* You can delete those if you want. I just found them very helpful */ -* { - box-sizing: border-box -} -.m { - /* Don't cut off dropdowns! */ - overflow: initial; -} -.m.adapter-container, -.m.adapter-container > div.App { - /* Fix layout/scrolling issues with tabs */ - height: 100%; - width: 100%; - position: relative; -} -.m .select-wrapper + label { - /* The positioning for dropdown labels is messed up */ - transform: none !important; -} - -label > i[title] { - /* Display the help cursor for the tooltip icons and fix their positioning */ - cursor: help; - margin-left: 0.25em; -} - -.dropdown-content { - /* Don't wrap text in dropdowns */ - white-space: nowrap; -} - -/* Add your styles here */ diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/test-adapter.png b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/test-adapter.png deleted file mode 100644 index 094ebd97..00000000 Binary files a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/test-adapter.png and /dev/null differ diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/tsconfig.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/tsconfig.json deleted file mode 100644 index 49fb013d..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../tsconfig.json", - "include": [ - "./admin.d.ts", - "./**/*.js", - // Include the adapter-config definition if it exists. - // It should be at either on of these paths: - "../lib/adapter-config.d.ts", // JS - "../src/lib/adapter-config.d.ts", // TS - ] -} diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/words.js b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/words.js deleted file mode 100644 index 4517fef8..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/admin/words.js +++ /dev/null @@ -1,46 +0,0 @@ -/* eslint no-unused-vars: off */ -/* eslint no-global-assign: off */ -/* global systemDictionary */ -"use strict"; - -systemDictionary = { - "test-adapter adapter settings": { - "en": "Adapter settings for test-adapter", - "de": "Adaptereinstellungen für test-adapter", - "ru": "Настройки адаптера для test-adapter", - "pt": "Configurações do adaptador para test-adapter", - "nl": "Adapterinstellingen voor test-adapter", - "fr": "Paramètres d'adaptateur pour test-adapter", - "it": "Impostazioni dell'adattatore per test-adapter", - "es": "Ajustes del adaptador para test-adapter", - "pl": "Ustawienia adaptera dla test-adapter", - "uk": "Налаштування адаптера для test-adapter", - "zh-cn": "test-adapter的适配器设置" - }, - "option1": { - "en": "option1", - "de": "Mock translation of 'option1' to 'de'", - "ru": "Mock translation of 'option1' to 'ru'", - "pt": "Mock translation of 'option1' to 'pt'", - "nl": "Mock translation of 'option1' to 'nl'", - "fr": "Mock translation of 'option1' to 'fr'", - "it": "Mock translation of 'option1' to 'it'", - "es": "Mock translation of 'option1' to 'es'", - "pl": "Mock translation of 'option1' to 'pl'", - "uk": "Mock translation of 'option1' to 'uk'", - "zh-cn": "Mock translation of 'option1' to 'zh-cn'" - }, - "option2": { - "en": "option2", - "de": "Mock translation of 'option2' to 'de'", - "ru": "Mock translation of 'option2' to 'ru'", - "pt": "Mock translation of 'option2' to 'pt'", - "nl": "Mock translation of 'option2' to 'nl'", - "fr": "Mock translation of 'option2' to 'fr'", - "it": "Mock translation of 'option2' to 'it'", - "es": "Mock translation of 'option2' to 'es'", - "pl": "Mock translation of 'option2' to 'pl'", - "uk": "Mock translation of 'option2' to 'uk'", - "zh-cn": "Mock translation of 'option2' to 'zh-cn'" - } -}; \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/io-package.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/io-package.json deleted file mode 100644 index 80930b4f..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/io-package.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "common": { - "name": "test-adapter", - "version": "0.0.1", - "news": { - "0.0.1": { - "en": "initial release", - "de": "Erstveröffentlichung", - "ru": "Начальная версия", - "pt": "lançamento inicial", - "nl": "Eerste uitgave", - "fr": "Première version", - "it": "Versione iniziale", - "es": "Versión inicial", - "pl": "Pierwsze wydanie", - "uk": "Початкова версія", - "zh-cn": "首次出版" - } - }, - "title": "Is used to test the creator", - "titleLang": { - "en": "Is used to test the creator", - "de": "Mock translation of 'Is used to test the creator' to 'de'", - "ru": "Mock translation of 'Is used to test the creator' to 'ru'", - "pt": "Mock translation of 'Is used to test the creator' to 'pt'", - "nl": "Mock translation of 'Is used to test the creator' to 'nl'", - "fr": "Mock translation of 'Is used to test the creator' to 'fr'", - "it": "Mock translation of 'Is used to test the creator' to 'it'", - "es": "Mock translation of 'Is used to test the creator' to 'es'", - "pl": "Mock translation of 'Is used to test the creator' to 'pl'", - "uk": "Mock translation of 'Is used to test the creator' to 'uk'", - "zh-cn": "Mock translation of 'Is used to test the creator' to 'zh-cn'" - }, - "desc": { - "en": "test-adapter", - "de": "Mock translation of 'test-adapter' to 'de'", - "ru": "Mock translation of 'test-adapter' to 'ru'", - "pt": "Mock translation of 'test-adapter' to 'pt'", - "nl": "Mock translation of 'test-adapter' to 'nl'", - "fr": "Mock translation of 'test-adapter' to 'fr'", - "it": "Mock translation of 'test-adapter' to 'it'", - "es": "Mock translation of 'test-adapter' to 'es'", - "pl": "Mock translation of 'test-adapter' to 'pl'", - "uk": "Mock translation of 'test-adapter' to 'uk'", - "zh-cn": "Mock translation of 'test-adapter' to 'zh-cn'" - }, - "authors": [ - "Al Calzone " - ], - "keywords": [ - "ioBroker", - "template", - "Smart Home", - "home automation" - ], - "license": "MIT", - "licenseInformation": { - "type": "free", - "license": "MIT" - }, - "platform": "Javascript/Node.js", - "main": "build/main.js", - "icon": "test-adapter.png", - "enabled": true, - "extIcon": "https://raw.githubusercontent.com/AlCalzone/ioBroker.test-adapter/main/admin/test-adapter.png", - "readme": "https://github.com/AlCalzone/ioBroker.test-adapter/blob/main/README.md", - "loglevel": "info", - "tier": 3, - "mode": "daemon", - "type": "general", - "compact": true, - "connectionType": "local", - "dataSource": "push", - "adminUI": { - "config": "materialize" - }, - "dependencies": [ - { - "js-controller": ">=3.3.22" - } - ], - "globalDependencies": [ - { - "admin": ">=5.0.0" - } - ] - }, - "native": { - "option1": true, - "option2": "42" - }, - "objects": [], - "instanceObjects": [] -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/package.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/package.json deleted file mode 100644 index 79f95a25..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/package.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "name": "iobroker.test-adapter", - "version": "0.0.1", - "description": "test-adapter", - "author": { - "name": "Al Calzone", - "email": "al@calzo.ne" - }, - "homepage": "https://github.com/AlCalzone/ioBroker.test-adapter", - "license": "MIT", - "keywords": [ - "ioBroker", - "template", - "Smart Home", - "home automation" - ], - "repository": { - "type": "git", - "url": "https://github.com/AlCalzone/ioBroker.test-adapter.git" - }, - "engines": { - "node": ">= 18" - }, - "dependencies": { - "@iobroker/adapter-core": "^3.0.4" - }, - "devDependencies": { - "@iobroker/adapter-dev": "^1.2.0", - "@iobroker/testing": "^4.1.0", - "@tsconfig/node18": "^18.2.2", - "@types/chai": "^4.3.11", - "@types/chai-as-promised": "^7.1.8", - "@types/mocha": "^10.0.6", - "@types/node": "^18.19.15", - "@types/proxyquire": "^1.3.31", - "@types/sinon": "^17.0.3", - "@types/sinon-chai": "^3.2.12", - "@typescript-eslint/eslint-plugin": "^6.21.0", - "@typescript-eslint/parser": "^6.21.0", - "chai-as-promised": "^7.1.1", - "chai": "^4.4.1", - "eslint": "^8.56.0", - "mocha": "^10.3.0", - "proxyquire": "^2.1.3", - "rimraf": "^5.0.5", - "sinon": "^17.0.1", - "sinon-chai": "^3.7.0", - "source-map-support": "^0.5.21", - "ts-node": "^10.9.2", - "typescript": "~5.0.4" - }, - "main": "build/main.js", - "files": [ - "admin{,/!(src)/**}/!(tsconfig|tsconfig.*|.eslintrc).{json,json5}", - "admin{,/!(src)/**}/*.{html,css,png,svg,jpg,js}", - "build/", - "www/", - "io-package.json", - "LICENSE" - ], - "scripts": { - "prebuild": "rimraf build", - "build": "build-adapter ts", - "watch": "build-adapter ts --watch", - "prebuild:ts": "rimraf build", - "build:ts": "build-adapter ts", - "watch:ts": "build-adapter ts --watch", - "test:ts": "mocha --config test/mocharc.custom.json src/**/*.test.ts", - "test:package": "mocha test/package --exit", - "test:integration": "mocha test/integration --exit", - "test": "npm run test:ts && npm run test:package", - "check": "tsc --noEmit", - "lint": "eslint --ext .ts src/", - "translate": "translate-adapter" - }, - "bugs": { - "url": "https://github.com/AlCalzone/ioBroker.test-adapter/issues" - }, - "readmeFilename": "README.md" -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/lib/adapter-config.d.ts b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/lib/adapter-config.d.ts deleted file mode 100644 index c6c8a0e2..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/lib/adapter-config.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -// This file extends the AdapterConfig type from "@types/iobroker" - -// Augment the globally declared type ioBroker.AdapterConfig -declare global { - namespace ioBroker { - interface AdapterConfig { - option1: boolean; - option2: string; - } - } -} - -// this is required so the above AdapterConfig is found by TypeScript / type checking -export {}; \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/main.test.ts b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/main.test.ts deleted file mode 100644 index a8d538e9..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/main.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This is a dummy TypeScript test file using chai and mocha - * - * It's automatically excluded from npm and its build output is excluded from both git and npm. - * It is advised to test all your modules with accompanying *.test.ts-files - */ - -import { expect } from "chai"; -// import { functionToTest } from "./moduleToTest"; - -describe("module to test => function to test", () => { - // initializing logic - const expected = 5; - - it(`should return ${expected}`, () => { - const result = 5; - // assign result a value from functionToTest - expect(result).to.equal(expected); - // or using the should() syntax - result.should.equal(expected); - }); - // ... more tests => it - -}); - -// ... more test suites => describe diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/main.ts b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/main.ts deleted file mode 100644 index 5a1427f7..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/src/main.ts +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Created with @iobroker/create-adapter v2.6.1 - */ - -// The adapter-core module gives you access to the core ioBroker functions -// you need to create an adapter -import * as utils from "@iobroker/adapter-core"; - -// Load your modules here, e.g.: -// import * as fs from "fs"; - -class TestAdapter extends utils.Adapter { - - public constructor(options: Partial = {}) { - super({ - ...options, - name: "test-adapter", - }); - this.on("ready", this.onReady.bind(this)); - this.on("stateChange", this.onStateChange.bind(this)); - // this.on("objectChange", this.onObjectChange.bind(this)); - // this.on("message", this.onMessage.bind(this)); - this.on("unload", this.onUnload.bind(this)); - } - - /** - * Is called when databases are connected and adapter received configuration. - */ - private async onReady(): Promise { - // Initialize your adapter here - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // this.config: - this.log.info("config option1: " + this.config.option1); - this.log.info("config option2: " + this.config.option2); - - /* - For every state in the system there has to be also an object of type state - Here a simple template for a boolean variable named "testVariable" - Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await this.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - this.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // this.subscribeStates("lights.*"); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // this.subscribeStates("*"); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await this.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await this.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - let result = await this.checkPasswordAsync("admin", "iobroker"); - this.log.info("check user admin pw iobroker: " + result); - - result = await this.checkGroupAsync("admin", "admin"); - this.log.info("check group user admin group admin: " + result); - } - - /** - * Is called when adapter shuts down - callback has to be called under any circumstances! - */ - private onUnload(callback: () => void): void { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - } - - // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. - // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. - // /** - // * Is called if a subscribed object changes - // */ - // private onObjectChange(id: string, obj: ioBroker.Object | null | undefined): void { - // if (obj) { - // // The object was changed - // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // this.log.info(`object ${id} deleted`); - // } - // } - - /** - * Is called if a subscribed state changes - */ - private onStateChange(id: string, state: ioBroker.State | null | undefined): void { - if (state) { - // The state was changed - this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - this.log.info(`state ${id} deleted`); - } - } - - // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // private onMessage(obj: ioBroker.Message): void { - // if (typeof obj === "object" && obj.message) { - // if (obj.command === "send") { - // // e.g. send email or pushover or whatever - // this.log.info("send command"); - - // // Send response in callback if required - // if (obj.callback) this.sendTo(obj.from, obj.command, "Message received", obj.callback); - // } - // } - // } - -} - -if (require.main !== module) { - // Export the constructor in compact mode - module.exports = (options: Partial | undefined) => new TestAdapter(options); -} else { - // otherwise start the instance directly - (() => new TestAdapter())(); -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/.eslintrc.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/.eslintrc.json deleted file mode 100644 index ce6b3d62..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/.eslintrc.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "root": true, - "env": { - "es6": true, - "node": true, - "mocha": true - }, - "extends": [ - "eslint:recommended" - ], - "rules": { - "indent": [ - "error", - "tab", - { - "SwitchCase": 1 - } - ], - "no-console": "off", - "no-unused-vars": [ - "error", - { - "ignoreRestSiblings": true, - "argsIgnorePattern": "^_" - } - ], - "no-var": "error", - "no-trailing-spaces": "error", - "prefer-const": "error", - "quotes": [ - "error", - "double", - { - "avoidEscape": true, - "allowTemplateLiterals": true - } - ], - "semi": [ - "error", - "always" - ] - } -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/integration.js b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/integration.js deleted file mode 100644 index 986936fa..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/integration.js +++ /dev/null @@ -1,5 +0,0 @@ -const path = require("path"); -const { tests } = require("@iobroker/testing"); - -// Run integration tests - See https://github.com/ioBroker/testing for a detailed explanation and further options -tests.integration(path.join(__dirname, "..")); \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/mocha.setup.js b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/mocha.setup.js deleted file mode 100644 index b839790f..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/mocha.setup.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; - -// Makes ts-node ignore warnings, so mocha --watch does work -process.env.TS_NODE_IGNORE_WARNINGS = "TRUE"; -// Sets the correct tsconfig for testing -process.env.TS_NODE_PROJECT = "tsconfig.json"; -// Make ts-node respect the "include" key in tsconfig.json -process.env.TS_NODE_FILES = "TRUE"; - -// Don't silently swallow unhandled rejections -process.on("unhandledRejection", (e) => { - throw e; -}); - -// enable the should interface with sinon -// and load chai-as-promised and sinon-chai by default -const sinonChai = require("sinon-chai"); -const chaiAsPromised = require("chai-as-promised"); -const { should, use } = require("chai"); - -should(); -use(sinonChai); -use(chaiAsPromised); \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/mocharc.custom.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/mocharc.custom.json deleted file mode 100644 index 851ed9cd..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/mocharc.custom.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "require": [ - "test/mocha.setup.js", - "ts-node/register", - "source-map-support/register" - ], - "watch-files": [ - "src/**/*.test.ts" - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/package.js b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/package.js deleted file mode 100644 index 3a48e044..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/package.js +++ /dev/null @@ -1,5 +0,0 @@ -const path = require("path"); -const { tests } = require("@iobroker/testing"); - -// Validate the package files -tests.packageFiles(path.join(__dirname, "..")); diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/tsconfig.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/tsconfig.json deleted file mode 100644 index 3ebc81b6..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/test/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "noImplicitAny": false - }, - "include": [ - "./**/*.js" - ] -} diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/tsconfig.build.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/tsconfig.build.json deleted file mode 100644 index 1f040ce1..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/tsconfig.build.json +++ /dev/null @@ -1,16 +0,0 @@ -// Specialized tsconfig to only compile .ts-files in the src dir -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "allowJs": false, - "checkJs": false, - "noEmit": false, - "declaration": false - }, - "include": [ - "src/**/*.ts" - ], - "exclude": [ - "src/**/*.test.ts" - ] -} diff --git a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/tsconfig.json b/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/tsconfig.json deleted file mode 100644 index 48ed29c0..00000000 --- a/test/baselines/adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT/tsconfig.json +++ /dev/null @@ -1,46 +0,0 @@ -// Root tsconfig to set the settings and power editor support for all TS files -{ - // To update the compilation target, install a different version of @tsconfig/node... and reference it here - // https://github.com/tsconfig/bases#node-18-tsconfigjson - "extends": "@tsconfig/node18/tsconfig.json", - "compilerOptions": { - // do not compile anything, this file is just to configure type checking - // the compilation is configured in tsconfig.build.json - "noEmit": true, - - // check JS files, but do not compile them => tsconfig.build.json - "allowJs": true, - "checkJs": true, - - "noEmitOnError": true, - "outDir": "./build/", - "removeComments": false, - - // This is necessary for the automatic typing of the adapter config - "resolveJsonModule": true, - - // If you want to disable the stricter type checks (not recommended), uncomment the following line - // "strict": false, - // And enable some of those features for more fine-grained control - // "strictNullChecks": true, - // "strictPropertyInitialization": true, - // "strictBindCallApply": true, - // "noImplicitAny": true, - // "noUnusedLocals": true, - // "noUnusedParameters": true, - // Uncomment this if you want the old behavior of catch variables being `any` - // "useUnknownInCatchVariables": false, - - "sourceMap": true, - "inlineSourceMap": false - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ], - "exclude": [ - "build/**", - "node_modules/**", - "widgets/**" - ] -} \ No newline at end of file diff --git a/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/.create-adapter.json b/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/.create-adapter.json index cd3e3c82..35aa2cff 100644 --- a/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/.create-adapter.json +++ b/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/.create-adapter.json @@ -24,7 +24,6 @@ ], "indentation": "Tab", "quotes": "double", - "es6class": "no", "authorName": "Al Calzone", "authorGithub": "AlCalzone", "authorEmail": "al@calzo.ne", diff --git a/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/src/main.ts b/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/src/main.ts index 31985807..5a1427f7 100644 --- a/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/src/main.ts +++ b/test/baselines/adapter_TS_ESLint_Tabs_DoubleQuotes_MIT/src/main.ts @@ -9,139 +9,145 @@ import * as utils from "@iobroker/adapter-core"; // Load your modules here, e.g.: // import * as fs from "fs"; -let adapter: ioBroker.Adapter; - -/** - * Starts the adapter instance - */ -function startAdapter(options: Partial = {}): ioBroker.Adapter { - // Create the adapter and define its methods - return adapter = utils.adapter({ - // Default options - ...options, - // custom options - name: "test-adapter", - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with `adapter.subscribeObjects`, similar to `adapter.subscribeStates`. - // objectChange: (id, obj) => { - // if (obj) { - // // The object was changed - // adapter.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // adapter.log.info(`object ${id} deleted`); - // } - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - adapter.log.info(`state ${id} deleted`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // if (typeof obj === "object" && obj.message) { - // if (obj.command === "send") { - // // e.g. send email or pushover or whatever - // adapter.log.info("send command"); - - // // Send response in callback if required - // if (obj.callback) adapter.sendTo(obj.from, obj.command, "Message received", obj.callback); - // } - // } - // }, - }); -} - -async function main(): Promise { - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: - adapter.log.info("config option1: " + adapter.config.option1); - adapter.log.info("config option2: " + adapter.config.option2); - - /* +class TestAdapter extends utils.Adapter { + + public constructor(options: Partial = {}) { + super({ + ...options, + name: "test-adapter", + }); + this.on("ready", this.onReady.bind(this)); + this.on("stateChange", this.onStateChange.bind(this)); + // this.on("objectChange", this.onObjectChange.bind(this)); + // this.on("message", this.onMessage.bind(this)); + this.on("unload", this.onUnload.bind(this)); + } + + /** + * Is called when databases are connected and adapter received configuration. + */ + private async onReady(): Promise { + // Initialize your adapter here + + // The adapters config (in the instance object everything under the attribute "native") is accessible via + // this.config: + this.log.info("config option1: " + this.config.option1); + this.log.info("config option2: " + this.config.option2); + + /* For every state in the system there has to be also an object of type state Here a simple template for a boolean variable named "testVariable" Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates("lights.*"); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates("*"); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword("admin", "iobroker", (res) => { - adapter.log.info("check user admin pw iobroker: " + res); - }); - - adapter.checkGroup("admin", "admin", (res) => { - adapter.log.info("check group user admin group admin: " + res); - }); + */ + await this.setObjectNotExistsAsync("testVariable", { + type: "state", + common: { + name: "testVariable", + type: "boolean", + role: "indicator", + read: true, + write: true, + }, + native: {}, + }); + + // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. + this.subscribeStates("testVariable"); + // You can also add a subscription for multiple states. The following line watches all states starting with "lights." + // this.subscribeStates("lights.*"); + // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: + // this.subscribeStates("*"); + + /* + setState examples + you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) + */ + // the variable testVariable is set to true as command (ack=false) + await this.setStateAsync("testVariable", true); + + // same thing, but the value is flagged "ack" + // ack should be always set to true if the value is received from or acknowledged from the target system + await this.setStateAsync("testVariable", { val: true, ack: true }); + + // same thing, but the state is deleted after 30s (getState will return null afterwards) + await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); + + // examples for the checkPassword/checkGroup functions + let result = await this.checkPasswordAsync("admin", "iobroker"); + this.log.info("check user admin pw iobroker: " + result); + + result = await this.checkGroupAsync("admin", "admin"); + this.log.info("check group user admin group admin: " + result); + } + + /** + * Is called when adapter shuts down - callback has to be called under any circumstances! + */ + private onUnload(callback: () => void): void { + try { + // Here you must clear all timeouts or intervals that may still be active + // clearTimeout(timeout1); + // clearTimeout(timeout2); + // ... + // clearInterval(interval1); + + callback(); + } catch (e) { + callback(); + } + } + + // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. + // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. + // /** + // * Is called if a subscribed object changes + // */ + // private onObjectChange(id: string, obj: ioBroker.Object | null | undefined): void { + // if (obj) { + // // The object was changed + // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); + // } else { + // // The object was deleted + // this.log.info(`object ${id} deleted`); + // } + // } + + /** + * Is called if a subscribed state changes + */ + private onStateChange(id: string, state: ioBroker.State | null | undefined): void { + if (state) { + // The state was changed + this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); + } else { + // The state was deleted + this.log.info(`state ${id} deleted`); + } + } + + // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. + // /** + // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... + // * Using this method requires "common.messagebox" property to be set to true in io-package.json + // */ + // private onMessage(obj: ioBroker.Message): void { + // if (typeof obj === "object" && obj.message) { + // if (obj.command === "send") { + // // e.g. send email or pushover or whatever + // this.log.info("send command"); + + // // Send response in callback if required + // if (obj.callback) this.sendTo(obj.from, obj.command, "Message received", obj.callback); + // } + // } + // } + } if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; + // Export the constructor in compact mode + module.exports = (options: Partial | undefined) => new TestAdapter(options); } else { // otherwise start the instance directly - startAdapter(); + (() => new TestAdapter())(); } \ No newline at end of file diff --git a/test/baselines/adapter_TS_React/.create-adapter.json b/test/baselines/adapter_TS_React/.create-adapter.json index 22358e29..a34c183c 100644 --- a/test/baselines/adapter_TS_React/.create-adapter.json +++ b/test/baselines/adapter_TS_React/.create-adapter.json @@ -21,7 +21,6 @@ ], "indentation": "Tab", "quotes": "double", - "es6class": "yes", "authorName": "Al Calzone", "authorGithub": "AlCalzone", "authorEmail": "al@calzo.ne", diff --git a/test/baselines/connectionIndicator_yes/src/main.ts b/test/baselines/connectionIndicator_yes/src/main.ts index 7374095b..a8cac4e0 100644 --- a/test/baselines/connectionIndicator_yes/src/main.ts +++ b/test/baselines/connectionIndicator_yes/src/main.ts @@ -9,142 +9,148 @@ import * as utils from "@iobroker/adapter-core"; // Load your modules here, e.g.: // import * as fs from "fs"; -let adapter: ioBroker.Adapter; - -/** - * Starts the adapter instance - */ -function startAdapter(options: Partial = {}): ioBroker.Adapter { - // Create the adapter and define its methods - return adapter = utils.adapter({ - // Default options - ...options, - // custom options - name: "test-adapter", - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with `adapter.subscribeObjects`, similar to `adapter.subscribeStates`. - // objectChange: (id, obj) => { - // if (obj) { - // // The object was changed - // adapter.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // adapter.log.info(`object ${id} deleted`); - // } - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - adapter.log.info(`state ${id} deleted`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // if (typeof obj === "object" && obj.message) { - // if (obj.command === "send") { - // // e.g. send email or pushover or whatever - // adapter.log.info("send command"); - - // // Send response in callback if required - // if (obj.callback) adapter.sendTo(obj.from, obj.command, "Message received", obj.callback); - // } - // } - // }, - }); -} - -async function main(): Promise { - - // Reset the connection indicator during startup - await this.setStateAsync("info.connection", false, true); - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: - adapter.log.info("config option1: " + adapter.config.option1); - adapter.log.info("config option2: " + adapter.config.option2); - - /* +class TestAdapter extends utils.Adapter { + + public constructor(options: Partial = {}) { + super({ + ...options, + name: "test-adapter", + }); + this.on("ready", this.onReady.bind(this)); + this.on("stateChange", this.onStateChange.bind(this)); + // this.on("objectChange", this.onObjectChange.bind(this)); + // this.on("message", this.onMessage.bind(this)); + this.on("unload", this.onUnload.bind(this)); + } + + /** + * Is called when databases are connected and adapter received configuration. + */ + private async onReady(): Promise { + // Initialize your adapter here + + // Reset the connection indicator during startup + this.setState("info.connection", false, true); + + // The adapters config (in the instance object everything under the attribute "native") is accessible via + // this.config: + this.log.info("config option1: " + this.config.option1); + this.log.info("config option2: " + this.config.option2); + + /* For every state in the system there has to be also an object of type state Here a simple template for a boolean variable named "testVariable" Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates("lights.*"); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates("*"); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword("admin", "iobroker", (res) => { - adapter.log.info("check user admin pw iobroker: " + res); - }); - - adapter.checkGroup("admin", "admin", (res) => { - adapter.log.info("check group user admin group admin: " + res); - }); + */ + await this.setObjectNotExistsAsync("testVariable", { + type: "state", + common: { + name: "testVariable", + type: "boolean", + role: "indicator", + read: true, + write: true, + }, + native: {}, + }); + + // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. + this.subscribeStates("testVariable"); + // You can also add a subscription for multiple states. The following line watches all states starting with "lights." + // this.subscribeStates("lights.*"); + // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: + // this.subscribeStates("*"); + + /* + setState examples + you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) + */ + // the variable testVariable is set to true as command (ack=false) + await this.setStateAsync("testVariable", true); + + // same thing, but the value is flagged "ack" + // ack should be always set to true if the value is received from or acknowledged from the target system + await this.setStateAsync("testVariable", { val: true, ack: true }); + + // same thing, but the state is deleted after 30s (getState will return null afterwards) + await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); + + // examples for the checkPassword/checkGroup functions + let result = await this.checkPasswordAsync("admin", "iobroker"); + this.log.info("check user admin pw iobroker: " + result); + + result = await this.checkGroupAsync("admin", "admin"); + this.log.info("check group user admin group admin: " + result); + } + + /** + * Is called when adapter shuts down - callback has to be called under any circumstances! + */ + private onUnload(callback: () => void): void { + try { + // Here you must clear all timeouts or intervals that may still be active + // clearTimeout(timeout1); + // clearTimeout(timeout2); + // ... + // clearInterval(interval1); + + callback(); + } catch (e) { + callback(); + } + } + + // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. + // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. + // /** + // * Is called if a subscribed object changes + // */ + // private onObjectChange(id: string, obj: ioBroker.Object | null | undefined): void { + // if (obj) { + // // The object was changed + // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); + // } else { + // // The object was deleted + // this.log.info(`object ${id} deleted`); + // } + // } + + /** + * Is called if a subscribed state changes + */ + private onStateChange(id: string, state: ioBroker.State | null | undefined): void { + if (state) { + // The state was changed + this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); + } else { + // The state was deleted + this.log.info(`state ${id} deleted`); + } + } + + // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. + // /** + // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... + // * Using this method requires "common.messagebox" property to be set to true in io-package.json + // */ + // private onMessage(obj: ioBroker.Message): void { + // if (typeof obj === "object" && obj.message) { + // if (obj.command === "send") { + // // e.g. send email or pushover or whatever + // this.log.info("send command"); + + // // Send response in callback if required + // if (obj.callback) this.sendTo(obj.from, obj.command, "Message received", obj.callback); + // } + // } + // } + } if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; + // Export the constructor in compact mode + module.exports = (options: Partial | undefined) => new TestAdapter(options); } else { // otherwise start the instance directly - startAdapter(); + (() => new TestAdapter())(); } \ No newline at end of file diff --git a/test/baselines/customAdapterSettings/src/main.ts b/test/baselines/customAdapterSettings/src/main.ts index 203f716b..ab267142 100644 --- a/test/baselines/customAdapterSettings/src/main.ts +++ b/test/baselines/customAdapterSettings/src/main.ts @@ -9,139 +9,145 @@ import * as utils from "@iobroker/adapter-core"; // Load your modules here, e.g.: // import * as fs from "fs"; -let adapter: ioBroker.Adapter; - -/** - * Starts the adapter instance - */ -function startAdapter(options: Partial = {}): ioBroker.Adapter { - // Create the adapter and define its methods - return adapter = utils.adapter({ - // Default options - ...options, - // custom options - name: "test-adapter", - - // The ready callback is called when databases are connected and adapter received configuration. - // start here! - ready: main, // Main method defined below for readability - - // is called when adapter shuts down - callback has to be called under any circumstances! - unload: (callback) => { - try { - // Here you must clear all timeouts or intervals that may still be active - // clearTimeout(timeout1); - // clearTimeout(timeout2); - // ... - // clearInterval(interval1); - - callback(); - } catch (e) { - callback(); - } - }, - - // If you need to react to object changes, uncomment the following method. - // You also need to subscribe to the objects with `adapter.subscribeObjects`, similar to `adapter.subscribeStates`. - // objectChange: (id, obj) => { - // if (obj) { - // // The object was changed - // adapter.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); - // } else { - // // The object was deleted - // adapter.log.info(`object ${id} deleted`); - // } - // }, - - // is called if a subscribed state changes - stateChange: (id, state) => { - if (state) { - // The state was changed - adapter.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); - } else { - // The state was deleted - adapter.log.info(`state ${id} deleted`); - } - }, - - // If you need to accept messages in your adapter, uncomment the following block. - // /** - // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... - // * Using this method requires "common.messagebox" property to be set to true in io-package.json - // */ - // message: (obj) => { - // if (typeof obj === "object" && obj.message) { - // if (obj.command === "send") { - // // e.g. send email or pushover or whatever - // adapter.log.info("send command"); - - // // Send response in callback if required - // if (obj.callback) adapter.sendTo(obj.from, obj.command, "Message received", obj.callback); - // } - // } - // }, - }); -} - -async function main(): Promise { - - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: - adapter.log.info("config prop1: " + adapter.config.prop1); - adapter.log.info("config prop2: " + adapter.config.prop2); - - /* +class TestAdapter extends utils.Adapter { + + public constructor(options: Partial = {}) { + super({ + ...options, + name: "test-adapter", + }); + this.on("ready", this.onReady.bind(this)); + this.on("stateChange", this.onStateChange.bind(this)); + // this.on("objectChange", this.onObjectChange.bind(this)); + // this.on("message", this.onMessage.bind(this)); + this.on("unload", this.onUnload.bind(this)); + } + + /** + * Is called when databases are connected and adapter received configuration. + */ + private async onReady(): Promise { + // Initialize your adapter here + + // The adapters config (in the instance object everything under the attribute "native") is accessible via + // this.config: + this.log.info("config prop1: " + this.config.prop1); + this.log.info("config prop2: " + this.config.prop2); + + /* For every state in the system there has to be also an object of type state Here a simple template for a boolean variable named "testVariable" Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - */ - await adapter.setObjectNotExistsAsync("testVariable", { - type: "state", - common: { - name: "testVariable", - type: "boolean", - role: "indicator", - read: true, - write: true, - }, - native: {}, - }); - - // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. - adapter.subscribeStates("testVariable"); - // You can also add a subscription for multiple states. The following line watches all states starting with "lights." - // adapter.subscribeStates("lights.*"); - // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: - // adapter.subscribeStates("*"); - - /* - setState examples - you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - */ - // the variable testVariable is set to true as command (ack=false) - await adapter.setStateAsync("testVariable", true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - await adapter.setStateAsync("testVariable", { val: true, ack: true }); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - await adapter.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword("admin", "iobroker", (res) => { - adapter.log.info("check user admin pw iobroker: " + res); - }); - - adapter.checkGroup("admin", "admin", (res) => { - adapter.log.info("check group user admin group admin: " + res); - }); + */ + await this.setObjectNotExistsAsync("testVariable", { + type: "state", + common: { + name: "testVariable", + type: "boolean", + role: "indicator", + read: true, + write: true, + }, + native: {}, + }); + + // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above. + this.subscribeStates("testVariable"); + // You can also add a subscription for multiple states. The following line watches all states starting with "lights." + // this.subscribeStates("lights.*"); + // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system: + // this.subscribeStates("*"); + + /* + setState examples + you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) + */ + // the variable testVariable is set to true as command (ack=false) + await this.setStateAsync("testVariable", true); + + // same thing, but the value is flagged "ack" + // ack should be always set to true if the value is received from or acknowledged from the target system + await this.setStateAsync("testVariable", { val: true, ack: true }); + + // same thing, but the state is deleted after 30s (getState will return null afterwards) + await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); + + // examples for the checkPassword/checkGroup functions + let result = await this.checkPasswordAsync("admin", "iobroker"); + this.log.info("check user admin pw iobroker: " + result); + + result = await this.checkGroupAsync("admin", "admin"); + this.log.info("check group user admin group admin: " + result); + } + + /** + * Is called when adapter shuts down - callback has to be called under any circumstances! + */ + private onUnload(callback: () => void): void { + try { + // Here you must clear all timeouts or intervals that may still be active + // clearTimeout(timeout1); + // clearTimeout(timeout2); + // ... + // clearInterval(interval1); + + callback(); + } catch (e) { + callback(); + } + } + + // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor. + // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`. + // /** + // * Is called if a subscribed object changes + // */ + // private onObjectChange(id: string, obj: ioBroker.Object | null | undefined): void { + // if (obj) { + // // The object was changed + // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`); + // } else { + // // The object was deleted + // this.log.info(`object ${id} deleted`); + // } + // } + + /** + * Is called if a subscribed state changes + */ + private onStateChange(id: string, state: ioBroker.State | null | undefined): void { + if (state) { + // The state was changed + this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`); + } else { + // The state was deleted + this.log.info(`state ${id} deleted`); + } + } + + // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor. + // /** + // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... + // * Using this method requires "common.messagebox" property to be set to true in io-package.json + // */ + // private onMessage(obj: ioBroker.Message): void { + // if (typeof obj === "object" && obj.message) { + // if (obj.command === "send") { + // // e.g. send email or pushover or whatever + // this.log.info("send command"); + + // // Send response in callback if required + // if (obj.callback) this.sendTo(obj.from, obj.command, "Message received", obj.callback); + // } + // } + // } + } if (require.main !== module) { - // Export startAdapter in compact mode - module.exports = startAdapter; + // Export the constructor in compact mode + module.exports = (options: Partial | undefined) => new TestAdapter(options); } else { // otherwise start the instance directly - startAdapter(); + (() => new TestAdapter())(); } \ No newline at end of file diff --git a/test/create-adapter.test.ts b/test/create-adapter.test.ts index 794dcbda..01b18170 100644 --- a/test/create-adapter.test.ts +++ b/test/create-adapter.test.ts @@ -121,7 +121,6 @@ const baseAnswers: Answers = { tools: ["ESLint"], indentation: "Tab", quotes: "double", - es6class: "no", authorName: "Al Calzone", authorGithub: "AlCalzone", authorEmail: "al@calzo.ne", @@ -225,21 +224,9 @@ describe("adapter creation =>", () => { ); }); - it("Adapter, TypeScript (ES6 class), ESLint, Tabs, Double quotes, MIT License", async () => { - const answers: Answers = { - ...baseAnswers, - es6class: "yes", - }; - await expectSuccess( - "adapter_TS_ES6Class_ESLint_Tabs_DoubleQuotes_MIT", - answers, - ); - }); - it("Adapter, TypeScript React", async () => { const answers: Answers = { ...baseAnswers, - es6class: "yes", adminUi: "react", }; await expectSuccess("adapter_TS_React", answers); @@ -249,7 +236,6 @@ describe("adapter creation =>", () => { const answers: Answers = { ...baseAnswers, language: "JavaScript", - es6class: "yes", adminUi: "react", }; await expectSuccess("adapter_JS_React", answers); @@ -271,22 +257,6 @@ describe("adapter creation =>", () => { ); }); - it("Adapter, JavaScript (ES6 class), ESLint, Spaces, Single quotes, Apache License", async () => { - const answers: Answers = { - ...baseAnswers, - language: "JavaScript", - tools: ["ESLint", "type checking"], - indentation: "Space (4)", - quotes: "single", - es6class: "yes", - license: "Apache License 2.0", - }; - await expectSuccess( - "adapter_JS_ES6Class_ESLint_TypeChecking_Spaces_SingleQuotes_Apache-2.0", - answers, - ); - }); - it("Widget", async () => { const answers: Answers = { cli: true, @@ -552,7 +522,6 @@ describe("adapter creation =>", () => { const answers: Answers = { ...baseAnswers, adminFeatures: ["tab"], - es6class: "yes", adminUi: "react", tabReact: "yes", }; @@ -670,20 +639,6 @@ describe("adapter creation =>", () => { file.name === "io-package.json", ); }); - - it(`JS with legacy main.js`, async () => { - const answers: Answers = { - ...baseAnswers, - language: "JavaScript", - es6class: "no", - connectionIndicator: "yes", - }; - await expectSuccess( - "JS_LegacyMain", - answers, - (file) => file.name === "main.js", - ); - }); }); }); });