Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async start() {
const existing = await HomeAssistant.getStates(this.master.connection);
for (let entity of existing)
this._maybeAddEntity(entity.entity_id, entity.state, entity.attributes);
this._unsubscribe = this.master.connection.subscribeEvents((event) => {
const { entity_id, new_state } = event.data;
if (new_state)
this._maybeAddEntity(entity_id, new_state.state, new_state.attributes);
else
this._maybeDeleteEntity(entity_id);
}, 'state_changed');
}