Skip to content

Commit

Permalink
Updated JsonConfig schema
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 17, 2024
1 parent ceb5556 commit e9a5648
Show file tree
Hide file tree
Showing 18 changed files with 4,041 additions and 848 deletions.
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

9 changes: 0 additions & 9 deletions .prettierrc.js

This file was deleted.

10 changes: 5 additions & 5 deletions .releaseconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"all": true,
"plugins": ["license"],
"exec": {
"before_commit": "npm run build"
}
"all": true,
"plugins": ["license"],
"exec": {
"before_commit": "npm run build"
}
}
62 changes: 16 additions & 46 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,57 +1,27 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
import config from '@iobroker/eslint-config';

export default [
...config,
{
ignores: [
"build/",
".prettierrc.js",
"**/.eslintrc.js",
"examples/"
],
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.mjs', 'examples/dm-test.ts'],
},
tsconfigRootDir: import.meta.dirname,
},
},
},
...compat.extends("plugin:@typescript-eslint/recommended"),
{
settings: {},

// disable temporary the rule 'jsdoc/require-param' and enable 'jsdoc/require-jsdoc'
rules: {
"@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",
"no-var": "error",
"prefer-const": "error",
"no-trailing-spaces": "error",
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param': 'off',

'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ["**/*.test.ts", "**/*.tsx"],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
},
ignores: ['build/**/*', 'node_modules/**/*', 'tasks.js'],
},
];
150 changes: 79 additions & 71 deletions examples/dm-test.ts
Original file line number Diff line number Diff line change
@@ -1,117 +1,123 @@
import { ActionContext, DeviceDetails, DeviceManagement, DeviceRefresh } from "../src";
import * as base from "../src/types/base";
import {
type ActionContext,
type DeviceDetails,
DeviceManagement,
type DeviceRefresh,
type JsonFormSchema,
} from '../src';
import type * as base from '../src/types/base';

const demoFormSchema = {
type: "tabs",
const demoFormSchema: JsonFormSchema = {
type: 'tabs',
items: {
options1: {
type: "panel",
label: "Tab1",
icon: "base64 svg", // optional
type: 'panel',
label: 'Tab1',
icon: 'base64 svg', // optional
items: {
myPort: {
type: "number",
type: 'number',
min: 1,
max: 65565,
label: "Number",
label: 'Number',
sm: 6, // 1 - 12
// "validator": "'"!!data.name"'", // else error
hidden: "data.myType === 1", // hidden if myType is 1
disabled: "data.myType === 2", // disabled if myType is 2
hidden: 'data.myType === 1', // hidden if myType is 1
disabled: 'data.myType === 2', // disabled if myType is 2
},
myType: {
// name could support more than one levelhelperText
newLine: true, // must start from new row
type: "select",
label: "My Type",
type: 'select',
label: 'My Type',
sm: 6, // 1 - 12
options: [
{ label: "option 0", value: 0 },
{ label: "option 1", value: 1 },
{ label: "option 2", value: 2 },
{ label: 'option 0', value: 0 },
{ label: 'option 1', value: 1 },
{ label: 'option 2', value: 2 },
],
},
myBool: {
type: "checkbox",
label: "My checkbox",
type: 'checkbox',
label: 'My checkbox',
},
},
},
options2: {
type: "panel",
label: "Tab2",
icon: "base64 svg", // optional
type: 'panel',
label: 'Tab2',
icon: 'base64 svg', // optional
items: {
secondPort: {
type: "number",
type: 'number',
min: 1,
max: 65565,
label: "Second Number",
label: 'Second Number',
sm: 6, // 1 - 12
// "validator": "'"!!data.name"'", // else error
hidden: "data.secondType === 1", // hidden if myType is 1
disabled: "data.secondType === 2", // disabled if myType is 2
hidden: 'data.secondType === 1', // hidden if myType is 1
disabled: 'data.secondType === 2', // disabled if myType is 2
},
secondType: {
// name could support more than one levelhelperText
newLine: true, // must start from new row
type: "select",
label: "Second Type",
type: 'select',
label: 'Second Type',
sm: 6, // 1 - 12
options: [
{ label: "option 0", value: 0 },
{ label: "option 1", value: 1 },
{ label: "option 2", value: 2 },
{ label: 'option 0', value: 0 },
{ label: 'option 1', value: 1 },
{ label: 'option 2', value: 2 },
],
},
secondBool: {
type: "checkbox",
label: "Second checkbox",
type: 'checkbox',
label: 'Second checkbox',
},
},
},
},
};

class DmTestDeviceManagement extends DeviceManagement {
protected async listDevices(): Promise<base.DeviceInfo<"adapter">[]> {
return [
{ id: "test-123", name: "Test 123", status: "connected" },
{ id: "test-345", name: "Test 345", status: "disconnected", hasDetails: true, actions: [] },
export class DmTestDeviceManagement extends DeviceManagement {
protected listDevices(): Promise<base.DeviceInfo<'adapter'>[]> {
return Promise.resolve([
{ id: 'test-123', name: 'Test 123', status: 'connected' },
{ id: 'test-345', name: 'Test 345', status: 'disconnected', hasDetails: true, actions: [] },
{
id: "test-789",
name: "Test 789",
status: "connected",
id: 'test-789',
name: 'Test 789',
status: 'connected',
actions: [
{
id: "play",
icon: "fas fa-play",
id: 'play',
icon: 'fas fa-play',
},
{
id: "pause",
icon: "fa-pause",
description: "Pause device",
id: 'pause',
icon: 'fa-pause',
description: 'Pause device',
},
{
id: "forward",
icon: "forward",
description: "Forward",
id: 'forward',
icon: 'forward',
description: 'Forward',
},
],
},
{
id: "test-ABC",
name: "Test ABC",
status: "connected",
id: 'test-ABC',
name: 'Test ABC',
status: 'connected',
actions: [
{
id: "forms",
icon: "fab fa-wpforms",
description: "Show forms flow",
id: 'forms',
icon: 'fab fa-wpforms',
description: 'Show forms flow',
},
],
},
];
]);
}

protected override async handleDeviceAction(
Expand All @@ -120,45 +126,47 @@ class DmTestDeviceManagement extends DeviceManagement {
context: ActionContext,
): Promise<{ refresh: DeviceRefresh }> {
switch (actionId) {
case "play":
case 'play':
this.log.info(`Play was pressed on ${deviceId}`);
return { refresh: false };
case "pause":
case 'pause': {
this.log.info(`Pause was pressed on ${deviceId}`);
const confirm = await context.showConfirmation("Do you want to refresh the device only?");
return { refresh: confirm ? "device" : "instance" };
case "forms":
const confirm = await context.showConfirmation('Do you want to refresh the device only?');
return { refresh: confirm ? 'device' : 'instance' };
}
case 'forms': {
this.log.info(`Forms was pressed on ${deviceId}`);
const data = await context.showForm(demoFormSchema, { data: { myPort: 8081, secondPort: 8082 } });
if (!data) {
await context.showMessage("You cancelled the previous form!");
await context.showMessage('You cancelled the previous form!');
} else {
await context.showMessage(`You entered: ${JSON.stringify(data)}`);
}
return { refresh: false };
}
default:
throw new Error(`Unknown action ${actionId}`);
}
}

protected override async getDeviceDetails(id: string): Promise<DeviceDetails> {
const schema = {
type: "panel",
protected override getDeviceDetails(id: string): Promise<DeviceDetails> {
const schema: JsonFormSchema = {
type: 'panel',
items: {
text1: {
type: "staticText",
text: "This is some description",
type: 'staticText',
text: 'This is some description',
sm: 12,
},
button1: {
type: "sendTo",
label: "Click me to send a message!",
type: 'sendto',
label: 'Click me to send a message!',
sm: 6,
command: "send",
data: { hello: "world" },
command: 'send',
data: { hello: 'world' },
},
},
};
return { id, schema };
return Promise.resolve({ id, schema });
}
}
Loading

0 comments on commit e9a5648

Please sign in to comment.