node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
98 lines (97 loc) • 3.27 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const const_1 = require("../../common/const");
const const_2 = require("../../const");
exports.default = [
{
version: 0,
up: (schema) => {
const newSchema = {
...schema,
version: 0,
entityIdFilterType: schema.entityIdFilterType || 'exact',
timeoutType: schema.timeoutType || 'num',
};
if (newSchema.blockInputOverrides === undefined) {
newSchema.blockInputOverrides = true;
}
if (newSchema.checkCurrentState === undefined) {
newSchema.checkCurrentState = false;
}
return newSchema;
},
},
{
version: 1,
up: (schema) => {
var _a;
const newSchema = {
...schema,
version: 1,
};
if (schema.entityIdFilterType === 'substring' &&
((_a = schema.entityId) === null || _a === void 0 ? void 0 : _a.includes(','))) {
newSchema.entityIdFilterType = 'list';
newSchema.entityId = schema.entityId
.split(',')
.map((e) => e.trim())
.filter((e) => e.length > 0);
}
return newSchema;
},
},
{
version: 2,
up: (schema) => {
const newSchema = {
...schema,
version: 2,
outputProperties: [],
entityLocation: undefined,
entityLocationType: undefined,
};
if (schema.entityLocationType !== 'none') {
newSchema.outputProperties.push({
property: schema.entityLocation,
propertyType: schema.entityLocationType,
value: '',
valueType: const_2.TypedInputTypes.Entity,
});
}
return newSchema;
},
},
{
version: 3,
up: (schema) => {
const newSchema = {
...schema,
version: 3,
entities: [],
entityId: undefined,
entityIdFilterType: undefined,
};
const entitites = {
[const_1.IdSelectorType.Entity]: [],
[const_1.IdSelectorType.Substring]: [],
[const_1.IdSelectorType.Regex]: [],
};
switch (schema.entityIdFilterType) {
case 'list':
entitites[const_1.IdSelectorType.Entity] = schema.entityId;
break;
case 'exact':
entitites[const_1.IdSelectorType.Entity] = [schema.entityId];
break;
case 'substring':
entitites[const_1.IdSelectorType.Substring] = [schema.entityId];
break;
case 'regex':
entitites[const_1.IdSelectorType.Regex] = [schema.entityId];
break;
}
newSchema.entities = entitites;
return newSchema;
},
},
];
;