Procházet zdrojové kódy

Corrected function arguments

pi před 3 roky
rodič
revize
2a19a62aea
1 změnil soubory, kde provedl 7 přidání a 5 odebrání
  1. 7 5
      pyscript/bedroom.py

+ 7 - 5
pyscript/bedroom.py

@@ -5,8 +5,11 @@ from homeassistant.const import EVENT_STATE_CHANGED
 # This script reacts to the actual sensor on the door
 # It sets the input_boolean which keeps its state during restarts
 # Arguments could be: (entity_id=None, new_state=None, old_state=None):
+#
+#  TypeError: bedroom_door_raw_sensor() called with unexpected keyword arguments: entity_id, new_state, old_state
+#
 @event_trigger(EVENT_STATE_CHANGED, "entity_id=='binary_sensor.bedroom_door_raw_sensor'")
-def bedroom_door_raw_sensor():
+def bedroom_door_raw_sensor(entity_id, new_state, old_state):
     #log.info(f"monitor_bedroom_door_event: entity {entity_id} changed from {old_state} to {new_state}")
     log.info(f"********* BEDROOM RAW SENSOR: "+binary_sensor.bedroom_door_raw_sensor+" ***********")
     input_boolean.bedroom_door = binary_sensor.bedroom_door_raw_sensor
@@ -23,15 +26,14 @@ def handle_bedroom_light():
     log.info(f"********* BEDROOM LIGHT CONTROL **** Btn_4:" + light.main_button_4 + " Door:"+ input_boolean.bedroom_door)
     task.sleep(1)
 
-    # The door sensor is out of battery, and thats why I disable this for now
-    #if light.main_button_4 == 'on' and input_boolean.bedroom_door == 'on':
-    if light.main_button_4 == 'on':
+    # Select which line to used based on if there is power in the door sensor battery
+    if light.main_button_4 == 'on' and input_boolean.bedroom_door == 'on':
+        #if light.main_button_4 == 'on':    # Use if battery is out of power
         # If OPEN
         switch.turn_on(entity_id='switch.tradfri_outlet')
     else:
         switch.turn_off(entity_id='switch.tradfri_outlet')
 
-
 """
 # This way does not work, beacuse it does not react to "off" when the door is already "off/aka Unknown" after a restart of HA
 @state_trigger("binary_sensor.bedroom_door_raw_sensor")