|
1 | 1 | import fz from '../src/converters/fromZigbee';
|
2 | 2 | import {repInterval} from '../src/lib/constants';
|
3 | 3 | import {fromZigbee as lumiFz} from '../src/lib/lumi';
|
| 4 | +import {setupAttributes} from '../src/lib/modernExtend'; |
4 | 5 | import {philipsFz} from '../src/lib/philips';
|
5 | 6 | import {assertDefintion, mockDevice, reportingItem} from './utils';
|
6 | 7 |
|
@@ -429,4 +430,41 @@ describe('ModernExtend', () => {
|
429 | 430 | },
|
430 | 431 | });
|
431 | 432 | });
|
| 433 | + |
| 434 | + test('Setup attributes', async () => { |
| 435 | + const device = mockDevice({modelID: '', endpoints: [{inputClusters: ['haElectricalMeasurement']}]}); |
| 436 | + const deviceEp = device.endpoints[0]; |
| 437 | + const coordinator = mockDevice({modelID: '', endpoints: [{}]}); |
| 438 | + const coordinatorEp = coordinator.endpoints[0]; |
| 439 | + const config = {min: 0, max: 10, change: 1}; |
| 440 | + const expectedConfig = {maximumReportInterval: 10, minimumReportInterval: 0, reportableChange: 1}; |
| 441 | + |
| 442 | + await setupAttributes(deviceEp, coordinator.endpoints[0], 'haElectricalMeasurement', [ |
| 443 | + {attribute: '1', ...config}, |
| 444 | + {attribute: '2', ...config}, |
| 445 | + {attribute: '3', ...config}, |
| 446 | + {attribute: '4', ...config}, |
| 447 | + {attribute: '5', ...config}, |
| 448 | + {attribute: '6', ...config}, |
| 449 | + ]); |
| 450 | + |
| 451 | + expect(deviceEp.bind).toHaveBeenCalledTimes(1); |
| 452 | + expect(deviceEp.bind).toHaveBeenCalledWith('haElectricalMeasurement', coordinatorEp); |
| 453 | + |
| 454 | + expect(deviceEp.configureReporting).toHaveBeenCalledTimes(2); |
| 455 | + expect(deviceEp.configureReporting).toHaveBeenNthCalledWith(1, 'haElectricalMeasurement', [ |
| 456 | + {attribute: '1', ...expectedConfig}, |
| 457 | + {attribute: '2', ...expectedConfig}, |
| 458 | + {attribute: '3', ...expectedConfig}, |
| 459 | + {attribute: '4', ...expectedConfig}, |
| 460 | + ]); |
| 461 | + expect(deviceEp.configureReporting).toHaveBeenNthCalledWith(2, 'haElectricalMeasurement', [ |
| 462 | + {attribute: '5', ...expectedConfig}, |
| 463 | + {attribute: '6', ...expectedConfig}, |
| 464 | + ]); |
| 465 | + |
| 466 | + expect(deviceEp.read).toHaveBeenCalledTimes(2); |
| 467 | + expect(deviceEp.read).toHaveBeenNthCalledWith(1, 'haElectricalMeasurement', ['1', '2', '3', '4']); |
| 468 | + expect(deviceEp.read).toHaveBeenNthCalledWith(2, 'haElectricalMeasurement', ['5', '6']); |
| 469 | + }); |
432 | 470 | });
|
0 commit comments