garaga page 7
This commit is contained in:
@@ -512,7 +512,10 @@
|
|||||||
async function toggleOutlet(deviceId, newState) {
|
async function toggleOutlet(deviceId, newState) {
|
||||||
try {
|
try {
|
||||||
const device = devicesData[deviceId];
|
const device = devicesData[deviceId];
|
||||||
await window.apiClient.setDeviceState(deviceId, device.type, { power: newState });
|
await sendCommand(deviceId, {
|
||||||
|
type: device.type,
|
||||||
|
payload: { power: newState }
|
||||||
|
});
|
||||||
console.log(`Set ${deviceId} to ${newState}`);
|
console.log(`Set ${deviceId} to ${newState}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error toggling outlet:', error);
|
console.error('Error toggling outlet:', error);
|
||||||
@@ -520,6 +523,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendCommand(deviceId, payload) {
|
||||||
|
const device = devicesData[deviceId];
|
||||||
|
await window.apiClient.setDeviceState(deviceId, device.type, payload.payload);
|
||||||
|
}
|
||||||
|
|
||||||
function connectRealtime() {
|
function connectRealtime() {
|
||||||
try {
|
try {
|
||||||
window.apiClient.connectRealtime((event) => {
|
window.apiClient.connectRealtime((event) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user