wall_buttons.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """
  2. trigger file.wall_buttons.hallway_wall_button got event trigger, running action
  3. (kwargs = {
  4. 'trigger_type': 'event',
  5. 'event_type': 'button_pressed',
  6. 'context': Context(user_id=None,
  7. parent_id=None,
  8. id='67d442d5b0b4c1f3308417722801f709'),
  9. 'entity_id': 'switch.hall_switch',
  10. 'state': 'on'
  11. })
  12. kalle = kwargs.context.get("entity_id", None)
  13. ^
  14. AttributeError: 'dict' object has no attribute 'context'
  15. """
  16. # Mode Panel:
  17. # 1: All ON
  18. # 2: Windows
  19. # 3: Morning-mode
  20. # 4: All OFF
  21. """
  22. ERROR:
  23. 2021-05-13 20:52:14 ERROR (MainThread) [custom_components.pyscript.function] run_coro: got exception Traceback (most recent call last):
  24. File "/config/custom_components/pyscript/eval.py", line 710, in call
  25. raise TypeError(f"{self.name}() called with unexpected keyword arguments: {unexpected}")
  26. TypeError: hallway_wall_button() called with unexpected keyword arguments: state
  27. got button_pressed: kwargs={
  28. 'trigger_type': 'event',
  29. 'event_type': 'button_pressed',
  30. 'context': Context(user_id=None, parent_id=None, id='01ce32cfcc4bed50ce9301ae967fa951'),
  31. 'entity_id': 'switch.mode_panel_4',
  32. 'state': 'off'}
  33. """
  34. @event_trigger( "button_pressed" )
  35. def hallway_wall_button(entity_id=None, state=None):
  36. log.info(f"*************** * got EVENT_CALL_SERVICE with Id:{entity_id} State:{state}")
  37. if( entity_id == 'switch.hall_switch' ):
  38. if( switch.group_button_all == 'on'):
  39. pyscript.state_goto_all_off()
  40. else:
  41. pyscript.state_goto_all_on()
  42. if( entity_id == 'switch.mode_panel_1' ): # All ON
  43. pyscript.state_goto_all_on()
  44. if( entity_id == 'switch.mode_panel_2' ): # Window
  45. pyscript.state_goto_window()
  46. #log.info(f"This mode has been disabled.")
  47. if( entity_id == 'switch.mode_panel_3' ): # Morning
  48. #log.info(f"This mode has been disabled.")
  49. pyscript.state_goto_morning()
  50. if( entity_id == 'switch.mode_panel_4' ): # All OFF
  51. pyscript.state_goto_all_off()
  52. if( entity_id == 'switch.mode_panel_kwl' ): # Kitchen work lights
  53. input_boolean.toggle(entity_id='input_boolean.kitchen_worklights')
  54. # This will trigger kitchen_worklights_button_trigger()