From fe749fc0f8eaba9ccea5b389e1b91be2d684d363 Mon Sep 17 00:00:00 2001
From: shred86 <32663154+shred86@users.noreply.github.com>
Date: Mon, 4 Nov 2019 12:49:11 -0800
Subject: [PATCH] Fix sensor device in the Abode component (#28516)

* Fix for occupancy sensor unique_id

* Add check for sensor attributes before adding entity

* Fixes temperature key issue

* Clean up code with better use of keys

* Code clean up
---
 homeassistant/components/abode/sensor.py | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/homeassistant/components/abode/sensor.py b/homeassistant/components/abode/sensor.py
index e25921f295f..6ee0cf59cbf 100644
--- a/homeassistant/components/abode/sensor.py
+++ b/homeassistant/components/abode/sensor.py
@@ -16,9 +16,9 @@ _LOGGER = logging.getLogger(__name__)
 
 # Sensor types: Name, icon
 SENSOR_TYPES = {
-    "temp": ["Temperature", DEVICE_CLASS_TEMPERATURE],
-    "humidity": ["Humidity", DEVICE_CLASS_HUMIDITY],
-    "lux": ["Lux", DEVICE_CLASS_ILLUMINANCE],
+    CONST.TEMP_STATUS_KEY: ["Temperature", DEVICE_CLASS_TEMPERATURE],
+    CONST.HUMI_STATUS_KEY: ["Humidity", DEVICE_CLASS_HUMIDITY],
+    CONST.LUX_STATUS_KEY: ["Lux", DEVICE_CLASS_ILLUMINANCE],
 }
 
 
@@ -29,15 +29,16 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
 
 async def async_setup_entry(hass, config_entry, async_add_entities):
     """Set up a sensor for an Abode device."""
-
     data = hass.data[DOMAIN]
+    entities = []
 
-    devices = []
     for device in data.abode.get_devices(generic_type=CONST.TYPE_SENSOR):
         for sensor_type in SENSOR_TYPES:
-            devices.append(AbodeSensor(data, device, sensor_type))
+            if sensor_type not in device.get_value(CONST.STATUSES_KEY):
+                continue
+            entities.append(AbodeSensor(data, device, sensor_type))
 
-    async_add_entities(devices)
+    async_add_entities(entities)
 
 
 class AbodeSensor(AbodeDevice):
@@ -62,6 +63,11 @@ class AbodeSensor(AbodeDevice):
         """Return the device class."""
         return self._device_class
 
+    @property
+    def unique_id(self):
+        """Return a unique ID to use for this device."""
+        return f"{self._device.device_uuid}-{self._sensor_type}"
+
     @property
     def state(self):
         """Return the state of the sensor."""
-- 
GitLab