mirror of
https://github.com/esphome/esphome.git
synced 2024-11-18 11:06:11 +01:00
Register light conditions (#570)
This commit is contained in:
parent
31821e6309
commit
f2d6817d8a
@ -89,7 +89,7 @@ template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> {
|
||||
protected:
|
||||
LightState *state_;
|
||||
};
|
||||
template<typename... Ts> class LightIsOffCondition : public Condition<LightState, Ts...> {
|
||||
template<typename... Ts> class LightIsOffCondition : public Condition<Ts...> {
|
||||
public:
|
||||
explicit LightIsOffCondition(LightState *state) : state_(state) {}
|
||||
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_COLOR_TEMPERATURE, CONF_RANGE_FROM, CONF_RANGE_TO
|
||||
from .types import DimRelativeAction, ToggleAction, LightState, LightControlAction, \
|
||||
AddressableLightState, AddressableSet
|
||||
AddressableLightState, AddressableSet, LightIsOnCondition, LightIsOffCondition
|
||||
|
||||
|
||||
@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)
|
||||
cg.add(var.set_white(templ))
|
||||
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)
|
||||
DimRelativeAction = light_ns.class_('DimRelativeAction', automation.Action)
|
||||
AddressableSet = light_ns.class_('AddressableSet', automation.Action)
|
||||
LightIsOnCondition = light_ns.class_('LightIsOnCondition', automation.Condition)
|
||||
LightIsOffCondition = light_ns.class_('LightIsOffCondition', automation.Condition)
|
||||
|
||||
# Effects
|
||||
LightEffect = light_ns.class_('LightEffect')
|
||||
|
@ -84,6 +84,8 @@ mqtt:
|
||||
condition:
|
||||
- wifi.connected:
|
||||
- mqtt.connected:
|
||||
- light.is_on: kitchen
|
||||
- light.is_off: kitchen
|
||||
then:
|
||||
- lambda: |-
|
||||
int data = x["my_data"];
|
||||
|
Loading…
Reference in New Issue
Block a user