From 5e64d21b5581c981031c90edf6b263866dce95f7 Mon Sep 17 00:00:00 2001
From: Ellis Percival <flyte@failcode.co.uk>
Date: Fri, 28 Jul 2017 18:41:32 +0100
Subject: [PATCH] Implement 'inverted' config value for digital outputs.

---
 config.schema.yml      | 6 +++++-
 pi_mqtt_gpio/server.py | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/config.schema.yml b/config.schema.yml
index 8eec9d4..5ebb7f1 100644
--- a/config.schema.yml
+++ b/config.schema.yml
@@ -128,4 +128,8 @@ digital_outputs:
       off_payload:
         type: string
         required: no
-        empty: no
\ No newline at end of file
+        empty: no
+      inverted:
+        type: boolean
+        required: no
+        default: no
\ No newline at end of file
diff --git a/pi_mqtt_gpio/server.py b/pi_mqtt_gpio/server.py
index 095657d..5980bc9 100644
--- a/pi_mqtt_gpio/server.py
+++ b/pi_mqtt_gpio/server.py
@@ -131,12 +131,13 @@ def set_pin(output_config, value):
     :rtype: NoneType
     """
     gpio = GPIO_MODULES[output_config["module"]]
-    gpio.set_pin(output_config["pin"], value)
+    set_value = not value if output_config["inverted"] else value
+    gpio.set_pin(output_config["pin"], set_value)
     _LOG.info(
         "Set %r output %r to %r",
         output_config["module"],
         output_config["name"],
-        value)
+        set_value)
     payload = output_config["on_payload" if value else "off_payload"]
     client.publish(
         "%s/%s/%s" % (topic_prefix, OUTPUT_TOPIC, output_config["name"]),
-- 
GitLab