iobroker.zigbee2mqtt 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/exposes.js CHANGED
@@ -87,6 +87,7 @@ function genState(expose, role, name, desc) {
87
87
 
88
88
  for (const val of expose.values) {
89
89
  state.states[val] = val;
90
+ state.type = typeof (val);
90
91
  }
91
92
 
92
93
  if (expose.endpoint) {
@@ -118,7 +119,7 @@ function genState(expose, role, name, desc) {
118
119
  return state;
119
120
  }
120
121
 
121
- function createFromExposes(deviceID, ieee_address, definitions, power_source) {
122
+ function createFromExposes(deviceID, ieee_address, definitions, power_source, scenes, useKelvin) {
122
123
  const states = [];
123
124
  // make the different (set and get) part of state is updatable if different exposes is used for get and set
124
125
  // as example:
@@ -282,6 +283,7 @@ function createFromExposes(deviceID, ieee_address, definitions, power_source) {
282
283
  min: 0, // ignore expose.value_min
283
284
  max: 100, // ignore expose.value_max
284
285
  inOptions: true,
286
+ unit: '%',
285
287
  getter: (value) => {
286
288
  return utils.bulbLevelToAdapterLevel(value[stateNameB]);
287
289
  },
@@ -318,10 +320,9 @@ function createFromExposes(deviceID, ieee_address, definitions, power_source) {
318
320
  write: true,
319
321
  read: true,
320
322
  type: 'number',
321
- // Ignore min and max value, so setting mireds and Kelvin with conversion to mireds works.
322
- // https://github.com/ioBroker/ioBroker.zigbee/pull/1433#issuecomment-1113837035
323
- min: undefined,
324
- max: undefined,
323
+ min: undefined, //useKelvin == true ? expose.value_min : utils.miredKelvinConversion(expose.value_min),
324
+ max: undefined, //useKelvin == true ? expose.value_min : utils.miredKelvinConversion(expose.value_max),
325
+ unit: useKelvin == true ? 'K' : 'mired',
325
326
  setter: (value) => {
326
327
  return utils.toMired(value);
327
328
  },
@@ -330,6 +331,14 @@ function createFromExposes(deviceID, ieee_address, definitions, power_source) {
330
331
  const transitionTime = hasTransitionTime ? options.transition_time : 0;
331
332
  return { ...options, transition: transitionTime };
332
333
  },
334
+ getter: (payload) => {
335
+ if (useKelvin == true) {
336
+ return utils.miredKelvinConversion(payload.color_temp);
337
+ }
338
+ else {
339
+ return payload.color_temp;
340
+ }
341
+ },
333
342
  epname: expose.endpoint,
334
343
  setattr: 'color_temp',
335
344
  }, prop.access);
@@ -377,163 +386,164 @@ function createFromExposes(deviceID, ieee_address, definitions, power_source) {
377
386
  }, 2);
378
387
  break;
379
388
  }
380
- case 'color_hs': {
381
- const stateNameH = expose.endpoint ? `color_${expose.endpoint}` : 'color';
382
- pushToStates({
383
- id: stateNameH,
384
- prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
385
- name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
386
- icon: undefined,
387
- role: 'level.color.rgb',
388
- write: true,
389
- read: true,
390
- type: 'string',
391
- setter: (value) => {
392
- const _rgb = colors.ParseColor(value);
393
- const hsv = rgb.rgbToHSV(_rgb.r, _rgb.g, _rgb.b, true);
394
- return {
395
- hue: Math.min(Math.max(hsv.h, 1), 359),
396
- saturation: hsv.s,
397
- // brightness: Math.floor(hsv.v * 2.55),
398
-
399
- };
400
- },
401
- setterOpt: (_value, options) => {
402
- const hasTransitionTime = options && options.hasOwnProperty('transition_time');
403
- const transitionTime = hasTransitionTime ? options.transition_time : 0;
404
- return { ...options, transition: transitionTime };
405
- },
406
- epname: expose.endpoint,
407
- setattr: 'color',
408
- }, prop.access);
409
- pushToStates({
410
- id: expose.endpoint ? `hue_${expose.endpoint}` : 'hue',
411
- prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
412
- name: `Hue ${expose.endpoint ? expose.endpoint : ''}`.trim(),
413
- icon: undefined,
414
- role: 'level.color.hue',
415
- write: true,
416
- read: false,
417
- type: 'number',
418
- min: 0,
419
- max: 360,
420
- inOptions: true,
421
- setter: (value, options) => {
422
- return {
423
- hue: value,
424
- saturation: options.saturation,
425
- };
426
- },
427
- setterOpt: (_value, options) => {
428
- const hasTransitionTime = options && options.hasOwnProperty('transition_time');
429
- const transitionTime = hasTransitionTime ? options.transition_time : 0;
430
- const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
431
- if (hasHueCalibrationTable)
432
- try {
433
- return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
434
- }
435
- catch (err) {
436
- const hue_correction_table = [];
437
- options.hue_calibration.split(',').forEach(element => {
438
- const match = /([0-9]+):([0-9]+)/.exec(element);
439
- if (match && match.length == 3)
440
- hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
441
- });
442
- if (hue_correction_table.length > 0)
443
- return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
444
- }
445
- return { ...options, transition: transitionTime };
446
- },
447
-
448
- }, prop.access);
449
- pushToStates({
450
- id: expose.endpoint ? `saturation_${expose.endpoint}` : 'saturation',
451
- prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
452
- name: `Saturation ${expose.endpoint ? expose.endpoint : ''}`.trim(),
453
- icon: undefined,
454
- role: 'level.color.saturation',
455
- write: true,
456
- read: false,
457
- type: 'number',
458
- min: 0,
459
- max: 100,
460
- inOptions: true,
461
- setter: (value, options) => {
462
- return {
463
- hue: options.hue,
464
- saturation: value,
465
- };
466
- },
467
- setterOpt: (_value, options) => {
468
- const hasTransitionTime = options && options.hasOwnProperty('transition_time');
469
- const transitionTime = hasTransitionTime ? options.transition_time : 0;
470
- const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
471
- if (hasHueCalibrationTable)
472
- try {
473
- return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
474
- }
475
- catch (err) {
476
- const hue_correction_table = [];
477
- options.hue_calibration.split(',').forEach(element => {
478
- const match = /([0-9]+):([0-9]+)/.exec(element);
479
- if (match && match.length == 3)
480
- hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
481
- });
482
- if (hue_correction_table.length > 0)
483
- return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
484
- }
485
- return { ...options, transition: transitionTime };
486
- },
487
-
488
- }, prop.access);
489
- pushToStates(statesDefs.hue_move, prop.access);
490
- pushToStates(statesDefs.saturation_move, prop.access);
491
- pushToStates({
492
- id: 'hue_calibration',
493
- prop: 'color',
494
- name: 'Hue color calibration table',
495
- icon: undefined,
496
- role: 'table',
497
- write: true,
498
- read: false,
499
- type: 'string',
500
- inOptions: true,
501
- setter: (_value, options) => {
502
- return {
503
- hue: options.hue,
504
- saturation: options.saturation,
505
- };
506
- },
507
- setterOpt: (_value, options) => {
508
- const hasTransitionTime = options && options.hasOwnProperty('transition_time');
509
- const transitionTime = hasTransitionTime ? options.transition_time : 0;
510
- const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
511
- if (hasHueCalibrationTable)
512
- try {
513
- return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
514
- }
515
- catch (err) {
516
- const hue_correction_table = [];
517
- options.hue_calibration.split(',').forEach(element => {
518
- const match = /([0-9]+):([0-9]+)/.exec(element);
519
- if (match && match.length == 3)
520
- hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
521
- });
522
- if (hue_correction_table.length > 0)
523
- return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
524
- }
525
- return { ...options, transition: transitionTime };
526
- },
527
-
528
- }, prop.access);
529
- break;
530
- }
389
+ // case 'color_hs': {
390
+ // const stateNameH = expose.endpoint ? `color_${expose.endpoint}` : 'color';
391
+ // pushToStates({
392
+ // id: stateNameH,
393
+ // prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
394
+ // name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
395
+ // icon: undefined,
396
+ // role: 'level.color.rgb',
397
+ // write: true,
398
+ // read: true,
399
+ // type: 'string',
400
+ // setter: (value) => {
401
+ // const _rgb = colors.ParseColor(value);
402
+ // const hsv = rgb.rgbToHSV(_rgb.r, _rgb.g, _rgb.b, true);
403
+ // return {
404
+ // hue: Math.min(Math.max(hsv.h, 1), 359),
405
+ // saturation: hsv.s,
406
+ // // brightness: Math.floor(hsv.v * 2.55),
407
+
408
+ // };
409
+ // },
410
+ // setterOpt: (_value, options) => {
411
+ // const hasTransitionTime = options && options.hasOwnProperty('transition_time');
412
+ // const transitionTime = hasTransitionTime ? options.transition_time : 0;
413
+ // return { ...options, transition: transitionTime };
414
+ // },
415
+ // epname: expose.endpoint,
416
+ // setattr: 'color',
417
+ // }, prop.access);
418
+ // pushToStates({
419
+ // id: expose.endpoint ? `hue_${expose.endpoint}` : 'hue',
420
+ // prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
421
+ // name: `Hue ${expose.endpoint ? expose.endpoint : ''}`.trim(),
422
+ // icon: undefined,
423
+ // role: 'level.color.hue',
424
+ // write: true,
425
+ // read: false,
426
+ // type: 'number',
427
+ // min: 0,
428
+ // max: 360,
429
+ // inOptions: true,
430
+ // setter: (value, options) => {
431
+ // return {
432
+ // hue: value,
433
+ // saturation: options.saturation,
434
+ // };
435
+ // },
436
+ // setterOpt: (_value, options) => {
437
+ // const hasTransitionTime = options && options.hasOwnProperty('transition_time');
438
+ // const transitionTime = hasTransitionTime ? options.transition_time : 0;
439
+ // const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
440
+ // if (hasHueCalibrationTable)
441
+ // try {
442
+ // return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
443
+ // }
444
+ // catch (err) {
445
+ // const hue_correction_table = [];
446
+ // options.hue_calibration.split(',').forEach(element => {
447
+ // const match = /([0-9]+):([0-9]+)/.exec(element);
448
+ // if (match && match.length == 3)
449
+ // hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
450
+ // });
451
+ // if (hue_correction_table.length > 0)
452
+ // return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
453
+ // }
454
+ // return { ...options, transition: transitionTime };
455
+ // },
456
+
457
+ // }, prop.access);
458
+ // pushToStates({
459
+ // id: expose.endpoint ? `saturation_${expose.endpoint}` : 'saturation',
460
+ // prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
461
+ // name: `Saturation ${expose.endpoint ? expose.endpoint : ''}`.trim(),
462
+ // icon: undefined,
463
+ // role: 'level.color.saturation',
464
+ // write: true,
465
+ // read: false,
466
+ // type: 'number',
467
+ // min: 0,
468
+ // max: 100,
469
+ // inOptions: true,
470
+ // setter: (value, options) => {
471
+ // return {
472
+ // hue: options.hue,
473
+ // saturation: value,
474
+ // };
475
+ // },
476
+ // setterOpt: (_value, options) => {
477
+ // const hasTransitionTime = options && options.hasOwnProperty('transition_time');
478
+ // const transitionTime = hasTransitionTime ? options.transition_time : 0;
479
+ // const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
480
+ // if (hasHueCalibrationTable)
481
+ // try {
482
+ // return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
483
+ // }
484
+ // catch (err) {
485
+ // const hue_correction_table = [];
486
+ // options.hue_calibration.split(',').forEach(element => {
487
+ // const match = /([0-9]+):([0-9]+)/.exec(element);
488
+ // if (match && match.length == 3)
489
+ // hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
490
+ // });
491
+ // if (hue_correction_table.length > 0)
492
+ // return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
493
+ // }
494
+ // return { ...options, transition: transitionTime };
495
+ // },
496
+
497
+ // }, prop.access);
498
+ // pushToStates(statesDefs.hue_move, prop.access);
499
+ // pushToStates(statesDefs.saturation_move, prop.access);
500
+ // pushToStates({
501
+ // id: 'hue_calibration',
502
+ // prop: 'color',
503
+ // name: 'Hue color calibration table',
504
+ // icon: undefined,
505
+ // role: 'table',
506
+ // write: true,
507
+ // read: false,
508
+ // type: 'string',
509
+ // inOptions: true,
510
+ // setter: (_value, options) => {
511
+ // return {
512
+ // hue: options.hue,
513
+ // saturation: options.saturation,
514
+ // };
515
+ // },
516
+ // setterOpt: (_value, options) => {
517
+ // const hasTransitionTime = options && options.hasOwnProperty('transition_time');
518
+ // const transitionTime = hasTransitionTime ? options.transition_time : 0;
519
+ // const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
520
+ // if (hasHueCalibrationTable)
521
+ // try {
522
+ // return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
523
+ // }
524
+ // catch (err) {
525
+ // const hue_correction_table = [];
526
+ // options.hue_calibration.split(',').forEach(element => {
527
+ // const match = /([0-9]+):([0-9]+)/.exec(element);
528
+ // if (match && match.length == 3)
529
+ // hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
530
+ // });
531
+ // if (hue_correction_table.length > 0)
532
+ // return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
533
+ // }
534
+ // return { ...options, transition: transitionTime };
535
+ // },
536
+
537
+ // }, prop.access);
538
+ // break;
539
+ // }
531
540
  default:
532
541
  pushToStates(genState(prop), prop.access);
533
542
  break;
534
543
  }
535
544
  }
536
- pushToStates(statesDefs.transition_time, 2);
545
+ // First don't create a transition_time datapoint, this will be set in the backend
546
+ //pushToStates(statesDefs.transition_time, 2);
537
547
  break;
538
548
 
539
549
  case 'switch':
@@ -720,8 +730,13 @@ function createFromExposes(deviceID, ieee_address, definitions, power_source) {
720
730
  case 'running_mode':
721
731
  pushToStates(statesDefs.climate_running_mode, prop.access);
722
732
  break;
723
- default:
724
- pushToStates(genState(prop), prop.access);
733
+ default: {
734
+ if (prop.name.includes('heating_setpoint')) {
735
+ pushToStates(genState(prop, 'level.temperature'), prop.access);
736
+ } else {
737
+ pushToStates(genState(prop), prop.access);
738
+ }
739
+ }
725
740
  break;
726
741
  }
727
742
  }
@@ -776,7 +791,7 @@ function createFromExposes(deviceID, ieee_address, definitions, power_source) {
776
791
  // Add default states
777
792
  pushToStates(statesDefs.available, 1);
778
793
 
779
- const newDev = {
794
+ const newDevice = {
780
795
  id: deviceID,
781
796
  ieee_address: ieee_address,
782
797
  icon: icon,
@@ -784,14 +799,31 @@ function createFromExposes(deviceID, ieee_address, definitions, power_source) {
784
799
  states: states,
785
800
  };
786
801
 
787
- return newDev;
802
+ // Create buttons for scenes
803
+ for (const scene of scenes) {
804
+ const sceneSate = {
805
+ id: `scene_${scene.id}`,
806
+ prop: `scene_recall`,
807
+ name: scene.name,
808
+ icon: undefined,
809
+ role: 'button',
810
+ write: true,
811
+ read: true,
812
+ type: 'boolean',
813
+ setter: (value) => (value) ? scene.id : undefined
814
+ };
815
+ // @ts-ignore
816
+ newDevice.states.push(sceneSate);
817
+ }
818
+
819
+ return newDevice;
788
820
  }
789
821
 
790
- function defineDeviceFromExposes(devices, deviceID, ieee_address, definitions, power_source) {
822
+ function defineDeviceFromExposes(devices, deviceID, ieee_address, definitions, power_source, scenes, useKelvin) {
791
823
  // if the device is already present in the cache, remove it
792
824
  utils.removeDeviceByIeee(devices, ieee_address);
793
825
  if (definitions.hasOwnProperty('exposes')) {
794
- const newDevice = createFromExposes(deviceID, ieee_address, definitions, power_source);
826
+ const newDevice = createFromExposes(deviceID, ieee_address, definitions, power_source, scenes, useKelvin);
795
827
  devices.push(newDevice);
796
828
  }
797
829
  }
package/lib/groups.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const states = require('./states').states;
2
2
  const utils = require('./utils');
3
3
 
4
- function defineGroupDevice(devices, groupID, ieee_address, scenes) {
4
+ function defineGroupDevice(devices, groupID, ieee_address, scenes, useKelvin) {
5
5
  const newDevice = {
6
6
  id: groupID,
7
7
  ieee_address: ieee_address,
@@ -9,15 +9,38 @@ function defineGroupDevice(devices, groupID, ieee_address, scenes) {
9
9
  states: [
10
10
  states.state,
11
11
  states.brightness,
12
- states.colortemp,
13
12
  states.color,
14
13
  states.brightness_move,
15
14
  states.colortemp_move,
16
- states.transition_time,
17
- //states.brightness_step
18
15
  ],
19
16
  };
20
17
 
18
+ const colortemp = {
19
+ id: 'colortemp',
20
+ prop: 'color_temp',
21
+ name: 'Color temperature',
22
+ icon: undefined,
23
+ role: 'level.color.temperature',
24
+ write: true,
25
+ read: true,
26
+ type: 'number',
27
+ unit: useKelvin == true ? 'K' : 'mired',
28
+ setter: (value) => {
29
+ return utils.toMired(value);
30
+ },
31
+ getter: (payload) => {
32
+ if (useKelvin == true) {
33
+ return utils.miredKelvinConversion(payload.color_temp);
34
+ }
35
+ else {
36
+ return payload.color_temp;
37
+ }
38
+ },
39
+ };
40
+
41
+ // @ts-ignore
42
+ newDevice.states.push(colortemp);
43
+
21
44
  // Create buttons for scenes
22
45
  for (const scene of scenes) {
23
46
  const sceneSate = {