From 200c0a87781d702d5a8308b06a25aed8d30807e8 Mon Sep 17 00:00:00 2001
From: Teemu R <tpr@iki.fi>
Date: Fri, 20 Jul 2018 14:40:10 +0200
Subject: [PATCH] light.tplink: initialize min & max mireds only once, avoid
 i/o outside update (#15571)

* light.tplink: initialize min & max mireds only once, avoid i/o outside update

* revert the index change

* fix indent, sorry for overwriting your fix, balloob
---
 homeassistant/components/light/tplink.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/homeassistant/components/light/tplink.py b/homeassistant/components/light/tplink.py
index 09a4fa3610d..669901f5b57 100644
--- a/homeassistant/components/light/tplink.py
+++ b/homeassistant/components/light/tplink.py
@@ -66,6 +66,8 @@ class TPLinkSmartBulb(Light):
         self._brightness = None
         self._hs = None
         self._supported_features = 0
+        self._min_mireds = None
+        self._max_mireds = None
         self._emeter_params = {}
 
     @property
@@ -107,12 +109,12 @@ class TPLinkSmartBulb(Light):
     @property
     def min_mireds(self):
         """Return minimum supported color temperature."""
-        return kelvin_to_mired(self.smartbulb.valid_temperature_range[1])
+        return self._min_mireds
 
     @property
     def max_mireds(self):
         """Return maximum supported color temperature."""
-        return kelvin_to_mired(self.smartbulb.valid_temperature_range[0])
+        return self._max_mireds
 
     @property
     def color_temp(self):
@@ -195,5 +197,9 @@ class TPLinkSmartBulb(Light):
             self._supported_features += SUPPORT_BRIGHTNESS
         if self.smartbulb.is_variable_color_temp:
             self._supported_features += SUPPORT_COLOR_TEMP
+            self._min_mireds = kelvin_to_mired(
+                self.smartbulb.valid_temperature_range[1])
+            self._max_mireds = kelvin_to_mired(
+                self.smartbulb.valid_temperature_range[0])
         if self.smartbulb.is_color:
             self._supported_features += SUPPORT_COLOR
-- 
GitLab