mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Pollen.com: Entity Registry updates and cleanup (#12361)
* Updated Pollen sensors to be entity registry-friendly * Pollen.com: Entity Registry updates and cleanup * Small cleanup * Owner-requested changes
This commit is contained in:
parent
8bff813014
commit
c5c409bed3
@ -16,7 +16,7 @@ from homeassistant.const import (
|
|||||||
ATTR_ATTRIBUTION, ATTR_STATE, CONF_MONITORED_CONDITIONS
|
ATTR_ATTRIBUTION, ATTR_STATE, CONF_MONITORED_CONDITIONS
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle, slugify
|
||||||
|
|
||||||
REQUIREMENTS = ['pypollencom==1.1.1']
|
REQUIREMENTS = ['pypollencom==1.1.1']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -125,6 +125,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
'allergy_index_data': AllergyIndexData(client),
|
'allergy_index_data': AllergyIndexData(client),
|
||||||
'disease_average_data': DiseaseData(client)
|
'disease_average_data': DiseaseData(client)
|
||||||
}
|
}
|
||||||
|
classes = {
|
||||||
|
'AllergyAverageSensor': AllergyAverageSensor,
|
||||||
|
'AllergyIndexSensor': AllergyIndexSensor
|
||||||
|
}
|
||||||
|
|
||||||
for data in datas.values():
|
for data in datas.values():
|
||||||
data.update()
|
data.update()
|
||||||
@ -132,11 +136,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
sensors = []
|
sensors = []
|
||||||
for condition in config[CONF_MONITORED_CONDITIONS]:
|
for condition in config[CONF_MONITORED_CONDITIONS]:
|
||||||
name, sensor_class, data_key, params, icon = CONDITIONS[condition]
|
name, sensor_class, data_key, params, icon = CONDITIONS[condition]
|
||||||
sensors.append(globals()[sensor_class](
|
sensors.append(classes[sensor_class](
|
||||||
datas[data_key],
|
datas[data_key],
|
||||||
params,
|
params,
|
||||||
name,
|
name,
|
||||||
icon
|
icon,
|
||||||
|
config[CONF_ZIP_CODE]
|
||||||
))
|
))
|
||||||
|
|
||||||
add_devices(sensors, True)
|
add_devices(sensors, True)
|
||||||
@ -154,7 +159,7 @@ def calculate_trend(list_of_nums):
|
|||||||
class BaseSensor(Entity):
|
class BaseSensor(Entity):
|
||||||
"""Define a base class for all of our sensors."""
|
"""Define a base class for all of our sensors."""
|
||||||
|
|
||||||
def __init__(self, data, data_params, name, icon):
|
def __init__(self, data, data_params, name, icon, unique_id):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._attrs = {}
|
self._attrs = {}
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
@ -162,6 +167,7 @@ class BaseSensor(Entity):
|
|||||||
self._data_params = data_params
|
self._data_params = data_params
|
||||||
self._state = None
|
self._state = None
|
||||||
self._unit = None
|
self._unit = None
|
||||||
|
self._unique_id = unique_id
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -185,6 +191,11 @@ class BaseSensor(Entity):
|
|||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return a unique, HASS-friendly identifier for this entity."""
|
||||||
|
return '{0}_{1}'.format(self._unique_id, slugify(self._name))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user