mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 01:50:47 -04:00
loggings
This commit is contained in:
@@ -10,13 +10,19 @@ function inferType(entityId, explicitType) {
|
|||||||
return 'switch';
|
return 'switch';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function inferDomain(entityId) {
|
||||||
|
const domain = String(entityId || '').split('.')[0].trim().toLowerCase();
|
||||||
|
return domain || 'switch';
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeConfigEntry(entry) {
|
function normalizeConfigEntry(entry) {
|
||||||
if (!entry) return null;
|
if (!entry) return null;
|
||||||
const id = entry.id || entry.entityId || entry.entity_id;
|
const id = entry.id || entry.entityId || entry.entity_id;
|
||||||
if (!id) return null;
|
if (!id) return null;
|
||||||
const type = inferType(id, entry.type);
|
const type = inferType(id, entry.type);
|
||||||
|
const domain = inferDomain(id);
|
||||||
const name = entry.name || null;
|
const name = entry.name || null;
|
||||||
return { id: String(id), name, type };
|
return { id: String(id), name, type, domain };
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeTriggerEntry(entry, index) {
|
function normalizeTriggerEntry(entry, index) {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ function createRuntimeEngine(deps) {
|
|||||||
if (!runtime.connection) throw new Error('Home Assistant not connected');
|
if (!runtime.connection) throw new Error('Home Assistant not connected');
|
||||||
|
|
||||||
const nextState = desiredState === 'on' ? 'on' : 'off';
|
const nextState = desiredState === 'on' ? 'on' : 'off';
|
||||||
const domain = meta.type === 'light' ? 'light' : 'switch';
|
const domain = String(meta.domain || (meta.type === 'light' ? 'light' : 'switch')).toLowerCase();
|
||||||
const service = nextState === 'on' ? 'turn_on' : 'turn_off';
|
const service = nextState === 'on' ? 'turn_on' : 'turn_off';
|
||||||
const source = String(options?.source || 'unknown');
|
const source = String(options?.source || 'unknown');
|
||||||
await callHomeAssistantService(domain, service, { entity_id: entityId });
|
await callHomeAssistantService(domain, service, { entity_id: entityId });
|
||||||
@@ -90,14 +90,29 @@ function createRuntimeEngine(deps) {
|
|||||||
const results = await Promise.allSettled(
|
const results = await Promise.allSettled(
|
||||||
ids.map((id) => setEntityState(id, desiredState, { source: `${source}:bulk` })),
|
ids.map((id) => setEntityState(id, desiredState, { source: `${source}:bulk` })),
|
||||||
);
|
);
|
||||||
const failures = results.filter((result) => result.status === 'rejected');
|
const failures = results
|
||||||
|
.map((result, index) => ({ result, entityId: ids[index] }))
|
||||||
|
.filter(({ result }) => result.status === 'rejected')
|
||||||
|
.map(({ result, entityId }) => ({ entityId, error: result.reason?.message || 'unknown error' }));
|
||||||
|
const succeeded = results
|
||||||
|
.map((result, index) => ({ result, entityId: ids[index] }))
|
||||||
|
.filter(({ result }) => result.status === 'fulfilled')
|
||||||
|
.map(({ entityId }) => entityId);
|
||||||
if (failures.length) {
|
if (failures.length) {
|
||||||
logger.warn('Some Home Assistant entity state updates failed', {
|
logger.warn('Some Home Assistant entity state updates failed', {
|
||||||
desiredState,
|
desiredState,
|
||||||
total: ids.length,
|
total: ids.length,
|
||||||
failed: failures.length,
|
failed: failures.length,
|
||||||
|
failures,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
desiredState: desiredState === 'on' ? 'on' : 'off',
|
||||||
|
source,
|
||||||
|
total: ids.length,
|
||||||
|
succeeded,
|
||||||
|
failures,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerMatches(trigger, raw, runtimeState) {
|
function triggerMatches(trigger, raw, runtimeState) {
|
||||||
|
|||||||
@@ -13,8 +13,20 @@ const {
|
|||||||
} = require('./constants');
|
} = require('./constants');
|
||||||
|
|
||||||
async function turnOffRoomControls() {
|
async function turnOffRoomControls() {
|
||||||
await homeAssistantService.setAllControllableEntitiesState('off', { source: 'idleService:turnOffRoomControls' });
|
const before = homeAssistantService.getState?.().entities || [];
|
||||||
return { action: 'roomControlsOff' };
|
const summary = await homeAssistantService.setAllControllableEntitiesState('off', {
|
||||||
|
source: 'idleService:turnOffRoomControls',
|
||||||
|
});
|
||||||
|
const after = homeAssistantService.getState?.().entities || [];
|
||||||
|
logger.info('Idle room-controls off summary', {
|
||||||
|
attempted: summary?.total || 0,
|
||||||
|
succeeded: Array.isArray(summary?.succeeded) ? summary.succeeded.length : 0,
|
||||||
|
failed: Array.isArray(summary?.failures) ? summary.failures.length : 0,
|
||||||
|
failedEntities: summary?.failures || [],
|
||||||
|
beforeStates: before.map((entity) => ({ id: entity.id, state: entity.state, available: entity.available })),
|
||||||
|
afterStates: after.map((entity) => ({ id: entity.id, state: entity.state, available: entity.available })),
|
||||||
|
});
|
||||||
|
return { action: 'roomControlsOff', ...summary };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dockAllRovers() {
|
async function dockAllRovers() {
|
||||||
|
|||||||
Reference in New Issue
Block a user