Skip to content

Commit

Permalink
fix: Use correct entity type when removing node from integration
Browse files Browse the repository at this point in the history
fixes #217
  • Loading branch information
zachowj committed Mar 9, 2020
1 parent 66345c9 commit f842578
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/events-ha-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ class EventsHaNode extends EventsNode {
removeFromHomeAssistant(nodeRemoved = false) {
if (
this.websocketClient.integrationVersion === 0 ||
(!this.removeFromHA && !nodeRemoved)
(!this.removeFromHA && !nodeRemoved) ||
(this.nodeConfig.entityType &&
this.nodeConfig.entityType !== 'switch')
) {
return;
}
Expand Down
16 changes: 6 additions & 10 deletions nodes/entity/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ module.exports = function(RED) {

async init() {
await this.loadPersistedData();

this.addEventClientListener(
`ha_events:config_update`,
this.onConfigUpdate.bind(this)
);

if (this.isConnected) {
this.registerEntity();
}
}

setConnectionStatus(additionalText) {
Expand Down Expand Up @@ -153,7 +144,12 @@ module.exports = function(RED) {
onClose(removed) {
super.onClose(removed);

if (this.registered && this.isConnected && removed) {
if (
this.nodeConfig.entityType !== 'switch' &&
this.registered &&
this.isConnected &&
removed
) {
const payload = {
type: 'nodered/discovery',
server_id: this.nodeConfig.server.id,
Expand Down

0 comments on commit f842578

Please sign in to comment.