Skip to content

Commit

Permalink
fix: final final fix for NaN bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Apr 3, 2020
1 parent b363e27 commit 10325fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/ha-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,19 @@ class HaWebsocket extends EventEmitter {

// Emit on the event type channel
if (emitEvent.event_type) {
this.emit(`ha_events:${msg.event_type}`, cloneDeep(emitEvent));
this.emit(`ha_events:${msg.event_type}`, emitEvent);

// Most specific emit for event_type and entity_id
if (emitEvent.entity_id) {
this.emit(
`ha_events:${msg.event_type}:${emitEvent.entity_id}`,
cloneDeep(emitEvent)
emitEvent
);
}
}

// Emit on all channel
this.emit('ha_events:all', cloneDeep(emitEvent));
this.emit('ha_events:all', emitEvent);
}
}

Expand Down
3 changes: 2 additions & 1 deletion nodes/events-state-changed/events-state-changed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable camelcase */
const cloneDeep = require('lodash.clonedeep');
const EventsHaNode = require('../../lib/events-ha-node');
const { shouldIncludeEvent } = require('../../lib/utils');

Expand Down Expand Up @@ -49,7 +50,7 @@ module.exports = function (RED) {
if (this.isEnabled === false) {
return;
}
const { entity_id, event } = evt;
const { entity_id, event } = cloneDeep(evt);

if (!event.new_state) {
return;
Expand Down
7 changes: 5 additions & 2 deletions nodes/trigger-state/trigger-state.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable camelcase */
const cloneDeep = require('lodash.clonedeep');
const selectn = require('selectn');
const { reduce } = require('p-iteration');

Expand Down Expand Up @@ -96,18 +97,20 @@ module.exports = function (RED) {
}
}

async onEntityStateChanged(eventMessage) {
async onEntityStateChanged(evt) {
if (this.isEnabled === false) {
this.debugToClient(
'incoming: node is currently disabled, ignoring received event'
);
return;
}

if (!selectn('event.new_state', eventMessage)) {
if (!selectn('event.new_state', evt)) {
return;
}

const eventMessage = cloneDeep(evt);

if (
!shouldIncludeEvent(
eventMessage.entity_id,
Expand Down
3 changes: 2 additions & 1 deletion nodes/wait-until/wait-until.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const cloneDeep = require('lodash.clonedeep');
const Joi = require('@hapi/joi');
const selectn = require('selectn');

Expand Down Expand Up @@ -152,7 +153,7 @@ module.exports = function (RED) {
}

async onEntityChange(evt) {
const event = evt.event;
const { event } = cloneDeep(evt);

if (!this.active) {
return;
Expand Down

0 comments on commit 10325fa

Please sign in to comment.