More Mobile app sensor fixes (#22914)
* Ensure we only add a sensor once * Ensure that we dont process updates for entities that arent what we were setup for * Add debug logging to ease development of apps * Use str representation
This commit is contained in:
1 parent
64ea13104e
commit
fd8d9747ef
4 files changed
+40
-5
No files matched your search
@@ -7,9 +7,10 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import (ATTR_SENSOR_STATE,
|
||||
ATTR_SENSOR_TYPE_SENSOR as ENTITY_TYPE,
|
||||
ATTR_SENSOR_UOM, DATA_DEVICES, DOMAIN)
|
||||
ATTR_SENSOR_UNIQUE_ID, ATTR_SENSOR_UOM, DATA_DEVICES,
|
||||
DOMAIN)
|
||||
|
||||
from .entity import MobileAppEntity
|
||||
from .entity import MobileAppEntity, sensor_id
|
||||
|
||||
DEPENDENCIES = ['mobile_app']
|
||||
|
||||
@@ -35,6 +36,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
if data[CONF_WEBHOOK_ID] != webhook_id:
|
||||
return
|
||||
|
||||
unique_id = sensor_id(data[CONF_WEBHOOK_ID],
|
||||
data[ATTR_SENSOR_UNIQUE_ID])
|
||||
|
||||
entity = hass.data[DOMAIN][ENTITY_TYPE][unique_id]
|
||||
|
||||
if 'added' in entity:
|
||||
return
|
||||
|
||||
entity['added'] = True
|
||||
|
||||
device = hass.data[DOMAIN][DATA_DEVICES][data[CONF_WEBHOOK_ID]]
|
||||
|
||||
async_add_entities([MobileAppSensor(data, device, config_entry)])
|
||||
|
||||
Reference in new issue
Block a user