Added warning to information collector
This commit is contained in:
1 parent
c34dc7fdd3
commit
956ade4d03
3 files changed
+82
No files matched your search
@@ -51,6 +51,24 @@ class InformationsCollector(SmartObject):
|
||||
else:
|
||||
self.log_error("No output_sensor defined for error_collector")
|
||||
|
||||
if 'warning_collector' in self.args:
|
||||
if 'output_sensor' in self.args['warning_collector']:
|
||||
sensor_name = self.args['warning_collector']['output_sensor']
|
||||
self.warning_list = []
|
||||
self.warning_log_handle = self.listen_log(self.on_log_warning, "WARNING", log="main_log")
|
||||
self.warning_count_sensor = self.create_entity(
|
||||
sensor_name, state=0,
|
||||
attributes={"last_warning": "", "warning_list": []},
|
||||
icon="mdi:alert-outline"
|
||||
)
|
||||
if 'reset_warning_count_button' in self.args['warning_collector']:
|
||||
self.listen_state(
|
||||
self.on_reset_warning_count,
|
||||
self.args['warning_collector']['reset_warning_count_button']
|
||||
)
|
||||
else:
|
||||
self.log_error("No output_sensor defined for warning_collector")
|
||||
|
||||
if 'min_max_temp_sensors' in self.args:
|
||||
for sensor in self.args['min_max_temp_sensors']['temperature_sensors']:
|
||||
self.listen_state(self.on_temperature_change, sensor)
|
||||
@@ -218,6 +236,21 @@ class InformationsCollector(SmartObject):
|
||||
self.error_list.clear()
|
||||
self.error_count_sensor.set_state(state=0, attributes={"last_error": "", "error_list": self.error_list})
|
||||
|
||||
def on_log_warning(self, name, ts, level, type, message, kwargs):
|
||||
warning_count = int(self.warning_count_sensor.get_state()) + 1
|
||||
self.warning_list.append(message)
|
||||
self.warning_count_sensor.set_state(
|
||||
state=warning_count,
|
||||
attributes={"last_warning": message, "warning_list": self.warning_list}
|
||||
)
|
||||
|
||||
def on_reset_warning_count(self, entity, attribute, old, new, kwargs):
|
||||
self.warning_list.clear()
|
||||
self.warning_count_sensor.set_state(
|
||||
state=0,
|
||||
attributes={"last_warning": "", "warning_list": self.warning_list}
|
||||
)
|
||||
|
||||
def _on_group_condition_changed(self, prev_result,result):
|
||||
self.update_group_collectors()
|
||||
|
||||
|
||||
Reference in new issue
Block a user