forked from platypush/platypush
Update the _last_measurement
only if some events were processed from the new data.
This commit is contained in:
parent
88784985e1
commit
fcdda40c4a
1 changed files with 11 additions and 4 deletions
|
@ -276,17 +276,20 @@ class SensorPlugin(RunnablePlugin, SensorEntityManager, ABC):
|
||||||
|
|
||||||
def _process_sensor_events(
|
def _process_sensor_events(
|
||||||
self, old_data: Optional[SensorDataType], new_data: Optional[SensorDataType]
|
self, old_data: Optional[SensorDataType], new_data: Optional[SensorDataType]
|
||||||
):
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Given the previous and new measurement, it runs the comparison logic
|
Given the previous and new measurement, it runs the comparison logic
|
||||||
against the configured tolerance values and thresholds, and it
|
against the configured tolerance values and thresholds, and it
|
||||||
processes the required sensor data change and above/below threshold
|
processes the required sensor data change and above/below threshold
|
||||||
events.
|
events.
|
||||||
|
|
||||||
|
:return: ``True`` if some events were processed for the new data,
|
||||||
|
``False`` otherwise.
|
||||||
"""
|
"""
|
||||||
# If the new data is missing or there are no changes, there are no
|
# If the new data is missing or there are no changes, there are no
|
||||||
# events to process
|
# events to process
|
||||||
if new_data is None or not self._has_changes(old_data, new_data):
|
if new_data is None or not self._has_changes(old_data, new_data):
|
||||||
return
|
return False
|
||||||
|
|
||||||
events = [
|
events = [
|
||||||
SensorDataChangeEvent(
|
SensorDataChangeEvent(
|
||||||
|
@ -300,6 +303,7 @@ class SensorPlugin(RunnablePlugin, SensorEntityManager, ABC):
|
||||||
get_bus().post(event)
|
get_bus().post(event)
|
||||||
|
|
||||||
self.publish_entities(new_data)
|
self.publish_entities(new_data)
|
||||||
|
return True
|
||||||
|
|
||||||
def _update_last_measurement(self, new_data: SensorDataType):
|
def _update_last_measurement(self, new_data: SensorDataType):
|
||||||
"""
|
"""
|
||||||
|
@ -415,7 +419,10 @@ class SensorPlugin(RunnablePlugin, SensorEntityManager, ABC):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
new_data = self._filter_enabled_sensors(new_data)
|
new_data = self._filter_enabled_sensors(new_data)
|
||||||
self._process_sensor_events(self._last_measurement, new_data)
|
is_event_processed = self._process_sensor_events(
|
||||||
|
self._last_measurement, new_data
|
||||||
|
)
|
||||||
|
if is_event_processed:
|
||||||
self._update_last_measurement(new_data)
|
self._update_last_measurement(new_data)
|
||||||
self.wait_stop(self.poll_interval)
|
self.wait_stop(self.poll_interval)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue