Compare commits
2 Commits
261132d9af
...
a7846b54e5
| Author | SHA1 | Date | |
|---|---|---|---|
| a7846b54e5 | |||
| ea8d62710c |
@@ -178,6 +178,10 @@ class EventHandler:
|
||||
self.__ad_api = ad_api
|
||||
self.event_dispatchers = []
|
||||
|
||||
if isinstance(events_block, list):
|
||||
for event in events_block:
|
||||
self.add_dispatcher(event,callback,event_context=event_context)
|
||||
else:
|
||||
for event_block in events_block.values():
|
||||
register_event_with_params(event_block,callback,event_context)
|
||||
|
||||
|
||||
30
virtualevents.py
Normal file
30
virtualevents.py
Normal 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'])
|
||||
|
||||
Reference in New Issue
Block a user