From cdd57e5b07c64f2126f7b69141168921662d7416 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git@ethitter.com>
Date: Tue, 20 Dec 2016 00:11:04 +0000
Subject: [PATCH] Simplify how configuration is read, allowing arbitrary states
 to trigger arbitrary responses

Allows one handler to encompass what the Dash SHM and Dash Home Assistant integrations required.

Breaking change, though, as configuration variables change
---
 index.js | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/index.js b/index.js
index a522baa..a402f1a 100644
--- a/index.js
+++ b/index.js
@@ -92,14 +92,11 @@ function buttonActivated( mac ) {
         var service  = 'services/',
             postBody = {};
 
-        if ( 'off' === body.state ) {
-            service            += buttonConfig.on.entity + '/' + buttonConfig.on.entity_action;
-            postBody.entity_id = buttonConfig.on.entity_id;
-        } else if ( 'on' === body.state ) {
-            service            += buttonConfig.off.entity + '/' + buttonConfig.off.entity_action;
-            postBody.entity_id = buttonConfig.off.entity_id;
+        if ( 'object' === typeof buttonConfig[ body.state ] ) {
+            service            += buttonConfig[ body.state ].entity + '/' + buttonConfig[ body.state ].entity_action;
+            postBody.entity_id  = buttonConfig[ body.state ].entity_id;
         } else {
-            console.error( 'Unknown state: ' + body.state );
+            console.error( 'Unhandled state: ' + body.state );
             return;
         }
 
-- 
GitLab