Initial nvs optimization for relay lights
This commit is contained in:
@@ -29,6 +29,8 @@ substitutions:
|
||||
LIGHT_SIDES_RESTORE_MODE: RESTORE_DEFAULT_OFF
|
||||
LIGHT_INDIVIDUAL_RESTORE_MODE: RESTORE_DEFAULT_OFF
|
||||
|
||||
LIGHT_ATTRS_DEFAULT: '0x64FFFFFF' # brightness=100, RGB=255,255,255
|
||||
|
||||
TAG_CORE_HW_LEDS: core.hw.leds
|
||||
|
||||
esphome:
|
||||
@@ -36,14 +38,6 @@ esphome:
|
||||
build_flags:
|
||||
- -D TX_ULTIMATE_EASY_CORE_HW_LEDS
|
||||
|
||||
globals:
|
||||
- id: gb_lights_1
|
||||
type: std::vector<light::LightState*>
|
||||
restore_value: false
|
||||
- id: gb_lights_2
|
||||
type: std::vector<light::LightState*>
|
||||
restore_value: false
|
||||
|
||||
light:
|
||||
# These lights are controlling the LEDs on the device
|
||||
- id: light_full
|
||||
@@ -550,6 +544,40 @@ script:
|
||||
// Identify itself
|
||||
ESP_LOGCONFIG(ESPHOME_PROJECT_NAME, " - Core - Hardware - LEDs");
|
||||
|
||||
- id: light_attributes_restore
|
||||
mode: parallel
|
||||
parameters:
|
||||
light_ptr: light::LightState*
|
||||
attr_global_ptr: uint32_t*
|
||||
then:
|
||||
- lambda: |-
|
||||
tx_ultimate_easy::LightAttributes attrs = tx_ultimate_easy::unpack_light_attributes(*attr_global_ptr);
|
||||
auto call = light_ptr->make_call();
|
||||
call.set_brightness(attrs.brightness / 100.0f);
|
||||
call.set_rgb(attrs.red / 255.0f, attrs.green / 255.0f, attrs.blue / 255.0f);
|
||||
call.perform();
|
||||
ESP_LOGI("${TAG_CORE_HW_LEDS}", "Restored light attributes: brightness=%d%%, RGB=(%d,%d,%d)",
|
||||
attrs.brightness, attrs.red, attrs.green, attrs.blue);
|
||||
|
||||
- id: light_attributes_save
|
||||
mode: parallel
|
||||
parameters:
|
||||
light_ptr: light::LightState*
|
||||
attr_global_ptr: uint32_t*
|
||||
then:
|
||||
- lambda: |-
|
||||
auto current = light_ptr->current_values;
|
||||
tx_ultimate_easy::LightAttributes attrs = {
|
||||
.brightness = uint8_t(current.get_brightness() * 100.0f),
|
||||
.red = uint8_t(current.get_red() * 255.0f),
|
||||
.green = uint8_t(current.get_green() * 255.0f),
|
||||
.blue = uint8_t(current.get_blue() * 255.0f)
|
||||
};
|
||||
|
||||
*attr_global_ptr = tx_ultimate_easy::pack_light_attributes(attrs);
|
||||
ESP_LOGD("${TAG_CORE_HW_LEDS}", "Saved light attributes: brightness=%d%%, RGB=(%d,%d,%d)",
|
||||
attrs.brightness, attrs.red, attrs.green, attrs.blue);
|
||||
|
||||
select:
|
||||
# EU relay light mode template
|
||||
- &relay_light_mode_eu
|
||||
|
||||
@@ -47,6 +47,13 @@ globals:
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
|
||||
- id: gb_lights_1
|
||||
type: std::vector<light::LightState*>
|
||||
restore_value: false
|
||||
- id: gb_lights_2
|
||||
type: std::vector<light::LightState*>
|
||||
restore_value: false
|
||||
|
||||
# Packed relay modes - replaces 4 separate selects
|
||||
- id: relay_modes_packed
|
||||
type: uint16_t
|
||||
@@ -62,10 +69,10 @@ globals:
|
||||
initial_value: '0' # All switches default to OFF
|
||||
# Bit layout: [unused(3)][sw_relay4][sw_relay3][sw_relay2][sw_relay1][sw_expose_leds]
|
||||
|
||||
# - id: attr_light_output_1
|
||||
# type: tx_ultimate_easy::LightAttributes
|
||||
# restore_value: true
|
||||
# initial_value:
|
||||
- id: attr_light_output_1
|
||||
type: uint32_t
|
||||
restore_value: true
|
||||
initial_value: '${LIGHT_ATTRS_DEFAULT}'
|
||||
|
||||
light:
|
||||
# These lights are used for the physical relays to be shown as lights
|
||||
@@ -89,6 +96,12 @@ light:
|
||||
- switch.is_on: sw_relay_1
|
||||
then:
|
||||
- switch.turn_off: sw_relay_1
|
||||
on_state:
|
||||
then:
|
||||
- script.execute:
|
||||
id: light_attributes_save
|
||||
light_ptr: !lambda return id(light_output_1);
|
||||
attr_global_ptr: !lambda return &id(attr_light_output_1);
|
||||
- id: light_output_2
|
||||
name: Light output 2
|
||||
output: output_relay_2
|
||||
@@ -770,6 +783,10 @@ script:
|
||||
#if !defined(TX_ULTIMATE_EASY_CORE)
|
||||
#error "The package TX-Ultimate-Easy-ESPHome_core.yaml is required."
|
||||
#endif
|
||||
#if !defined(TX_ULTIMATE_EASY_CORE_HW_LEDS)
|
||||
#error "The package TX-Ultimate-Easy-ESPHome_core_hw_leds.yaml is required."
|
||||
#endif // TX_ULTIMATE_EASY_CORE_HW_LEDS
|
||||
|
||||
|
||||
// Identify itself
|
||||
ESP_LOGCONFIG(ESPHOME_PROJECT_NAME, " - Standard - Hardware - Relays");
|
||||
|
||||
Reference in New Issue
Block a user