Added a new VirtualEvent class

This commit is contained in:
2026-04-20 22:11:35 +02:00
parent 261132d9af
commit ea8d62710c

30
virtualevents.py Normal file
View File

@@ -0,0 +1,30 @@
import appdaemon.plugins.hass.hassapi as hass
import smartcondition as SmartCondition
from expressionparser import ParsingException
from logger_interface import LoggerInterface
class VirtualEvents(hass.Hass,LoggerInterface):
def initialize(self):
self.initialize_logger_interface(self.get_ad_api())
try: self.mute_logger(self.args['mute'])
except KeyError: pass
self.virtual_events = dict()
if "virtual_events" in self.args:
for event in self.args["virtual_events"]:
try: self.virtual_events[event] = SmartCondition.Evaluator(self,self.args["virtual_events"][event]['event_condition'],condition_name = event,on_succeed_cb = self.on_condition_succeed,pass_condition_name_to_cb = event, trigger_callback_on_activation = False, trigger_callback_on_entity_creation = False)
except ParsingException as e:
self.log_error(str(e))
continue
def on_condition_succeed(self,event_name):
event_yaml = self.args["virtual_events"][event_name]
if 'event_data' in event_yaml:
self.log(f"Sending event {event_yaml['event_name']} data = {event_yaml['event_data']}")
self.fire_event(event_yaml['event_name'],**event_yaml['event_data'])
else:
self.log(f"Sending event {event_yaml['event_name']}")
self.fire_event(event_yaml['event_name'])