From 3a99a817aa4b1512b689591204bd6861280eedaa Mon Sep 17 00:00:00 2001 From: Florian Hess Date: Tue, 24 Sep 2024 10:17:52 +0200 Subject: [PATCH] Update Number State based on current settings --- firmware/addons/memory-utils.yaml | 108 +++++++++++++++++++++--------- firmware/base.yaml | 1 + 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/firmware/addons/memory-utils.yaml b/firmware/addons/memory-utils.yaml index d0c35a0..4f14c61 100644 --- a/firmware/addons/memory-utils.yaml +++ b/firmware/addons/memory-utils.yaml @@ -11,6 +11,13 @@ tc_bus: on_read_memory_timeout: - logger.log: "Failed to read Memory" +# Read Memory before reading and writing +button: + - platform: template + name: "Read Memory" + on_press: + - tc_bus.read_memory: + number: - platform: template name: "Ringtone volume" @@ -18,6 +25,8 @@ number: min_value: 0 max_value: 7 step: 1 + lambda: !lambda "return id(tc_bus_intercom)->get_settings().ringtone_volume;" + update_interval: 10s set_action: - tc_bus.update_setting: type: volume_ringtone @@ -29,49 +38,82 @@ number: min_value: 0 max_value: 7 step: 1 + lambda: !lambda "return id(tc_bus_intercom)->get_settings().handset_volume;" + update_interval: 10s set_action: - tc_bus.update_setting: type: volume_handset value: !lambda "return x;" -select: + - platform: template + name: "Ringtone: Floor Call" + optimistic: true + min_value: 0 + max_value: 12 + step: 1 + lambda: !lambda "return id(tc_bus_intercom)->get_settings().floor_call_ringtone;" + update_interval: 10s + set_action: + - tc_bus.update_setting: + type: ringtone_floor_call + value: !lambda "return x;" + - platform: template name: "Ringtone: Door Call" optimistic: true - options: - - "Ringtone 1" - - "Ringtone 2" - - "Ringtone 3" - - "Ringtone 4" - - "Ringtone 5" - - "Ringtone 6" - - "Ringtone 7" - - "Ringtone 8" - - "Ringtone 9" - - "Ringtone 10" - - "Ringtone 11" - - "Ringtone 12" - initial_option: "Ringtone 1" + min_value: 0 + max_value: 12 + step: 1 + lambda: !lambda "return id(tc_bus_intercom)->get_settings().door_call_ringtone;" + update_interval: 10s set_action: - tc_bus.update_setting: type: ringtone_door_call - value: !lambda |- - std::string str = x; - std::vector v; - char * token; - char seps[] = " "; - token = strtok (&str[1],seps); - while (token != NULL) - { - v.push_back(token); - token = strtok (NULL, seps); - } - - return std::stoi(v[1].c_str()); - + value: !lambda "return x;" -button: - platform: template - name: "Read Memory" - on_press: - - tc_bus.read_memory: \ No newline at end of file + name: "Ringtone: Internal Call" + optimistic: true + min_value: 0 + max_value: 12 + step: 1 + lambda: !lambda "return id(tc_bus_intercom)->get_settings().internal_call_ringtone;" + update_interval: 10s + set_action: + - tc_bus.update_setting: + type: ringtone_internal_call + value: !lambda "return x;" + +#select: +# - platform: template +# name: "Ringtone: Door Call" +# optimistic: true +# options: +# - "Ringtone 1" +# - "Ringtone 2" +# - "Ringtone 3" +# - "Ringtone 4" +# - "Ringtone 5" +# - "Ringtone 6" +# - "Ringtone 7" +# - "Ringtone 8" +# - "Ringtone 9" +# - "Ringtone 10" +# - "Ringtone 11" +# - "Ringtone 12" +# initial_option: "Ringtone 1" +# set_action: +# - tc_bus.update_setting: +# type: ringtone_door_call +# value: !lambda |- +# std::string str = x; +# std::vector v; +# char * token; +# char seps[] = " "; +# token = strtok (&str[1],seps); +# while (token != NULL) +# { +# v.push_back(token); +# token = strtok (NULL, seps); +# } +# return std::stoi(v[1].c_str()); \ No newline at end of file diff --git a/firmware/base.yaml b/firmware/base.yaml index c3f1655..577d595 100644 --- a/firmware/base.yaml +++ b/firmware/base.yaml @@ -118,6 +118,7 @@ external_components: # Setup TC:BUS Component tc_bus: + id: tc_bus_intercom event: "doorman" hardware_version: name: "Hardware"