2018-11-16 12:23:11 -07:00
|
|
|
const devices = require('zigbee-shepherd-converters').devices;
|
|
|
|
const HomeassistantExtension = require('../lib/extension/homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
const settings = require('../lib/util/settings');
|
2019-06-09 15:01:48 -07:00
|
|
|
const utils = require('./utils');
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
const WSDCGQ11LM = devices.find((d) => d.model === 'WSDCGQ11LM');
|
2019-02-23 08:02:45 -07:00
|
|
|
const SV01 = devices.find((d) => d.model === 'SV01');
|
2019-04-26 12:57:38 -07:00
|
|
|
const FAN99432 = devices.find((d) => d.model === '99432');
|
2018-11-16 12:23:11 -07:00
|
|
|
|
|
|
|
describe('HomeAssistant extension', () => {
|
2019-01-08 11:00:47 -07:00
|
|
|
let homeassistant = null;
|
|
|
|
let mqtt = null;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-06-09 15:01:48 -07:00
|
|
|
utils.stubLogger(jest);
|
|
|
|
|
2019-01-08 11:00:47 -07:00
|
|
|
mqtt = {
|
2019-03-09 15:34:19 -07:00
|
|
|
publish: jest.fn(),
|
2019-01-08 11:00:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
homeassistant = new HomeassistantExtension(null, mqtt, null, null);
|
2019-01-30 10:07:44 -07:00
|
|
|
homeassistant.zigbee2mqttVersion = 'test';
|
2019-01-08 11:00:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-03-09 15:34:19 -07:00
|
|
|
jest.restoreAllMocks();
|
2019-01-08 11:00:47 -07:00
|
|
|
});
|
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
it('Should have mapping for all devices supported by zigbee-shepherd-converters', () => {
|
|
|
|
const missing = [];
|
|
|
|
|
|
|
|
devices.forEach((d) => {
|
|
|
|
if (!homeassistant._getMapping()[d.model]) {
|
|
|
|
missing.push(d.model);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-09 14:12:10 -07:00
|
|
|
expect(missing).toHaveLength(0);
|
|
|
|
}
|
|
|
|
);
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
it('Should discover devices', () => {
|
|
|
|
let payload = null;
|
2019-03-09 20:11:50 -07:00
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({friendly_name: 'my_device'});
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 1
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '°C',
|
|
|
|
'device_class': 'temperature',
|
|
|
|
'value_template': '{{ value_json.temperature }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_temperature',
|
|
|
|
'unique_id': '0x12345678_temperature_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[0][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[0][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 2
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '%',
|
|
|
|
'device_class': 'humidity',
|
|
|
|
'value_template': '{{ value_json.humidity }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_humidity',
|
|
|
|
'unique_id': '0x12345678_humidity_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[1][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[1][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[1][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[1][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 3
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': 'hPa',
|
|
|
|
'device_class': 'pressure',
|
|
|
|
'value_template': '{{ value_json.pressure }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_pressure',
|
|
|
|
'unique_id': '0x12345678_pressure_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[2][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[2][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[2][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[2][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 4
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '%',
|
|
|
|
'device_class': 'battery',
|
|
|
|
'value_template': '{{ value_json.battery }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_battery',
|
|
|
|
'unique_id': '0x12345678_battery_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[3][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[3][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[3][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[3][4]).toBe('homeassistant');
|
2019-02-20 12:10:38 -07:00
|
|
|
|
|
|
|
// 5
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '-',
|
|
|
|
'value_template': '{{ value_json.linkquality }}',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_linkquality',
|
|
|
|
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-20 12:10:38 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[4][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[4][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[4][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[4][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should discover devices with precision', () => {
|
|
|
|
let payload = null;
|
2019-03-09 20:11:50 -07:00
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({
|
|
|
|
friendly_name: 'my_device',
|
|
|
|
humidity_precision: 0,
|
|
|
|
temperature_precision: 1,
|
|
|
|
pressure_precision: 2,
|
2019-01-08 11:00:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 1
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '°C',
|
|
|
|
'device_class': 'temperature',
|
|
|
|
'value_template': '{{ (value_json.temperature | float) | round(1) }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_temperature',
|
|
|
|
'unique_id': '0x12345678_temperature_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[0][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[0][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 2
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '%',
|
|
|
|
'device_class': 'humidity',
|
|
|
|
'value_template': '{{ (value_json.humidity | float) | round(0) }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_humidity',
|
|
|
|
'unique_id': '0x12345678_humidity_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[1][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[1][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[1][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[1][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 3
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': 'hPa',
|
|
|
|
'device_class': 'pressure',
|
|
|
|
'value_template': '{{ (value_json.pressure | float) | round(2) }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_pressure',
|
|
|
|
'unique_id': '0x12345678_pressure_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[2][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[2][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[2][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[2][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
|
|
|
|
// 4
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '%',
|
|
|
|
'device_class': 'battery',
|
|
|
|
'value_template': '{{ value_json.battery }}',
|
2019-01-14 10:04:33 -07:00
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
2019-01-08 11:00:47 -07:00
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_battery',
|
|
|
|
'unique_id': '0x12345678_battery_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-01-08 11:00:47 -07:00
|
|
|
'name': 'my_device',
|
2019-01-30 10:07:44 -07:00
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
2019-01-08 11:00:47 -07:00
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[3][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[3][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[3][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[3][4]).toBe('homeassistant');
|
2019-02-20 12:10:38 -07:00
|
|
|
|
|
|
|
// 5
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '-',
|
|
|
|
'value_template': '{{ value_json.linkquality }}',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_linkquality',
|
|
|
|
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-20 12:10:38 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[4][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[4][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[4][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[4][4]).toBe('homeassistant');
|
2019-01-08 11:00:47 -07:00
|
|
|
});
|
2019-02-09 11:42:31 -07:00
|
|
|
|
|
|
|
it('Should discover devices with overriden user configuration', () => {
|
|
|
|
let payload = null;
|
2019-03-09 20:11:50 -07:00
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({
|
|
|
|
friendly_name: 'my_device',
|
|
|
|
homeassistant: {
|
|
|
|
expire_after: 30,
|
|
|
|
icon: 'mdi:test',
|
|
|
|
temperature: {
|
|
|
|
expire_after: 90,
|
2019-02-09 11:42:31 -07:00
|
|
|
},
|
2019-03-09 20:11:50 -07:00
|
|
|
},
|
2019-02-09 11:42:31 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
2019-02-09 11:42:31 -07:00
|
|
|
|
|
|
|
// 1
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '°C',
|
|
|
|
'device_class': 'temperature',
|
|
|
|
'value_template': '{{ value_json.temperature }}',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_temperature',
|
|
|
|
'unique_id': '0x12345678_temperature_zigbee2mqtt',
|
|
|
|
'expire_after': 90,
|
|
|
|
'icon': 'mdi:test',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-09 11:42:31 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[0][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[0][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
2019-02-09 11:42:31 -07:00
|
|
|
|
|
|
|
// 2
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '%',
|
|
|
|
'device_class': 'humidity',
|
|
|
|
'value_template': '{{ value_json.humidity }}',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_humidity',
|
|
|
|
'unique_id': '0x12345678_humidity_zigbee2mqtt',
|
|
|
|
'expire_after': 30,
|
|
|
|
'icon': 'mdi:test',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-09 11:42:31 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[1][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[1][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[1][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[1][4]).toBe('homeassistant');
|
2019-02-09 11:42:31 -07:00
|
|
|
|
|
|
|
// 3
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': 'hPa',
|
|
|
|
'device_class': 'pressure',
|
|
|
|
'value_template': '{{ value_json.pressure }}',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_pressure',
|
|
|
|
'unique_id': '0x12345678_pressure_zigbee2mqtt',
|
|
|
|
'expire_after': 30,
|
|
|
|
'icon': 'mdi:test',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-09 11:42:31 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[2][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[2][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[2][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[2][4]).toBe('homeassistant');
|
2019-02-09 11:42:31 -07:00
|
|
|
|
|
|
|
// 4
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '%',
|
|
|
|
'device_class': 'battery',
|
|
|
|
'value_template': '{{ value_json.battery }}',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_battery',
|
|
|
|
'unique_id': '0x12345678_battery_zigbee2mqtt',
|
|
|
|
'expire_after': 30,
|
|
|
|
'icon': 'mdi:test',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-09 11:42:31 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[3][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[3][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[3][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[3][4]).toBe('homeassistant');
|
2019-02-20 12:10:38 -07:00
|
|
|
|
|
|
|
// 5
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '-',
|
|
|
|
'value_template': '{{ value_json.linkquality }}',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_linkquality',
|
|
|
|
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
|
|
|
|
'expire_after': 30,
|
|
|
|
'icon': 'mdi:test',
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-20 12:10:38 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[4][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[4][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[4][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[4][4]).toBe('homeassistant');
|
2019-02-09 11:42:31 -07:00
|
|
|
});
|
2019-02-23 08:02:45 -07:00
|
|
|
|
2019-04-26 12:57:38 -07:00
|
|
|
it('Should discover devices with fan', () => {
|
|
|
|
let payload = null;
|
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({friendly_name: 'my_device'});
|
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', FAN99432, false);
|
2019-04-28 11:53:50 -07:00
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(3);
|
2019-04-26 12:57:38 -07:00
|
|
|
|
|
|
|
// 1
|
|
|
|
payload = {
|
|
|
|
name: 'my_device_fan',
|
|
|
|
state_topic: 'zigbee2mqtt/my_device',
|
|
|
|
state_value_template: '{{ value_json.fan_state }}',
|
|
|
|
command_topic: 'zigbee2mqtt/my_device/set/fan_state',
|
|
|
|
speed_state_topic: 'zigbee2mqtt/my_device',
|
|
|
|
speed_value_template: '{{ value_json.fan_mode }}',
|
|
|
|
speed_command_topic: 'zigbee2mqtt/my_device/set/fan_mode',
|
|
|
|
unique_id: '0x12345678_fan_zigbee2mqtt',
|
|
|
|
speeds: ['off', 'low', 'medium', 'high', 'on', 'auto', 'smart'],
|
|
|
|
device: {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-04-26 12:57:38 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'manufacturer': 'Hampton Bay',
|
|
|
|
'model': 'Universal wink enabled white ceiling fan premier remote control (99432)',
|
|
|
|
},
|
|
|
|
availability_topic: 'zigbee2mqtt/bridge/state',
|
|
|
|
json_attributes_topic: 'zigbee2mqtt/my_device',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[0][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[0][2]).toStrictEqual({retain: true, qos: 0});
|
|
|
|
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
|
|
|
});
|
|
|
|
|
2019-02-23 08:02:45 -07:00
|
|
|
it('Should discover devices with cover_position', () => {
|
|
|
|
let payload = null;
|
2019-03-09 20:11:50 -07:00
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({friendly_name: 'my_device'});
|
2019-02-23 08:02:45 -07:00
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', SV01, false);
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
2019-02-23 08:02:45 -07:00
|
|
|
|
|
|
|
// 1
|
|
|
|
payload = {
|
|
|
|
name: 'my_device_cover',
|
|
|
|
command_topic: 'zigbee2mqtt/my_device/set',
|
|
|
|
position_topic: 'zigbee2mqtt/my_device',
|
|
|
|
set_position_topic: 'zigbee2mqtt/my_device/set',
|
|
|
|
set_position_template: '{ "position": {{ position }} }',
|
|
|
|
value_template: '{{ value_json.position }}',
|
|
|
|
unique_id: '0x12345678_cover_zigbee2mqtt',
|
|
|
|
device: {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['zigbee2mqtt_0x12345678'],
|
2019-02-23 08:02:45 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Smart vent (SV01)',
|
|
|
|
'manufacturer': 'Keen Home',
|
|
|
|
},
|
|
|
|
availability_topic: 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[0][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[0][2]).toStrictEqual({retain: true, qos: 0});
|
2019-03-09 15:34:19 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
2019-03-09 20:30:33 -07:00
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
2019-02-23 08:02:45 -07:00
|
|
|
});
|
2019-03-10 13:48:40 -07:00
|
|
|
|
|
|
|
it('Should discover devices with overriden user configuration in device', () => {
|
|
|
|
let payload = null;
|
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({
|
|
|
|
friendly_name: 'my_device',
|
|
|
|
homeassistant: {
|
|
|
|
device: {
|
2019-06-15 07:55:33 -07:00
|
|
|
identifiers: ['test123'],
|
2019-03-10 13:48:40 -07:00
|
|
|
},
|
|
|
|
temperature: {
|
|
|
|
expire_after: 90,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
|
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
|
|
|
|
|
|
|
// 1
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '°C',
|
|
|
|
'device_class': 'temperature',
|
|
|
|
'value_template': '{{ value_json.temperature }}',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_temperature',
|
|
|
|
'unique_id': '0x12345678_temperature_zigbee2mqtt',
|
|
|
|
'expire_after': 90,
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['test123'],
|
2019-03-10 13:48:40 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[0][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[0][2]).toStrictEqual({retain: true, qos: 0});
|
|
|
|
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should discover devices with overriden user configuration in device in temperature', () => {
|
|
|
|
let payload = null;
|
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({
|
|
|
|
friendly_name: 'my_device',
|
|
|
|
homeassistant: {
|
|
|
|
temperature: {
|
|
|
|
expire_after: 90,
|
|
|
|
device: {
|
2019-06-15 07:55:33 -07:00
|
|
|
identifiers: ['test'],
|
2019-03-10 13:48:40 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
|
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
|
|
|
|
|
|
|
// 1
|
|
|
|
payload = {
|
|
|
|
'unit_of_measurement': '°C',
|
|
|
|
'device_class': 'temperature',
|
|
|
|
'value_template': '{{ value_json.temperature }}',
|
|
|
|
'json_attributes_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'state_topic': 'zigbee2mqtt/my_device',
|
|
|
|
'name': 'my_device_temperature',
|
|
|
|
'unique_id': '0x12345678_temperature_zigbee2mqtt',
|
|
|
|
'expire_after': 90,
|
|
|
|
'device': {
|
2019-06-15 07:55:33 -07:00
|
|
|
'identifiers': ['test'],
|
2019-03-10 13:48:40 -07:00
|
|
|
'name': 'my_device',
|
|
|
|
'sw_version': 'Zigbee2mqtt test',
|
|
|
|
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
|
|
|
|
'manufacturer': 'Xiaomi',
|
|
|
|
},
|
|
|
|
'availability_topic': 'zigbee2mqtt/bridge/state',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(JSON.parse(mqtt.publish.mock.calls[0][1])).toStrictEqual(payload);
|
|
|
|
expect(mqtt.publish.mock.calls[0][2]).toStrictEqual({retain: true, qos: 0});
|
|
|
|
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
|
|
|
});
|
2019-03-15 14:41:39 -07:00
|
|
|
|
|
|
|
it('Should discover devices with a custom discovery topic', () => {
|
|
|
|
jest.spyOn(settings, 'get').mockReturnValue({
|
|
|
|
mqtt: {
|
|
|
|
base_topic: 'zigbee2mqtt',
|
|
|
|
},
|
|
|
|
experimental: {
|
|
|
|
output: 'json',
|
|
|
|
},
|
|
|
|
advanced: {
|
|
|
|
homeassistant_discovery_topic: 'my_custom_topic',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
homeassistant = new HomeassistantExtension(null, mqtt, null, null);
|
|
|
|
|
|
|
|
jest.spyOn(settings, 'getDevice').mockReturnValue({
|
|
|
|
friendly_name: 'my_device',
|
|
|
|
homeassistant: {
|
|
|
|
temperature: {
|
|
|
|
expire_after: 90,
|
|
|
|
device: {
|
2019-06-15 07:55:33 -07:00
|
|
|
identifiers: ['test'],
|
2019-03-15 14:41:39 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
|
|
|
|
|
|
|
|
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
|
|
|
expect(mqtt.publish.mock.calls[0][4]).toBe('my_custom_topic');
|
|
|
|
});
|
2018-11-16 12:23:11 -07:00
|
|
|
});
|