Register light conditions (#570)

This commit is contained in:
Otto Winter 2019-05-30 13:12:12 +02:00 committed by GitHub
parent 8dd971b25e
commit 1ce257c721
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 2 deletions

View file

@ -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(); }

View file

@ -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)

View file

@ -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')

View file

@ -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"];