From a831d189d8f7e324de3ebadbe2f3986378715524 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Wed, 5 Apr 2023 08:58:11 +0200 Subject: [PATCH] Code optimization --- nspanel_blueprint.yaml | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index dd9f276..90b11f9 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -4058,20 +4058,8 @@ action: - variables: notification_unread_state: "{{ states(notification_unread) | default('unavailable') if notification_unread is string else 'unavailable' }}" notification_text_state: "{{ states(notification_text) | default(None) if notification_text is string else None }}" - set_button04_icon: >- - {%- if notification_unread_state == 'on' and notification_text_state | length > 0 -%} {{ page_home.buttons[3].icon}} - {%- elif notification_unread_state == 'off' and notification_text_state | length > 0 -%} {{ page_home.buttons[3].icon }} - {%- else -%} {{ nextion.icons.blank }} - {%- endif -%} - set_button04_icon_font: >- - {%- if notification_unread_state == 'on' and notification_text_state | length > 0 -%} - {% set rgb = page_home.buttons[3].color_rgb.on %} - {{ rgb if is_number(rgb) else ((rgb[0] //(2**3)) *(2**11))+((rgb[1] //(2**2)) *(2**5))+(rgb[2] //(2**3)) }} - {%- elif notification_unread_state == 'off' and notification_text_state | length > 0 -%} - {% set rgb = page_home.buttons[3].color_rgb.off %} - {{ rgb if is_number(rgb) else ((rgb[0] //(2**3)) *(2**11))+((rgb[1] //(2**2)) *(2**5))+(rgb[2] //(2**3)) }} - {%- else -%} {{ nextion.colors.grey_light }} - {%- endif -%} + set_button04_icon: "{{ page_home.buttons[3].icon if notification_unread_state in ['on', 'off'] and notification_text_state | length > 0 else nextion.icons.blank }}" + set_button04_icon_font: "{{ (page_home.buttons[3].color_rgb[notification_unread_state] if is_number(page_home.buttons[3].color_rgb[notification_unread_state]) else ((page_home.buttons[3].color_rgb[notification_unread_state][0] //(2**3)) *(2**11))+((page_home.buttons[3].color_rgb[notification_unread_state][1] //(2**2)) *(2**5))+(page_home.buttons[3].color_rgb[notification_unread_state][2] //(2**3))) if notification_unread_state in ['on', 'off'] and notification_text_state | length > 0 else nextion.colors.grey_light }}" ##### SET ICON Font - Notify ##### - *delay-default - service: "{{ nextion.commands.text_printf }}" @@ -4786,10 +4774,7 @@ action: # HVAC Button PIC - variables: - heating_bt_pic: >- - {%- if hvac_mode == 'off' -%} {{ nextion.pics.heating.button.off }} - {%- else -%} {{ nextion.pics.heating.button.on }} - {%- endif -%} + heating_bt_pic: "{{ nextion.pics.heating.button.off if hvac_mode == 'off' else nextion.pics.heating.button.on }}" - *delay-default - service: "{{ nextion.commands.printf }}" data: @@ -5848,10 +5833,7 @@ action: - *variables-weather - variables: heating_state: "{{ mui[language].climate.states.off if trigger.event.data.new_state.state == 'off' else mui[language].climate.states.on }}" - heating_bt_pic: >- - {%- if trigger.event.data.new_state.state == 'off' -%} {{ nextion.pics.heating.button.off }} - {%- else -%} {{ nextion.pics.heating.button.on }} - {%- endif -%} + heating_bt_pic: "{{ nextion.pics.heating.button.off if trigger.event.data.new_state.state == 'off' else nextion.pics.heating.button.on }}" - service: "{{ nextion.commands.text_printf }}" data: