mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +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);
|
||||
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user