This commit is contained in:
Mateusz Gruszczyński
2026-09-16 22:38:45 +02:00
parent bb39ab9dfa
commit e02557bb65
15 changed files with 136 additions and 55 deletions
+1 -1
View File
@@ -646,7 +646,7 @@ $('#greeCloudReconnectButton')?.addEventListener('click', async event => {
try {
button.disabled = true;
await api('/api/integrations/gree-cloud/reconnect', { method: 'POST' });
await refreshGreeCloudRuntimeStatus();
await refreshGreeCloudRuntimeStatus({ force: true });
toast(tr('common.saved'));
} catch (error) {
toast(error.message, true);
+31 -2
View File
@@ -584,7 +584,36 @@ function formatDuration(seconds) {
setInterval(() => { if (app.currentView === 'settings') renderSystemInfo(); }, 30000);
async function refreshGreeCloudRuntimeStatus() {
let greeCloudRuntimeStatusCache = null;
let greeCloudRuntimeStatusCachedAt = 0;
let greeCloudRuntimeStatusRequest = null;
const GREE_CLOUD_RUNTIME_STATUS_CACHE_MS = 5000;
function invalidateGreeCloudRuntimeStatusCache() {
greeCloudRuntimeStatusCache = null;
greeCloudRuntimeStatusCachedAt = 0;
}
async function getGreeCloudRuntimeStatus(force = false) {
const now = Date.now();
if (!force && greeCloudRuntimeStatusCache && now - greeCloudRuntimeStatusCachedAt < GREE_CLOUD_RUNTIME_STATUS_CACHE_MS) {
return greeCloudRuntimeStatusCache;
}
if (!force && greeCloudRuntimeStatusRequest) return greeCloudRuntimeStatusRequest;
const request = api('/api/integrations/gree-cloud/status');
if (!force) greeCloudRuntimeStatusRequest = request;
try {
const status = await request;
greeCloudRuntimeStatusCache = status;
greeCloudRuntimeStatusCachedAt = Date.now();
return status;
} finally {
if (greeCloudRuntimeStatusRequest === request) greeCloudRuntimeStatusRequest = null;
}
}
async function refreshGreeCloudRuntimeStatus({ force = false } = {}) {
const summary = $('.cloud-runtime-summary');
if (!summary) return;
const metricSelectors = [
@@ -602,7 +631,7 @@ async function refreshGreeCloudRuntimeStatus() {
const lastContact = $('#greeCloudLastContact');
const lastContactRow = lastContact?.closest('small');
try {
const status = await api('/api/integrations/gree-cloud/status');
const status = await getGreeCloudRuntimeStatus(force);
const runtime = status.runtime || {};
const enabled = status.enabled === true;
const deviceCount = Number(status.device_count || 0);
+2
View File
@@ -181,6 +181,7 @@ async function saveMainSettings(form, notify = true) {
applySettingsSection('application', application);
applySettingsSection('gree', gree);
applySettingsSection('greeCloud', greeCloud);
invalidateGreeCloudRuntimeStatusCache();
applySettingsSection('history', history);
applySettingsSection('influxdb', influxdb);
applySettingsSection('notifications', notifications);
@@ -474,6 +475,7 @@ document.addEventListener('click', event => {
async function saveGreeCloudSettings(form = $('#settingsForm')) {
const data = await api(SETTINGS_ENDPOINTS.greeCloud, { method: 'PUT', body: greeCloudSettingsBodyFromForm(form) });
applySettingsSection('greeCloud', data);
invalidateGreeCloudRuntimeStatusCache();
return data;
}