v0.14.0
This commit is contained in:
+74
-1
@@ -73,6 +73,18 @@ document.addEventListener('click', async event => {
|
||||
return;
|
||||
}
|
||||
const action = button.dataset.action; if (!action) return;
|
||||
if (action === 'add-cloud-device') {
|
||||
const cloudId = button.dataset.cloudId; if (!cloudId) return;
|
||||
button.disabled = true;
|
||||
try {
|
||||
await api(`/api/integrations/gree-cloud/devices/${encodeURIComponent(cloudId)}/add`, { method: 'POST' });
|
||||
await loadBootstrap();
|
||||
await loadCloudDiscovery({ open: false });
|
||||
toast(tr('devices.cloudAdded'));
|
||||
} catch (error) { toast(error.message, true); }
|
||||
finally { button.disabled = false; }
|
||||
return;
|
||||
}
|
||||
const device = app.devices.find(v => v.id === button.dataset.device);
|
||||
if (action === 'open-ping' && device) { openDevicePing(device.id); return; }
|
||||
if (action === 'ping-toggle') { if (app.pingMonitor.running) stopPingMonitor(); else startPingMonitor(); return; }
|
||||
@@ -84,6 +96,9 @@ document.addEventListener('click', async event => {
|
||||
if (action === 'poll' && device) { try { button.disabled = true; updateDevice(await api(`/api/devices/${encodeURIComponent(device.id)}/poll`, { method: 'POST' })); renderAll(); toast(tr('devices.readDone')); } catch (e) { toast(e.message, true); } finally { button.disabled = false; } return; }
|
||||
if (action === 'bind' && device) { try { button.disabled = true; updateDevice(await api(`/api/devices/${encodeURIComponent(device.id)}/bind`, { method: 'POST' })); renderAll(); toast(tr('devices.bound')); } catch (e) { toast(e.message, true); } finally { button.disabled = false; } return; }
|
||||
if (action === 'rename-device' && device) return populateDeviceRename(device.id);
|
||||
if (action === 'energy-config' && device) return openDeviceDetails(device.id);
|
||||
if (action === 'cloud-details' && device) return openDeviceDetails(device.id);
|
||||
if (action === 'cloud-diagnostics' && device) return openCloudDiagnostics(device.id);
|
||||
if (action === 'delete-device') return deleteEntity('devices', button.dataset.device, 'label.device');
|
||||
if (action === 'house-mode') {
|
||||
try {
|
||||
@@ -209,6 +224,13 @@ $('#discoverButton').addEventListener('click', () => {
|
||||
form.protocol_version.value = '0'; form.passes.value = '3'; form.timeout_ms.value = String(Math.max(6000, Number(app.settings?.discovery_timeout_ms || 3000)));
|
||||
openDialog('discoverDialog');
|
||||
});
|
||||
$('#cloudDiscoverButton')?.addEventListener('click', async event => {
|
||||
const button = event.currentTarget;
|
||||
button.disabled = true;
|
||||
try { await loadCloudDiscovery(); }
|
||||
catch (error) { toast(error.message, true); }
|
||||
finally { button.disabled = false; }
|
||||
});
|
||||
$('#historyRefresh').addEventListener('click', loadHistory);
|
||||
$('#historyHours').addEventListener('change', () => { updateBrowserUrl(currentHistoryPath(), true); loadHistory(); });
|
||||
$('#logsRefresh').addEventListener('click', loadLogs);
|
||||
@@ -328,12 +350,20 @@ $('#renameDeviceForm').addEventListener('submit', async event => {
|
||||
const result = $('#deviceConfigCheckResult');
|
||||
if (result) { result.hidden = true; result.textContent = ''; result.classList.remove('success', 'error'); }
|
||||
await runFormTask(form, async () => {
|
||||
let device = await api(`/api/devices/${encodeURIComponent(raw.id)}`, { method: 'PATCH', body: { name: raw.name.trim(), ip: raw.ip.trim(), port: Number(raw.port), protocol_version: Number(raw.protocol_version) } });
|
||||
const isCloud = previous?.connection_type === 'gree_cloud';
|
||||
const patch = isCloud ? { name: raw.name.trim() } : { name: raw.name.trim(), ip: raw.ip.trim(), port: Number(raw.port), protocol_version: Number(raw.protocol_version) };
|
||||
let device = await api(`/api/devices/${encodeURIComponent(raw.id)}`, { method: 'PATCH', body: patch });
|
||||
updateDevice(device);
|
||||
if (saveMode !== 'check') {
|
||||
form.closest('dialog').close(); renderAll(); toast(tr('common.saved')); return;
|
||||
}
|
||||
try {
|
||||
if (isCloud) {
|
||||
const check = await api('/api/integrations/gree-cloud/test', { method: 'POST' });
|
||||
if (!check.ok) throw new Error(check.message || check.status || tr('settings.cloudConnectionFailed'));
|
||||
if (result) { result.hidden = false; result.classList.add('success'); result.textContent = tr('settings.cloudConnected', { count: Number(check.device_count || 0) }); }
|
||||
markFormClean(form); renderAll(); toast(tr('devices.savedAndChecked')); return;
|
||||
}
|
||||
const protocolChanged = previous && Number(previous.protocol_version) !== Number(raw.protocol_version);
|
||||
if (!device.simulated && protocolChanged) {
|
||||
device = await api(`/api/devices/${encodeURIComponent(device.id)}/bind`, { method: 'POST' });
|
||||
@@ -367,6 +397,35 @@ $('#renameDeviceForm').addEventListener('submit', async event => {
|
||||
});
|
||||
});
|
||||
|
||||
$('#deviceDetailsForm')?.addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const raw = Object.fromEntries(new FormData(form));
|
||||
const option = form.ha_energy_entity_id.selectedOptions?.[0];
|
||||
const patch = {
|
||||
name: raw.name.trim(),
|
||||
energy_source: raw.energy_source || 'auto',
|
||||
ha_energy_entity_id: raw.ha_energy_entity_id || null,
|
||||
ha_energy_unit: option?.value ? (option.dataset.unit || null) : null,
|
||||
ha_energy_device_class: option?.value ? (option.dataset.deviceClass || null) : null,
|
||||
ha_energy_state_class: option?.value ? (option.dataset.stateClass || null) : null,
|
||||
};
|
||||
await runFormTask(form, async () => {
|
||||
const device = await api(`/api/devices/${encodeURIComponent(raw.id)}`, { method: 'PATCH', body: patch });
|
||||
updateDevice(device);
|
||||
form.closest('dialog').close();
|
||||
renderAll();
|
||||
toast(tr('common.saved'));
|
||||
});
|
||||
});
|
||||
|
||||
$('#deviceDetailsForm')?.ha_energy_entity_id?.addEventListener('change', updateDeviceEnergySensorMeta);
|
||||
|
||||
$('#cloudDiagnosticsRefresh')?.addEventListener('click', () => {
|
||||
const id = $('#cloudDiagnosticsDialog')?.dataset.deviceId;
|
||||
if (id) openCloudDiagnostics(id);
|
||||
});
|
||||
|
||||
$('#pingDeviceSelect')?.addEventListener('change', event => {
|
||||
app.pingMonitor.targetId = event.target.value;
|
||||
renderPingDialog();
|
||||
@@ -495,3 +554,17 @@ $('#automationForm').addEventListener('submit', async event => {
|
||||
await api(id ? `/api/automations/${encodeURIComponent(id)}` : '/api/automations', { method: id ? 'PUT' : 'POST', body }); form.closest('dialog').close(); form.reset(); await loadBootstrap(); toast(tr('common.saved'));
|
||||
});
|
||||
});
|
||||
|
||||
$('#greeCloudReconnectButton')?.addEventListener('click', async event => {
|
||||
const button = event.currentTarget;
|
||||
try {
|
||||
button.disabled = true;
|
||||
await api('/api/integrations/gree-cloud/reconnect', { method: 'POST' });
|
||||
await refreshGreeCloudRuntimeStatus();
|
||||
toast(tr('common.saved'));
|
||||
} catch (error) {
|
||||
toast(error.message, true);
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user