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
This commit is contained in:
parent
e419689229
commit
fe749fc0f8
1 changed files with 13 additions and 7 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue