node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
57 lines (56 loc) • 1.72 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInvalidIds = getInvalidIds;
const _1 = require(".");
const utils_1 = require("./utils");
function getInvalidIds(type, config, ids) {
const invalidIds = [];
if (!ids) {
return invalidIds;
}
if (!Array.isArray(ids)) {
ids = [ids];
}
const ha = (0, utils_1.getHomeAssistant)(config);
if (!(ha === null || ha === void 0 ? void 0 : ha.websocket.isStatesLoaded)) {
return invalidIds;
}
for (const id of ids) {
if ((0, utils_1.isDynamicValue)(id)) {
continue;
}
switch (type) {
case _1.IssueType.AreaId:
if (!ha.websocket.getArea(id)) {
invalidIds.push(id);
}
break;
case _1.IssueType.DeviceId:
if (!ha.websocket.getDevice(id)) {
invalidIds.push(id);
}
break;
case _1.IssueType.EntityId:
if (!ha.websocket.getEntity(id)) {
invalidIds.push(id);
}
break;
case _1.IssueType.FloorId:
if (!ha.websocket.getFloor(id)) {
invalidIds.push(id);
}
break;
case _1.IssueType.LabelId:
if (!ha.websocket.getLabel(id)) {
invalidIds.push(id);
}
break;
case _1.IssueType.StateId:
if (!ha.websocket.getState(id)) {
invalidIds.push(id);
}
break;
}
}
return invalidIds;
}
;