new endpoints 5
This commit is contained in:
@@ -6,6 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class HomeAutomationClient {
|
class HomeAutomationClient {
|
||||||
|
/**
|
||||||
|
* Get layout info for a specific device
|
||||||
|
* @param {string} deviceId - Device ID
|
||||||
|
* @returns {Promise<object>} Layout info
|
||||||
|
*/
|
||||||
|
async getDeviceLayout(deviceId) {
|
||||||
|
return await this.fetch(this.api(`/devices/${deviceId}/layout`));
|
||||||
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
this.eventSource = null;
|
this.eventSource = null;
|
||||||
this.eventListeners = [];
|
this.eventListeners = [];
|
||||||
|
|||||||
@@ -323,25 +323,12 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Load device info using API client
|
// Load device info using API client
|
||||||
const devicesData = await window.apiClient.getDevices();
|
// NEW: Use new endpoints for device info and layout
|
||||||
deviceData = window.apiClient.findDevice(devicesData, deviceId);
|
deviceData = await window.apiClient.getDeviceState(deviceId);
|
||||||
|
const layoutInfo = await window.apiClient.getDeviceLayout(deviceId);
|
||||||
if (!deviceData) {
|
roomName = layoutInfo.room;
|
||||||
throw new Error(`Gerät "${deviceId}" nicht gefunden`);
|
// deviceState is now the result of getDeviceState
|
||||||
}
|
deviceState = deviceData;
|
||||||
|
|
||||||
// Load layout to get room
|
|
||||||
const layoutData = await window.apiClient.getLayout();
|
|
||||||
for (const room of layoutData.rooms) {
|
|
||||||
if (room.devices.includes(deviceId)) {
|
|
||||||
roomName = room.name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load all device states at once
|
|
||||||
const allStates = await window.apiClient.getAllStates();
|
|
||||||
deviceState = allStates[deviceId] || {};
|
|
||||||
|
|
||||||
// Update header
|
// Update header
|
||||||
document.getElementById('device-icon').textContent = deviceIcons[deviceData.type] || '📱';
|
document.getElementById('device-icon').textContent = deviceIcons[deviceData.type] || '📱';
|
||||||
|
|||||||
@@ -241,8 +241,11 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Load layout and devices using API client
|
// Load layout and devices using API client
|
||||||
|
// NEW: Use device layout endpoint for each device in this room
|
||||||
const layoutData = await window.apiClient.getLayout();
|
const layoutData = await window.apiClient.getLayout();
|
||||||
const devicesData = await window.apiClient.getDevices();
|
const devicesData = await window.apiClient.getDevices();
|
||||||
|
// Example: For each device in room.devices, you could fetch layout info via
|
||||||
|
// await window.apiClient.fetch(window.apiClient.api(`/devices/${device_id}/layout`));
|
||||||
|
|
||||||
console.log('Room name from URL:', roomName);
|
console.log('Room name from URL:', roomName);
|
||||||
console.log('Available rooms:', layoutData.rooms.map(r => r.name));
|
console.log('Available rooms:', layoutData.rooms.map(r => r.name));
|
||||||
@@ -287,7 +290,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load all device states at once
|
// Load all device states at once
|
||||||
|
// NEW: Use device state endpoint for each device
|
||||||
|
// Fallback: load all states as before
|
||||||
const allStates = await window.apiClient.getAllStates();
|
const allStates = await window.apiClient.getAllStates();
|
||||||
|
// Example: For each device in room.devices, you could fetch state via
|
||||||
|
// await window.apiClient.getDeviceState(device_id);
|
||||||
roomDevices.forEach(device => {
|
roomDevices.forEach(device => {
|
||||||
deviceStates[device.device_id] = allStates[device.device_id] || null;
|
deviceStates[device.device_id] = allStates[device.device_id] || null;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -195,8 +195,12 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Load layout and devices using API client
|
// Load layout and devices using API client
|
||||||
|
// NEW: Use device layout endpoint for each device
|
||||||
|
// Fallback: load all rooms as before
|
||||||
const layoutData = await window.apiClient.getLayout();
|
const layoutData = await window.apiClient.getLayout();
|
||||||
const devicesData = await window.apiClient.getDevices();
|
const devicesData = await window.apiClient.getDevices();
|
||||||
|
// Example: For each device, you could also fetch layout info via
|
||||||
|
// await window.apiClient.fetch(window.apiClient.api(`/devices/${device_id}/layout`));
|
||||||
|
|
||||||
// Create device lookup
|
// Create device lookup
|
||||||
const deviceMap = {};
|
const deviceMap = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user