diff --git a/README.md b/README.md
index 6170c9ab..6d8b597d 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,8 @@ To use, add the following to your `configuration.yaml` file:
```yaml
sensor:
- platform: thermal_comfort
+ poll: true
+ scan_interval: 300
sensors:
livingroom:
friendly_name: Living Room
@@ -33,7 +35,15 @@ sensor:
bedroom:
…
```
-### Configuration Variables
+### Platform Configuration Variables
+
+ - poll
boolean
(optional, default: false)
+ - Set to true if you want the sensors to be polled. This can avoid double calculated values if your input sensors split change updates for humidity and temperature.
+ - scan_interval
boolean
(optional, default: 30)
+ - Change the polling interval in seconds if
poll
is set to true.
+
+
+### Sensor Configuration Variables
- temperature_sensor
string
REQUIRED
- ID of temperature sensor entity to be used for calculations.
diff --git a/custom_components/thermal_comfort/sensor.py b/custom_components/thermal_comfort/sensor.py
index 68746a80..e73d63d8 100644
--- a/custom_components/thermal_comfort/sensor.py
+++ b/custom_components/thermal_comfort/sensor.py
@@ -38,11 +38,12 @@
_LOGGER = logging.getLogger(__name__)
-CONF_TEMPERATURE_SENSOR = 'temperature_sensor'
-CONF_HUMIDITY_SENSOR = 'humidity_sensor'
-CONF_SENSOR_TYPES = 'sensor_types'
ATTR_HUMIDITY = 'humidity'
ATTR_FROST_RISK_LEVEL = 'frost_risk_level'
+CONF_HUMIDITY_SENSOR = 'humidity_sensor'
+CONF_POLL = 'poll'
+CONF_SENSOR_TYPES = 'sensor_types'
+CONF_TEMPERATURE_SENSOR = 'temperature_sensor'
class ThermalComfortDeviceClass(StrEnum):
"""State class for thermal comfort sensors."""
@@ -128,6 +129,7 @@ class SensorType(StrEnum):
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_SENSORS): cv.schema_with_slug_keys(SENSOR_SCHEMA),
+ vol.Optional(CONF_POLL, default=False): cv.boolean,
})
class ThermalPerception(StrEnum):
@@ -179,6 +181,7 @@ async def async_setup_platform(hass, config, async_add_entities,
"""Set up the Thermal Comfort sensors."""
sensors = []
+ should_poll = config.get(CONF_POLL)
for device, device_config in config[CONF_SENSORS].items():
temperature_entity = device_config.get(CONF_TEMPERATURE_SENSOR)
humidity_entity = device_config.get(CONF_HUMIDITY_SENSOR)
@@ -193,6 +196,7 @@ async def async_setup_platform(hass, config, async_add_entities,
temperature_entity,
humidity_entity,
sensor_types,
+ should_poll,
)
for sensor_type in sensor_types:
@@ -233,7 +237,7 @@ def __init__(self, device, device_id, friendly_name, entity_description, icon_te
self._attr_extra_state_attributes = {}
if unique_id is not None:
self._attr_unique_id = unique_id + sensor_type
- self._attr_should_poll = False
+ self._attr_should_poll = self._device.should_poll
@property
def extra_state_attributes(self):
@@ -241,7 +245,7 @@ def extra_state_attributes(self):
async def async_added_to_hass(self):
"""Register callbacks."""
- self._device._sensors.append(self)
+ self._device.sensors.append(self)
async def async_update(self):
"""Update the state of the sensor."""
@@ -291,7 +295,8 @@ def __init__(self,
hass,
temperature_entity,
humidity_entity,
- sensor_types
+ sensor_types,
+ should_poll,
):
"""Initialize the sensor."""
self.hass = hass
@@ -301,7 +306,8 @@ def __init__(self,
self._temperature = None
self._humidity = None
self._sensor_types = sensor_types
- self._sensors = []
+ self.should_poll = should_poll
+ self.sensors = []
self._compute_states = { sensor_type: ComputeState(lock=Lock()) for sensor_type in SENSOR_TYPES.keys() }
temperature_state = hass.states.get(temperature_entity)
@@ -471,8 +477,8 @@ async def async_update(self):
if self._temperature is not None and self._humidity is not None:
for sensor_type in SENSOR_TYPES.keys():
self._compute_states[sensor_type].needs_update = True
- for sensor in self._sensors:
- if sensor is not None:
+ if not self.should_poll:
+ for sensor in self.sensors:
sensor.async_schedule_update_ha_state(True)