Merge branch 'master' into upstream-pr-entity-filter
This commit is contained in:
+4
-3
@@ -108,11 +108,12 @@ export default class HASS extends EventEmitter {
|
||||
this.emit('state_changed', response.event.data.new_state);
|
||||
}
|
||||
} 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');
|
||||
socket.terminate();
|
||||
} else {
|
||||
setTimeout(() => this.sendAuth(socket, this.options.password!), 50);
|
||||
setTimeout(() => this.sendAuth(socket, password), 50);
|
||||
}
|
||||
} else if (response.type === 'auth_ok') {
|
||||
setImmediate(() =>
|
||||
@@ -228,7 +229,7 @@ export default class HASS extends EventEmitter {
|
||||
}
|
||||
|
||||
this.socket = new WebSocket(
|
||||
`ws${this.options.secure ? 's' : ''}://${this.options.host}:${this.options.port}/api/websocket`,
|
||||
`ws${this.options.secure ? 's' : ''}://${this.options.host}:${this.options.port}/${this.options.host === 'supervisor' ? 'core' : 'api'}/websocket`,
|
||||
{ perMessageDeflate: false },
|
||||
);
|
||||
|
||||
|
||||
+28
-7
@@ -635,7 +635,7 @@ class HassAdapter extends Adapter {
|
||||
desc: service[s].description,
|
||||
read: false,
|
||||
write: true,
|
||||
type: 'mixed' as ioBroker.CommonType,
|
||||
type: 'mixed',
|
||||
role: 'button',
|
||||
},
|
||||
native: {
|
||||
@@ -817,7 +817,7 @@ class HassAdapter extends Adapter {
|
||||
|
||||
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)}`);
|
||||
if (!entity || typeof entity.entity_id !== 'string') {
|
||||
return;
|
||||
@@ -834,7 +834,7 @@ class HassAdapter extends Adapter {
|
||||
|
||||
if (entity.state !== undefined) {
|
||||
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 {
|
||||
this.log.info(
|
||||
`State changed for unknown object ${id}state. Triggering synchronization to resync the objects.`,
|
||||
@@ -843,7 +843,7 @@ class HassAdapter extends Adapter {
|
||||
}
|
||||
// Update boolean state
|
||||
if (this.hassObjects[`${this.namespace}.${id}state_boolean`]) {
|
||||
this.setState(`${id}state_boolean`, {
|
||||
await this.setStateAsync(`${id}state_boolean`, {
|
||||
val: entity.state === 'on',
|
||||
ack: true,
|
||||
lc: lc || Date.now(),
|
||||
@@ -869,7 +869,28 @@ class HassAdapter extends Adapter {
|
||||
}
|
||||
const attrId = attr.replace(this.FORBIDDEN_CHARS, '_').replace(/\.+$/, '_');
|
||||
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: ioBroker.StateCommon = {
|
||||
...(knownAttributes[attr] as ioBroker.StateCommon | undefined),
|
||||
name: attr.replace(/_/g, ' '),
|
||||
read: true,
|
||||
write: false,
|
||||
role: 'state',
|
||||
type: mapTypes[typeof entity.attributes[attr]] ?? 'mixed',
|
||||
};
|
||||
const newObj: ioBroker.StateObject = {
|
||||
_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 {
|
||||
this.log.info(
|
||||
`State changed for unknown object ${id + attrId}. Triggering synchronization to resync the objects.`,
|
||||
@@ -884,7 +905,7 @@ class HassAdapter extends Adapter {
|
||||
if (!this.hassConnected) {
|
||||
this.log.debug('Connected');
|
||||
this.hassConnected = true;
|
||||
this.setState('info.connection', true, true);
|
||||
void this.setState('info.connection', true, true);
|
||||
this.hass!.getConfig(err => {
|
||||
if (err) {
|
||||
this.log.error(`Cannot read config: ${err}`);
|
||||
@@ -929,7 +950,7 @@ class HassAdapter extends Adapter {
|
||||
if (this.hassConnected) {
|
||||
this.log.debug('Disconnected');
|
||||
this.hassConnected = false;
|
||||
this.setState('info.connection', false, true);
|
||||
void this.setState('info.connection', false, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user