mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Allow mocking websocket commands in the gallery (#1859)
* Allow mocking rest/websocket commands in the gallery * typo
This commit is contained in:
parent
9f60499a3f
commit
8bf60d502a
@ -10,6 +10,7 @@ export default (elements, { initialStates = {} } = {}) => {
|
|||||||
elements = ensureArray(elements);
|
elements = ensureArray(elements);
|
||||||
|
|
||||||
const wsCommands = {};
|
const wsCommands = {};
|
||||||
|
const restResponses = {};
|
||||||
let hass;
|
let hass;
|
||||||
const entities = {};
|
const entities = {};
|
||||||
|
|
||||||
@ -69,6 +70,14 @@ export default (elements, { initialStates = {} } = {}) => {
|
|||||||
console.log("sendWS", msg);
|
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
|
// Mock functions
|
||||||
updateHass,
|
updateHass,
|
||||||
updateStates(newStates) {
|
updateStates(newStates) {
|
||||||
@ -85,6 +94,12 @@ export default (elements, { initialStates = {} } = {}) => {
|
|||||||
});
|
});
|
||||||
this.updateStates(states);
|
this.updateStates(states);
|
||||||
},
|
},
|
||||||
|
mockWS(type, callback) {
|
||||||
|
wsCommands[type] = callback;
|
||||||
|
},
|
||||||
|
mockAPI(path, callback) {
|
||||||
|
restResponses[path] = callback;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return hass;
|
return hass;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user