mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-07-12 14:48:57 +00:00
d83085ea7f
* Update zigbee-herdsman and zigbee-shepherd-converters. * Force Aqara S2 Lock endvices (#1764) * Start on zigbee-herdsman controller refactor. * More updates. * Cleanup zapp. * updates. * Propagate adapter disconnected event. * Updates. * Initial refactor to zigbee-herdsman. * Refactor deviceReceive to zigbee-herdsman. * Rename * Refactor deviceConfigure. * Finish bridge config. * Refactor availability. * Active homeassistant extension and more refactors. * Refactor groups. * Enable soft reset. * Activate group membership * Start on tests. * Enable reporting. * Add more controller tests. * Add more tests * Fix linting error. * Data en deviceReceive tests. * Move to zigbee-herdsman-converters. * More device publish tests. * Cleanup dependencies. * Bring device publish coverage to 100. * Bring home assistant test coverage to 100. * Device configure tests. * Attempt to fix tests. * Another attempt. * Another one. * Another one. * Another. * Add wait. * Longer wait. * Debug. * Update dependencies. * Another. * Begin on availability tests. * Improve availability tests. * Complete deviceAvailability tests. * Device bind tests. * More tests. * Begin networkmap refactors. * start on networkmap tests. * Network map tests. * Add utils tests. * Logger tests. * Settings and logger tests. * Ignore some stuff for coverage and add todos. * Add remaining missing tests. * Enforce 100% test coverage. * Start on groups test and refactor entityPublish to resolveEntity * Remove joinPathStorage, not used anymore as group information is stored into zigbee-herdsman database. * Fix linting issues. * Improve tests. * Add groups. * fix group membership. * Group: log names. * Convert MQTT message to string by default. * Fix group name. * Updates. * Revert configuration.yaml. * Add new line. * Fixes. * Updates. * Fix tests. * Ignore soft reset extension.
172 lines
4.7 KiB
JavaScript
172 lines
4.7 KiB
JavaScript
const tmp = require('tmp');
|
|
const yaml = require('../../lib/util/yaml');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const mockDir = tmp.dirSync().name;
|
|
const mockDirStorage = tmp.dirSync().name;
|
|
|
|
function writeDefaultConfiguration() {
|
|
const config = {
|
|
homeassistant: false,
|
|
permit_join: true,
|
|
mqtt: {
|
|
base_topic: "zigbee2mqtt",
|
|
server: "mqtt://localhost",
|
|
},
|
|
serial: {
|
|
"port": "/dev/dummy",
|
|
},
|
|
devices: {
|
|
"0x000b57fffec6a5b2": {
|
|
retain: true,
|
|
friendly_name: "bulb"
|
|
},
|
|
"0x0017880104e45517": {
|
|
retain: true,
|
|
friendly_name: "remote"
|
|
},
|
|
"0x0017880104e45520": {
|
|
retain: false,
|
|
friendly_name: "button"
|
|
},
|
|
"0x0017880104e45521": {
|
|
retain: false,
|
|
friendly_name: "button_double_key"
|
|
},
|
|
"0x0017880104e45522": {
|
|
qos: 1,
|
|
friendly_name: "weather_sensor"
|
|
},
|
|
"0x0017880104e45523": {
|
|
retain: false,
|
|
friendly_name: "occupancy_sensor"
|
|
},
|
|
"0x0017880104e45524": {
|
|
retain: false,
|
|
friendly_name: "power_plug"
|
|
},
|
|
"0x0017880104e45530": {
|
|
retain: false,
|
|
friendly_name: "button_double_key_interviewing"
|
|
},
|
|
"0x0017880104e45540": {
|
|
retain: false,
|
|
friendly_name: "ikea_onoff"
|
|
},
|
|
"0x000b57fffec6a5b3": {
|
|
retain: false,
|
|
friendly_name: "bulb_color"
|
|
},
|
|
"0x0017880104e45541": {
|
|
retain: false,
|
|
friendly_name: "wall_switch"
|
|
},
|
|
"0x0017880104e45542": {
|
|
retain: false,
|
|
friendly_name: "wall_switch_double"
|
|
},
|
|
"0x0017880104e45543": {
|
|
retain: false,
|
|
friendly_name: "led_controller_1"
|
|
},
|
|
"0x0017880104e45544": {
|
|
retain: false,
|
|
friendly_name: "led_controller_2"
|
|
},
|
|
'0x0017880104e45545': {
|
|
retain: false,
|
|
friendly_name: "dimmer_wall_switch"
|
|
},
|
|
'0x0017880104e45547': {
|
|
retain: false,
|
|
friendly_name: "curtain"
|
|
},
|
|
'0x0017880104e45548': {
|
|
retain: false,
|
|
friendly_name: 'fan'
|
|
},
|
|
'0x0017880104e45549': {
|
|
retain: false,
|
|
friendly_name: 'siren'
|
|
},
|
|
'0x0017880104e45529': {
|
|
retain: false,
|
|
friendly_name: 'unsupported2'
|
|
},
|
|
'0x0017880104e45550': {
|
|
retain: false,
|
|
friendly_name: 'thermostat'
|
|
},
|
|
'0x0017880104e45551': {
|
|
retain: false,
|
|
friendly_name: 'smart_vent'
|
|
},
|
|
'0x0017880104e45552': {
|
|
retain: false,
|
|
friendly_name: 'j1'
|
|
},
|
|
'0x0017880104e45553': {
|
|
retain: false,
|
|
friendly_name: 'bulb_enddevice'
|
|
},
|
|
'0x0017880104e45559': {
|
|
retain: false,
|
|
friendly_name: 'cc2530_router'
|
|
}
|
|
},
|
|
groups: {
|
|
'1': {
|
|
friendly_name: 'group_1',
|
|
retain: false,
|
|
},
|
|
'2': {
|
|
friendly_name: 'group_2',
|
|
retain: false,
|
|
}
|
|
}
|
|
};
|
|
|
|
yaml.write(path.join(mockDir, 'configuration.yaml'), config);
|
|
}
|
|
|
|
function writeEmptyState() {
|
|
yaml.write(path.join(mockDir, 'state.json'), JSON.stringify({}));
|
|
}
|
|
|
|
function writeDefaultState() {
|
|
const state = {
|
|
"0x000b57fffec6a5b2": {
|
|
"state": "ON",
|
|
"brightness": 50,
|
|
"color_temp": 370,
|
|
"linkquality": 99,
|
|
},
|
|
"0x0017880104e45517": {
|
|
"brightness": 255
|
|
},
|
|
}
|
|
|
|
fs.writeFileSync(path.join(mockDir, 'state.json'), JSON.stringify(state));
|
|
}
|
|
|
|
function removeState() {
|
|
fs.unlinkSync(path.join(mockDir, 'state.json'))
|
|
}
|
|
|
|
jest.mock('../../lib/util/data', () => ({
|
|
joinPath: (file) => require('path').join(mockDir, file),
|
|
getPath: () => mockDir,
|
|
}));
|
|
|
|
writeDefaultConfiguration();
|
|
writeDefaultState();
|
|
|
|
module.exports = {
|
|
mockDir,
|
|
writeDefaultConfiguration,
|
|
writeDefaultState,
|
|
removeState,
|
|
writeEmptyState,
|
|
};
|