2021-07-05 17:25:23 +02:00
|
|
|
WA.onInit().then(() => {
|
|
|
|
console.log('Trying to read variable "doorOpened" whose default property is true. This should display "true".');
|
2021-07-07 22:14:59 +02:00
|
|
|
console.log('doorOpened', WA.state.loadVariable('doorOpened'));
|
2021-07-02 11:31:44 +02:00
|
|
|
|
2021-07-05 18:29:34 +02:00
|
|
|
console.log('Trying to set variable "not_exists". This should display an error in the console, followed by a log saying the error was caught.')
|
2021-07-07 22:14:59 +02:00
|
|
|
WA.state.saveVariable('not_exists', 'foo').catch((e) => {
|
2021-07-05 18:29:34 +02:00
|
|
|
console.log('Successfully caught error: ', e);
|
|
|
|
});
|
2021-07-02 11:31:44 +02:00
|
|
|
|
2021-07-06 10:58:12 +02:00
|
|
|
console.log('Trying to set variable "myvar". This should work.');
|
2021-07-07 22:14:59 +02:00
|
|
|
WA.state.saveVariable('myvar', {'foo': 'bar'});
|
2021-07-02 11:31:44 +02:00
|
|
|
|
2021-07-06 10:58:12 +02:00
|
|
|
console.log('Trying to read variable "myvar". This should display a {"foo": "bar"} object.');
|
2021-07-07 22:14:59 +02:00
|
|
|
console.log(WA.state.loadVariable('myvar'));
|
|
|
|
|
|
|
|
console.log('Trying to set variable "myvar" using proxy. This should work.');
|
|
|
|
WA.state.myvar = {'baz': 42};
|
|
|
|
|
|
|
|
console.log('Trying to read variable "myvar" using proxy. This should display a {"baz": 42} object.');
|
|
|
|
console.log(WA.state.myvar);
|
2021-07-06 10:58:12 +02:00
|
|
|
|
|
|
|
console.log('Trying to set variable "config". This should not work because we are not logged as admin.');
|
2021-07-07 22:14:59 +02:00
|
|
|
WA.state.saveVariable('config', {'foo': 'bar'}).catch(e => {
|
2021-07-06 10:58:12 +02:00
|
|
|
console.log('Successfully caught error because variable "config" is not writable: ', e);
|
|
|
|
});
|
2021-07-19 10:16:43 +02:00
|
|
|
|
|
|
|
console.log('Trying to read variable "readableByAdmin" that can only be read by "admin". We are not admin so we should not get the default value.');
|
|
|
|
if (WA.state.readableByAdmin === true) {
|
|
|
|
console.error('Failed test: readableByAdmin can be read.');
|
|
|
|
} else {
|
|
|
|
console.log('Success test: readableByAdmin was not read.');
|
|
|
|
}
|
2021-07-05 17:25:23 +02:00
|
|
|
});
|