clydebarrow / esphome

ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
https://esphome.io/
Other
24 stars 11 forks source link

Lambdas for widgets states/flags #65

Open nagyrobi opened 8 months ago

nagyrobi commented 8 months ago

To make complex automations, we need some easily usable lambdas to get the states and flags of the widgets. These are all booleans so their usage in conditions as lambdas would be very easy.

Use case:

      - if:
          condition:
            lambda: |-
              return id(my_widget).state.checked; #or id(my_widget).flag.hidden;
          then:
            -  do.something

States:

  • default (Optional, boolean): Normal, released state
  • disabled (Optional, boolean): Disabled state
  • pressed (Optional, boolean): Being pressed
  • checked (Optional, boolean): Toggled or checked state
  • scrolled (Optional, boolean): Being scrolled
  • focused (Optional, boolean): Focused via keypad or encoder or clicked via touchpad/mouse
  • focus_key (Optional, boolean): Focused via keypad or encoder but not via touchpad/mouse
  • edited (Optional, boolean): Edit by an encoder
  • user_1, user_2, user_3, user_4 (Optional, boolean): Custom states

Flags:

  • hidden (Optional, boolean): make the widget hidden (like it wasn't there at all),
  • checkable (Optional, boolean): toggle checked state when the widget is clicked
  • clickable (Optional, boolean): make the widget clickable by input devices.
  • click_focusable (Optional, boolean): add focused state to the widget when clicked
  • scrollable (Optional, boolean): make the widget scrollable
  • scroll_elastic (Optional, boolean): allow scrolling inside but with slower speed
  • scroll_momentum (Optional, boolean): make the widget scroll further when "thrown"
  • scroll_one (Optional, boolean): allow scrolling only one snappable children
  • scroll_chain_hor (Optional, boolean): allow propagating the horizontal scroll to a parent
  • scroll_chain_ver (Optional, boolean): allow propagating the vertical scroll to a parent
  • scroll_chain simple (Optional, boolean): packaging for (scroll_chain_hor | scroll_chain_ver)
  • scroll_on_focus (Optional, boolean): automatically scroll widget to make it visible when focused
  • scroll_with_arrow (Optional, boolean): allow scrolling the focused widget with arrow keys
  • snappable (Optional, boolean): if scroll snap is enabled on the parent it can snap to this widget
  • press_lock (Optional, boolean): keep the widget pressed even if the press slid from the widget
  • event_bubble (Optional, boolean): propagate the events to the parent too
  • gesture_bubble (Optional, boolean): propagate the gestures to the parent
  • adv_hittest (Optional, boolean): allow performing more accurate hit (click) test. E.g. Accounting for rounded corners
  • ignore_layout (Optional, boolean): make the widget positionable by the layouts
  • floating (Optional, boolean): do not scroll the widget when the parent scrolls and ignore layout
  • overflow_visible (Optional, boolean): do not clip the children's content to the parent's boundary
  • layout_1, layout_2 (Optional, boolean): custom flags, free to use by layouts
  • widget_1, widget_2 (Optional, boolean): custom flags, free to use by widget
  • user_1, user_2, user_3, user_4 (Optional, boolean): custom flags, free to use by user
clydebarrow commented 8 months ago

This is already possible by using lvgl functions, e.g.

            !lambda return lv_obj_get_state(id(pendant_lights)) & LV_STATE_CHECKED;

Some nicer syntax might be possible in the future.