From 22e8286a59a215dd1aac077869d90aaf6f24beac Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Tue, 15 May 2018 05:21:36 -0400
Subject: [PATCH] Redo restoring lights a second time in case any lights were
 missed.

---
 src/get-weather.js       |  1 -
 src/weather-to-lights.js | 25 +++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/get-weather.js b/src/get-weather.js
index db2552f..14b9873 100755
--- a/src/get-weather.js
+++ b/src/get-weather.js
@@ -13,7 +13,6 @@ function getWeather(fn) {
     if(err){
       console.log('error:', error);
     } else {
-      console.log(`weather: ${body}`);
       let weather = JSON.parse(body)
       fn(weather);
     }
diff --git a/src/weather-to-lights.js b/src/weather-to-lights.js
index b05574a..1675f6f 100755
--- a/src/weather-to-lights.js
+++ b/src/weather-to-lights.js
@@ -8,6 +8,7 @@ let getOnLights = require('./get-on-lights');
 let sleep = require('./sleep');
 let retry = require('./retry');
 
+const REDO_DURATION = 60000;
 const RAIN_DURATION = 15000;
 const MIN_DURATION = 15000;
 const MAX_DURATION = 15000;
@@ -114,6 +115,30 @@ getWeather(weatherInfo => {
           }
 
 
+          retry(() => client.lights.save(light) );
+        }
+      });
+
+      sleep(REDO_DURATION).then(() => {
+        for (let lightData of onLights) {
+          let light = lightData.light;
+
+          light.alert = "none";
+          light.brightness = lightData.brightness;
+          if(light.colorMode.includes("hs")) {
+            light.hue = lightData.hue;
+            light.saturation = lightData.saturation;
+          }
+
+          if(light.colorMode.includes("xy")) {
+            light.xy = lightData.xy;
+          }
+
+          if(light.colorMode.includes("ct")) {
+            light.colorTemp = lightData.colorTemp;
+          }
+
+
           retry(() => client.lights.save(light) );
         }
       });
-- 
GitLab