Fixed linter
This commit is contained in:
+4
-3
@@ -88,12 +88,13 @@ class HASS extends node_events_1.EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (response.type === 'auth_required') {
|
else if (response.type === 'auth_required') {
|
||||||
if (!this.options.password) {
|
const password = this.options.password || process.env.SUPERVISOR_TOKEN;
|
||||||
|
if (!password) {
|
||||||
this.emit('error', 'Password required. Connection closed');
|
this.emit('error', 'Password required. Connection closed');
|
||||||
socket.terminate();
|
socket.terminate();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setTimeout(() => this.sendAuth(socket, this.options.password), 50);
|
setTimeout(() => this.sendAuth(socket, password), 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (response.type === 'auth_ok') {
|
else if (response.type === 'auth_ok') {
|
||||||
@@ -196,7 +197,7 @@ class HASS extends node_events_1.EventEmitter {
|
|||||||
clearTimeout(this.connectTimeout);
|
clearTimeout(this.connectTimeout);
|
||||||
this.connectTimeout = null;
|
this.connectTimeout = null;
|
||||||
}
|
}
|
||||||
this.socket = new ws_1.default(`ws${this.options.secure ? 's' : ''}://${this.options.host}:${this.options.port}/api/websocket`, { perMessageDeflate: false });
|
this.socket = new ws_1.default(`ws${this.options.secure ? 's' : ''}://${this.options.host}:${this.options.port}/${this.options.host === 'supervisor' ? 'core' : 'api'}/websocket`, { perMessageDeflate: false });
|
||||||
this.initSocket(this.socket);
|
this.initSocket(this.socket);
|
||||||
}
|
}
|
||||||
close() {
|
close() {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
+27
-6
@@ -562,7 +562,7 @@ class HassAdapter extends adapter_core_1.Adapter {
|
|||||||
await this.setStateAsync('info.connection', false, true);
|
await this.setStateAsync('info.connection', false, true);
|
||||||
this.hass = new hass_1.default(this.config, this.log);
|
this.hass = new hass_1.default(this.config, this.log);
|
||||||
this.hass.on('error', err => this.log.error(err));
|
this.hass.on('error', err => this.log.error(err));
|
||||||
this.hass.on('state_changed', entity => {
|
this.hass.on('state_changed', async (entity) => {
|
||||||
this.log.debug(`HASS-Message: State Changed: ${JSON.stringify(entity)}`);
|
this.log.debug(`HASS-Message: State Changed: ${JSON.stringify(entity)}`);
|
||||||
if (!entity || typeof entity.entity_id !== 'string') {
|
if (!entity || typeof entity.entity_id !== 'string') {
|
||||||
return;
|
return;
|
||||||
@@ -572,7 +572,7 @@ class HassAdapter extends adapter_core_1.Adapter {
|
|||||||
const ts = entity.last_updated ? new Date(entity.last_updated).getTime() : undefined;
|
const ts = entity.last_updated ? new Date(entity.last_updated).getTime() : undefined;
|
||||||
if (entity.state !== undefined) {
|
if (entity.state !== undefined) {
|
||||||
if (this.hassObjects[`${this.namespace}.${id}state`]) {
|
if (this.hassObjects[`${this.namespace}.${id}state`]) {
|
||||||
this.setState(`${id}state`, { val: entity.state, ack: true, lc, ts });
|
await this.setStateAsync(`${id}state`, { val: entity.state, ack: true, lc, ts });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.log.info(`State changed for unknown object ${id}state. Triggering synchronization to resync the objects.`);
|
this.log.info(`State changed for unknown object ${id}state. Triggering synchronization to resync the objects.`);
|
||||||
@@ -580,7 +580,7 @@ class HassAdapter extends adapter_core_1.Adapter {
|
|||||||
}
|
}
|
||||||
// Update boolean state
|
// Update boolean state
|
||||||
if (this.hassObjects[`${this.namespace}.${id}state_boolean`]) {
|
if (this.hassObjects[`${this.namespace}.${id}state_boolean`]) {
|
||||||
this.setState(`${id}state_boolean`, {
|
await this.setStateAsync(`${id}state_boolean`, {
|
||||||
val: entity.state === 'on',
|
val: entity.state === 'on',
|
||||||
ack: true,
|
ack: true,
|
||||||
lc: lc || Date.now(),
|
lc: lc || Date.now(),
|
||||||
@@ -603,7 +603,28 @@ class HassAdapter extends adapter_core_1.Adapter {
|
|||||||
}
|
}
|
||||||
const attrId = attr.replace(this.FORBIDDEN_CHARS, '_').replace(/\.+$/, '_');
|
const attrId = attr.replace(this.FORBIDDEN_CHARS, '_').replace(/\.+$/, '_');
|
||||||
if (this.hassObjects[`${this.namespace}.${id}state`]) {
|
if (this.hassObjects[`${this.namespace}.${id}state`]) {
|
||||||
this.setState(id + attrId, { val, ack: true, lc, ts });
|
const fullAttrId = `${this.namespace}.${id}${attrId}`;
|
||||||
|
if (!this.hassObjects[fullAttrId]) {
|
||||||
|
// Attribute appeared after initial sync — create object dynamically
|
||||||
|
const common = {
|
||||||
|
...knownAttributes[attr],
|
||||||
|
name: attr.replace(/_/g, ' '),
|
||||||
|
read: true,
|
||||||
|
write: false,
|
||||||
|
role: 'state',
|
||||||
|
type: mapTypes[typeof entity.attributes[attr]] ?? 'mixed',
|
||||||
|
};
|
||||||
|
const newObj = {
|
||||||
|
_id: fullAttrId,
|
||||||
|
type: 'state',
|
||||||
|
common,
|
||||||
|
native: { entity_id: entity.entity_id, attr },
|
||||||
|
};
|
||||||
|
this.log.debug(`Creating missing attribute object ${fullAttrId}`);
|
||||||
|
await this.setForeignObjectAsync(fullAttrId, newObj);
|
||||||
|
this.hassObjects[fullAttrId] = newObj;
|
||||||
|
}
|
||||||
|
await this.setStateAsync(id + attrId, { val, ack: true, lc, ts });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.log.info(`State changed for unknown object ${id + attrId}. Triggering synchronization to resync the objects.`);
|
this.log.info(`State changed for unknown object ${id + attrId}. Triggering synchronization to resync the objects.`);
|
||||||
@@ -616,7 +637,7 @@ class HassAdapter extends adapter_core_1.Adapter {
|
|||||||
if (!this.hassConnected) {
|
if (!this.hassConnected) {
|
||||||
this.log.debug('Connected');
|
this.log.debug('Connected');
|
||||||
this.hassConnected = true;
|
this.hassConnected = true;
|
||||||
this.setState('info.connection', true, true);
|
void this.setState('info.connection', true, true);
|
||||||
this.hass.getConfig(err => {
|
this.hass.getConfig(err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.log.error(`Cannot read config: ${err}`);
|
this.log.error(`Cannot read config: ${err}`);
|
||||||
@@ -661,7 +682,7 @@ class HassAdapter extends adapter_core_1.Adapter {
|
|||||||
if (this.hassConnected) {
|
if (this.hassConnected) {
|
||||||
this.log.debug('Disconnected');
|
this.log.debug('Disconnected');
|
||||||
this.hassConnected = false;
|
this.hassConnected = false;
|
||||||
this.setState('info.connection', false, true);
|
void this.setState('info.connection', false, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.hass.connect();
|
this.hass.connect();
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+11
-32
@@ -2,7 +2,6 @@
|
|||||||
"common": {
|
"common": {
|
||||||
"name": "hass",
|
"name": "hass",
|
||||||
"version": "2.0.4",
|
"version": "2.0.4",
|
||||||
"title": "Home Assistant",
|
|
||||||
"titleLang": {
|
"titleLang": {
|
||||||
"en": "Home Assistant",
|
"en": "Home Assistant",
|
||||||
"de": "Home Assistant",
|
"de": "Home Assistant",
|
||||||
@@ -122,7 +121,9 @@
|
|||||||
"uk": "Знову показати замасковані поля пароля в конфігурації"
|
"uk": "Знову показати замасковані поля пароля в конфігурації"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"localLink": "http://%host%:8123",
|
"localLinks": {
|
||||||
|
"_default": "http://%host%:8123"
|
||||||
|
},
|
||||||
"platform": "Javascript/Node.js",
|
"platform": "Javascript/Node.js",
|
||||||
"mode": "daemon",
|
"mode": "daemon",
|
||||||
"icon": "hass.png",
|
"icon": "hass.png",
|
||||||
@@ -137,17 +138,11 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"extIcon": "https://raw.githubusercontent.com/ioBroker/ioBroker.hass/master/admin/hass.png",
|
"extIcon": "https://raw.githubusercontent.com/ioBroker/ioBroker.hass/master/admin/hass.png",
|
||||||
"keywords": [
|
"keywords": ["HASS", "Home", "assistant"],
|
||||||
"HASS",
|
|
||||||
"Home",
|
|
||||||
"assistant"
|
|
||||||
],
|
|
||||||
"readme": "https://github.com/ioBroker/ioBroker.hass/blob/master/README.md",
|
"readme": "https://github.com/ioBroker/ioBroker.hass/blob/master/README.md",
|
||||||
"loglevel": "info",
|
"loglevel": "info",
|
||||||
"type": "iot-systems",
|
"type": "iot-systems",
|
||||||
"authors": [
|
"authors": ["bluefox <dogafox@gmail.com>"],
|
||||||
"bluefox <dogafox@gmail.com>"
|
|
||||||
],
|
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
{
|
{
|
||||||
"js-controller": ">=6.0.11"
|
"js-controller": ">=6.0.11"
|
||||||
@@ -170,10 +165,7 @@
|
|||||||
{
|
{
|
||||||
"condition": {
|
"condition": {
|
||||||
"operand": "and",
|
"operand": "and",
|
||||||
"rules": [
|
"rules": ["oldVersion<1.1.0", "newVersion>=1.1.0"]
|
||||||
"oldVersion<1.1.0",
|
|
||||||
"newVersion>=1.1.0"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"en": "Re-enter the password after Update!",
|
"en": "Re-enter the password after Update!",
|
||||||
@@ -202,18 +194,12 @@
|
|||||||
"uk": "Після встановлення цього оновлення пароль/токен, який використовується для доступу до встановлення HASS, потрібно повторно ввести в налаштуваннях екземпляра!"
|
"uk": "Після встановлення цього оновлення пароль/токен, який використовується для доступу до встановлення HASS, потрібно повторно ввести в налаштуваннях екземпляра!"
|
||||||
},
|
},
|
||||||
"level": "warn",
|
"level": "warn",
|
||||||
"buttons": [
|
"buttons": ["agree", "cancel"]
|
||||||
"agree",
|
|
||||||
"cancel"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"condition": {
|
"condition": {
|
||||||
"operand": "and",
|
"operand": "and",
|
||||||
"rules": [
|
"rules": ["oldVersion<1.2.0", "newVersion>=1.2.0"]
|
||||||
"oldVersion<1.2.0",
|
|
||||||
"newVersion>=1.2.0"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"en": "Important notice!",
|
"en": "Important notice!",
|
||||||
@@ -242,10 +228,7 @@
|
|||||||
"uk": "Нова версія 1.2.x потенційно змінить назви об’єктів, якщо в атрибутах об’єктів використовувалися спеціальні символи, такі як «.», «-» або пробіли! За потреби видаліть старі об’єкти вручну."
|
"uk": "Нова версія 1.2.x потенційно змінить назви об’єктів, якщо в атрибутах об’єктів використовувалися спеціальні символи, такі як «.», «-» або пробіли! За потреби видаліть старі об’єкти вручну."
|
||||||
},
|
},
|
||||||
"level": "warn",
|
"level": "warn",
|
||||||
"buttons": [
|
"buttons": ["agree", "cancel"]
|
||||||
"agree",
|
|
||||||
"cancel"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -255,12 +238,8 @@
|
|||||||
"password": "",
|
"password": "",
|
||||||
"secure": false
|
"secure": false
|
||||||
},
|
},
|
||||||
"protectedNative": [
|
"protectedNative": ["password"],
|
||||||
"password"
|
"encryptedNative": ["password"],
|
||||||
],
|
|
||||||
"encryptedNative": [
|
|
||||||
"password"
|
|
||||||
],
|
|
||||||
"objects": [],
|
"objects": [],
|
||||||
"instanceObjects": [
|
"instanceObjects": [
|
||||||
{
|
{
|
||||||
|
|||||||
+7
-7
@@ -619,7 +619,7 @@ class HassAdapter extends Adapter {
|
|||||||
desc: service[s].description,
|
desc: service[s].description,
|
||||||
read: false,
|
read: false,
|
||||||
write: true,
|
write: true,
|
||||||
type: 'mixed' as ioBroker.CommonType,
|
type: 'mixed',
|
||||||
role: 'button',
|
role: 'button',
|
||||||
},
|
},
|
||||||
native: {
|
native: {
|
||||||
@@ -676,7 +676,7 @@ class HassAdapter extends Adapter {
|
|||||||
|
|
||||||
if (entity.state !== undefined) {
|
if (entity.state !== undefined) {
|
||||||
if (this.hassObjects[`${this.namespace}.${id}state`]) {
|
if (this.hassObjects[`${this.namespace}.${id}state`]) {
|
||||||
this.setState(`${id}state`, { val: entity.state, ack: true, lc, ts });
|
await this.setStateAsync(`${id}state`, { val: entity.state, ack: true, lc, ts });
|
||||||
} else {
|
} else {
|
||||||
this.log.info(
|
this.log.info(
|
||||||
`State changed for unknown object ${id}state. Triggering synchronization to resync the objects.`,
|
`State changed for unknown object ${id}state. Triggering synchronization to resync the objects.`,
|
||||||
@@ -685,7 +685,7 @@ class HassAdapter extends Adapter {
|
|||||||
}
|
}
|
||||||
// Update boolean state
|
// Update boolean state
|
||||||
if (this.hassObjects[`${this.namespace}.${id}state_boolean`]) {
|
if (this.hassObjects[`${this.namespace}.${id}state_boolean`]) {
|
||||||
this.setState(`${id}state_boolean`, {
|
await this.setStateAsync(`${id}state_boolean`, {
|
||||||
val: entity.state === 'on',
|
val: entity.state === 'on',
|
||||||
ack: true,
|
ack: true,
|
||||||
lc: lc || Date.now(),
|
lc: lc || Date.now(),
|
||||||
@@ -720,7 +720,7 @@ class HassAdapter extends Adapter {
|
|||||||
read: true,
|
read: true,
|
||||||
write: false,
|
write: false,
|
||||||
role: 'state',
|
role: 'state',
|
||||||
type: (mapTypes[typeof entity.attributes[attr]] ?? 'mixed') as ioBroker.CommonType,
|
type: mapTypes[typeof entity.attributes[attr]] ?? 'mixed',
|
||||||
};
|
};
|
||||||
const newObj: ioBroker.StateObject = {
|
const newObj: ioBroker.StateObject = {
|
||||||
_id: fullAttrId,
|
_id: fullAttrId,
|
||||||
@@ -732,7 +732,7 @@ class HassAdapter extends Adapter {
|
|||||||
await this.setForeignObjectAsync(fullAttrId, newObj);
|
await this.setForeignObjectAsync(fullAttrId, newObj);
|
||||||
this.hassObjects[fullAttrId] = newObj;
|
this.hassObjects[fullAttrId] = newObj;
|
||||||
}
|
}
|
||||||
this.setState(id + attrId, { val, ack: true, lc, ts });
|
await this.setStateAsync(id + attrId, { val, ack: true, lc, ts });
|
||||||
} else {
|
} else {
|
||||||
this.log.info(
|
this.log.info(
|
||||||
`State changed for unknown object ${id + attrId}. Triggering synchronization to resync the objects.`,
|
`State changed for unknown object ${id + attrId}. Triggering synchronization to resync the objects.`,
|
||||||
@@ -747,7 +747,7 @@ class HassAdapter extends Adapter {
|
|||||||
if (!this.hassConnected) {
|
if (!this.hassConnected) {
|
||||||
this.log.debug('Connected');
|
this.log.debug('Connected');
|
||||||
this.hassConnected = true;
|
this.hassConnected = true;
|
||||||
this.setState('info.connection', true, true);
|
void this.setState('info.connection', true, true);
|
||||||
this.hass!.getConfig(err => {
|
this.hass!.getConfig(err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.log.error(`Cannot read config: ${err}`);
|
this.log.error(`Cannot read config: ${err}`);
|
||||||
@@ -792,7 +792,7 @@ class HassAdapter extends Adapter {
|
|||||||
if (this.hassConnected) {
|
if (this.hassConnected) {
|
||||||
this.log.debug('Disconnected');
|
this.log.debug('Disconnected');
|
||||||
this.hassConnected = false;
|
this.hassConnected = false;
|
||||||
this.setState('info.connection', false, true);
|
void this.setState('info.connection', false, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user