mirror of
https://git.wetfence.xyz/RandyTheSilly/Trigalarm.git
synced 2026-08-27 22:26:25 -04:00
[Pavlok] Add test beep button to settings to verify API config
This commit is contained in:
+4
-7
@@ -35,13 +35,10 @@ module.exports = [
|
||||
"label": "Zap Intensity"
|
||||
},
|
||||
{
|
||||
"id": "pavlok_interval",
|
||||
"type": "slider",
|
||||
"messageKey": "PKJS_PAVLOK_INTERVAL",
|
||||
defaultValue: 5,
|
||||
min: 1,
|
||||
max: 60,
|
||||
"label": "Zap Repeat Interval (Seconds - NOT IMPLEMENTED)"
|
||||
"id": "pavlok_test_button",
|
||||
"type": "button",
|
||||
"messageKey": "PKJS_PAVLOK_TEST_BUTTON",
|
||||
"defaultValue": "Test Beep"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
+23
-2
@@ -8,17 +8,38 @@ module.exports = function (minified) {
|
||||
if (this.get()) {
|
||||
clayConfig.getItemById('pavlok_api_key').show();
|
||||
clayConfig.getItemById('pavlok_zap_intensity').show();
|
||||
clayConfig.getItemById('pavlok_interval').show();
|
||||
clayConfig.getItemById('pavlok_test_button').show();
|
||||
} else {
|
||||
clayConfig.getItemById('pavlok_api_key').hide();
|
||||
clayConfig.getItemById('pavlok_zap_intensity').hide();
|
||||
clayConfig.getItemById('pavlok_interval').hide();
|
||||
clayConfig.getItemById('pavlok_test_button').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function sendTestBeep() {
|
||||
const data = JSON.stringify({
|
||||
stimulus: {
|
||||
stimulusType: 'beep',
|
||||
stimulusValue: 80,
|
||||
reason: 'Trigalarm Test'
|
||||
}
|
||||
});
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = true;
|
||||
|
||||
xhr.open('POST', 'https://api.pavlok.com/api/v5/stimulus/send');
|
||||
xhr.setRequestHeader('accept', 'application/json');
|
||||
xhr.setRequestHeader('content-type', 'application/json');
|
||||
xhr.setRequestHeader('Authorization', 'Bearer ' + clayConfig.getItemById('pavlok_api_key').get());
|
||||
xhr.send(data);
|
||||
}
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function () {
|
||||
var pavlokIntegrationToggle = clayConfig.getItemById('pavlok_enable');
|
||||
togglePavlokIntegration.call(pavlokIntegrationToggle);
|
||||
pavlokIntegrationToggle.on('change', togglePavlokIntegration);
|
||||
|
||||
clayConfig.getItemById('pavlok_test_button').on('click', sendTestBeep);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user