mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Register light conditions (#570)
This commit is contained in:
		| @@ -89,7 +89,7 @@ template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> { | |||||||
|  protected: |  protected: | ||||||
|   LightState *state_; |   LightState *state_; | ||||||
| }; | }; | ||||||
| template<typename... Ts> class LightIsOffCondition : public Condition<LightState, Ts...> { | template<typename... Ts> class LightIsOffCondition : public Condition<Ts...> { | ||||||
|  public: |  public: | ||||||
|   explicit LightIsOffCondition(LightState *state) : state_(state) {} |   explicit LightIsOffCondition(LightState *state) : state_(state) {} | ||||||
|   bool check(Ts... x) override { return !this->state_->current_values.is_on(); } |   bool check(Ts... x) override { return !this->state_->current_values.is_on(); } | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ from esphome.const import CONF_ID, CONF_TRANSITION_LENGTH, CONF_STATE, CONF_FLAS | |||||||
|     CONF_EFFECT, CONF_BRIGHTNESS, CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, \ |     CONF_EFFECT, CONF_BRIGHTNESS, CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, \ | ||||||
|     CONF_COLOR_TEMPERATURE, CONF_RANGE_FROM, CONF_RANGE_TO |     CONF_COLOR_TEMPERATURE, CONF_RANGE_FROM, CONF_RANGE_TO | ||||||
| from .types import DimRelativeAction, ToggleAction, LightState, LightControlAction, \ | from .types import DimRelativeAction, ToggleAction, LightState, LightControlAction, \ | ||||||
|     AddressableLightState, AddressableSet |     AddressableLightState, AddressableSet, LightIsOnCondition, LightIsOffCondition | ||||||
|  |  | ||||||
|  |  | ||||||
| @automation.register_action('light.toggle', ToggleAction, automation.maybe_simple_id({ | @automation.register_action('light.toggle', ToggleAction, automation.maybe_simple_id({ | ||||||
| @@ -145,3 +145,16 @@ def light_addressable_set_to_code(config, action_id, template_arg, args): | |||||||
|         templ = yield cg.templatable(config[CONF_WHITE], args, cg.uint8, to_exp=rgbw_to_exp) |         templ = yield cg.templatable(config[CONF_WHITE], args, cg.uint8, to_exp=rgbw_to_exp) | ||||||
|         cg.add(var.set_white(templ)) |         cg.add(var.set_white(templ)) | ||||||
|     yield var |     yield var | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @automation.register_condition('light.is_on', LightIsOnCondition, | ||||||
|  |                                automation.maybe_simple_id({ | ||||||
|  |                                    cv.Required(CONF_ID): cv.use_id(LightState), | ||||||
|  |                                })) | ||||||
|  | @automation.register_condition('light.is_off', LightIsOffCondition, | ||||||
|  |                                automation.maybe_simple_id({ | ||||||
|  |                                    cv.Required(CONF_ID): cv.use_id(LightState), | ||||||
|  |                                })) | ||||||
|  | def binary_sensor_is_on_to_code(config, condition_id, template_arg, args): | ||||||
|  |     paren = yield cg.get_variable(config[CONF_ID]) | ||||||
|  |     yield cg.new_Pvariable(condition_id, template_arg, paren) | ||||||
|   | |||||||
| @@ -16,6 +16,8 @@ ToggleAction = light_ns.class_('ToggleAction', automation.Action) | |||||||
| LightControlAction = light_ns.class_('LightControlAction', automation.Action) | LightControlAction = light_ns.class_('LightControlAction', automation.Action) | ||||||
| DimRelativeAction = light_ns.class_('DimRelativeAction', automation.Action) | DimRelativeAction = light_ns.class_('DimRelativeAction', automation.Action) | ||||||
| AddressableSet = light_ns.class_('AddressableSet', automation.Action) | AddressableSet = light_ns.class_('AddressableSet', automation.Action) | ||||||
|  | LightIsOnCondition = light_ns.class_('LightIsOnCondition', automation.Condition) | ||||||
|  | LightIsOffCondition = light_ns.class_('LightIsOffCondition', automation.Condition) | ||||||
|  |  | ||||||
| # Effects | # Effects | ||||||
| LightEffect = light_ns.class_('LightEffect') | LightEffect = light_ns.class_('LightEffect') | ||||||
|   | |||||||
| @@ -84,6 +84,8 @@ mqtt: | |||||||
|         condition: |         condition: | ||||||
|           - wifi.connected: |           - wifi.connected: | ||||||
|           - mqtt.connected: |           - mqtt.connected: | ||||||
|  |           - light.is_on: kitchen | ||||||
|  |           - light.is_off: kitchen | ||||||
|         then: |         then: | ||||||
|         - lambda: |- |         - lambda: |- | ||||||
|             int data = x["my_data"]; |             int data = x["my_data"]; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user