@iobroker/legacy-testing 0.2.0 → 0.2.1
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/README.md +2 -1
- package/package.json +1 -1
- package/setup.js +39 -0
package/README.md
CHANGED
|
@@ -11,8 +11,9 @@ Legacy test modules for ioBroker
|
|
|
11
11
|
|
|
12
12
|
## Changelog
|
|
13
13
|
<!-- ### **WORK IN PROGRESS** -->
|
|
14
|
-
### 0.2.
|
|
14
|
+
### 0.2.1 (2023-05-07)
|
|
15
15
|
* (bluefox) Added possibility to install additional adapters at start
|
|
16
|
+
* (bluefox) Added setOfflineState/getOfflineState
|
|
16
17
|
|
|
17
18
|
### 0.1.1 (2022-12-22)
|
|
18
19
|
* (bluefox) Extended testPackageFiles.js with checks
|
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -944,6 +944,43 @@ async function getAdapterConfig(instance, customAdapterName, customInstance) {
|
|
|
944
944
|
}
|
|
945
945
|
}
|
|
946
946
|
|
|
947
|
+
async function setOfflineState(id, state) {
|
|
948
|
+
if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
|
|
949
|
+
const states = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
|
|
950
|
+
states[id] = state;
|
|
951
|
+
fs.writeFileSync(`${rootDir}tmp/${appName}-data/states.json`, JSON.stringify(objects));
|
|
952
|
+
} else if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
|
|
953
|
+
loadJSONLDB();
|
|
954
|
+
const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
|
|
955
|
+
await db.open();
|
|
956
|
+
|
|
957
|
+
db.set(id, state);
|
|
958
|
+
|
|
959
|
+
await db.close();
|
|
960
|
+
} else {
|
|
961
|
+
console.error(`setAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// Read config of the adapter
|
|
966
|
+
async function getOfflineState(id) {
|
|
967
|
+
if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
|
|
968
|
+
const states = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
|
|
969
|
+
return states[id];
|
|
970
|
+
} else if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
|
|
971
|
+
loadJSONLDB();
|
|
972
|
+
const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
|
|
973
|
+
await db.open();
|
|
974
|
+
|
|
975
|
+
const state = db.get(id);
|
|
976
|
+
|
|
977
|
+
await db.close();
|
|
978
|
+
return state;
|
|
979
|
+
} else {
|
|
980
|
+
console.error(`getAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
947
984
|
if (typeof module !== undefined && module.parent) {
|
|
948
985
|
module.exports.getAdapterConfig = getAdapterConfig;
|
|
949
986
|
module.exports.setAdapterConfig = setAdapterConfig;
|
|
@@ -958,4 +995,6 @@ if (typeof module !== undefined && module.parent) {
|
|
|
958
995
|
module.exports.adapterStarted = adapterStarted;
|
|
959
996
|
module.exports.getSecret = getSecret;
|
|
960
997
|
module.exports.encrypt = encrypt;
|
|
998
|
+
module.exports.setOfflineState = setOfflineState;
|
|
999
|
+
module.exports.getOfflineState = getOfflineState;
|
|
961
1000
|
}
|