Allow mocking websocket commands in the gallery (#1859)

* Allow mocking rest/websocket commands in the gallery

* typo
This commit is contained in:
Paulus Schoutsen 2018-10-26 09:27:10 +02:00 committed by GitHub
parent 9f60499a3f
commit 8bf60d502a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ export default (elements, { initialStates = {} } = {}) => {
elements = ensureArray(elements);
const wsCommands = {};
const restResponses = {};
let hass;
const entities = {};
@ -69,6 +70,14 @@ export default (elements, { initialStates = {} } = {}) => {
console.log("sendWS", msg);
},
async callApi(method, path, parameters) {
const callback = restResponses[path];
return callback
? callback(method, path, parameters)
: Promise.reject(`Mock for {path} is not implemented`);
},
// Mock functions
updateHass,
updateStates(newStates) {
@ -85,6 +94,12 @@ export default (elements, { initialStates = {} } = {}) => {
});
this.updateStates(states);
},
mockWS(type, callback) {
wsCommands[type] = callback;
},
mockAPI(path, callback) {
restResponses[path] = callback;
},
});
return hass;