import { type ActionContext, type DeviceDetails, type DeviceLoadContext, DeviceManagement, type JsonFormSchema, } from '../src'; import { type DeviceRefreshResponse } from '../src/types/base'; const demoFormSchema: JsonFormSchema = { type: 'tabs', items: { options1: { type: 'panel', label: 'Tab1', icon: 'base64 svg', // optional items: { myPort: { type: 'number', min: 1, max: 65565, 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 }, myType: { // name could support more than one levelhelperText newLine: true, // must start from new row 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 }, ], }, myBool: { type: 'checkbox', label: 'My checkbox', }, }, }, options2: { type: 'panel', label: 'Tab2', icon: 'base64 svg', // optional items: { secondPort: { type: 'number', min: 1, max: 65565, 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 }, secondType: { // name could support more than one levelhelperText newLine: true, // must start from new row 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 }, ], }, secondBool: { type: 'checkbox', label: 'Second checkbox', }, }, }, }, }; export class DmTestDeviceManagement extends DeviceManagement { protected loadDevices(context: DeviceLoadContext): void { context.addDevice({ id: 'test-123', identifier: 'test-123', name: 'Test 123', status: 'connected', actions: [ { id: 'update', icon: 'forward', handler: (deviceId: string): DeviceRefreshResponse<'adapter', string> => { this.log.info(`Update was pressed on ${deviceId}`); return { update: { id: 'test-123', identifier: 'test-123 (*)', name: `Updated name for ${deviceId}`, status: 'disconnected', }, }; }, }, ], }); context.addDevice({ id: 'test-345', identifier: 'test-345', name: 'Test 345', status: 'disconnected', hasDetails: true, actions: [ { id: 'info', icon: 'settings', // instead of handler, url can be provided to open a link when action is clicked url: 'https://www.iobroker.net', }, { id: 'infoTranslated', icon: 'info', // The URL can also be translated, so it can be different for different languages url: { en: 'https://www.iobroker.net/#en', de: 'https://www.iobroker.net/#de', ru: 'https://www.iobroker.net/#ru', 'zh-cn': 'https://www.iobroker.net/#zh-cn', }, }, ], }); context.addDevice({ id: 'test-789', identifier: 'test-789', name: 'Test 789', status: 'connected', actions: [ { id: 'play', icon: 'play', handler: (deviceId: string) => { this.log.info(`Play was pressed on ${deviceId}`); return { refresh: 'none' }; }, }, { id: 'pause', icon: 'pause', description: 'Pause device', handler: async (deviceId: string, context: ActionContext) => { this.log.info(`Pause was pressed on ${deviceId}`); const confirm = await context.showConfirmation('Do you want to refresh the device list only?'); return { refresh: confirm ? 'devices' : 'instance' }; }, }, { id: 'forward', icon: 'forward', description: 'Forward', }, ], }); context.addDevice({ id: 'test-ABC', identifier: 'test-ABC', name: 'Test ABC', status: 'connected', actions: [ { id: 'forms', icon: 'fab fa-wpforms', description: 'Show forms flow', handler: async (deviceId: string, context: ActionContext) => { 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!'); } else { await context.showMessage(`You entered: ${JSON.stringify(data)}`); } return { refresh: 'none' }; }, }, ], }); } protected override getDeviceDetails(id: string): Promise> { const schema: JsonFormSchema = { type: 'panel', items: { text1: { type: 'staticText', text: 'This is some description', sm: 12, }, button1: { type: 'sendto', label: 'Click me to send a message!', sm: 6, command: 'send', data: { hello: 'world' }, }, }, }; return Promise.resolve({ id, schema }); } }