From 62caea6bfb5fbb084d0cedcd437a1c809c7c26df Mon Sep 17 00:00:00 2001
From: Maciej Bieniek <bieniu@users.noreply.github.com>
Date: Sun, 22 Oct 2017 11:59:24 +0200
Subject: [PATCH] fix temperature/humidity sensors valid values (#10024)

---
 homeassistant/components/sensor/xiaomi_aqara.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/homeassistant/components/sensor/xiaomi_aqara.py b/homeassistant/components/sensor/xiaomi_aqara.py
index 92b4e5b80b9..f375f1ba9ad 100644
--- a/homeassistant/components/sensor/xiaomi_aqara.py
+++ b/homeassistant/components/sensor/xiaomi_aqara.py
@@ -67,6 +67,10 @@ class XiaomiSensor(XiaomiDevice):
         if value is None:
             return False
         value = float(value)
+        if self._data_key in ['temperature', 'humidity', 'pressure']:
+            value /= 100
+        elif self._data_key in ['illumination']:
+            value = max(value - 300, 0)
         if self._data_key == 'temperature' and (value < -20 or value > 60):
             return False
         elif self._data_key == 'humidity' and (value <= 0 or value > 100):
@@ -75,9 +79,5 @@ class XiaomiSensor(XiaomiDevice):
             return False
         elif self._data_key == 'pressure' and value == 0:
             return False
-        if self._data_key in ['temperature', 'humidity', 'pressure']:
-            value /= 100
-        elif self._data_key in ['illumination']:
-            value = max(value - 300, 0)
         self._state = round(value, 2)
         return True