Skip to content

Commit 2c49611

Browse files
authored
Merge pull request #135 from edwardtfn/code-update
Move HA event handling to component
2 parents cd39fee + 2ec6053 commit 2c49611

26 files changed

+578
-539
lines changed

.test/esphome_ard_hw_relays.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
packages:
33
common_arduino: !include common_ard.yaml
44
core_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml
5-
standard_hw_relays_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_standard_hw_relays.yaml
5+
hw_relays_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_hw_relays.yaml
66
...

.test/esphome_ard_hw_speaker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
packages:
33
common_arduino: !include common_ard.yaml
44
core_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml
5-
standard_hw_speaker_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_standard_hw_speaker.yaml
5+
hw_speaker_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_hw_speaker.yaml
66
...

.test/esphome_ard_hw_vibration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
packages:
33
common_arduino: !include common_ard.yaml
44
core_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml
5-
standard_hw_vibration_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_standard_hw_vibration.yaml
5+
hw_vibration_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_hw_vibration.yaml
66
...

.test/esphome_idf_hw_relays.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
packages:
33
common_idf: !include common_idf.yaml
44
core_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml
5-
standard_hw_relays_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_standard_hw_relays.yaml
5+
hw_relays_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_hw_relays.yaml
66
...

.test/esphome_idf_hw_speaker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
packages:
33
common_idf: !include common_idf.yaml
44
core_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml
5-
standard_hw_speaker_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_standard_hw_speaker.yaml
5+
hw_speaker_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_hw_speaker.yaml
66
...

.test/esphome_idf_hw_vibration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
packages:
33
common_idf: !include common_idf.yaml
44
core_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml
5-
standard_hw_vibration_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_standard_hw_vibration.yaml
5+
hw_vibration_package: !include ../ESPHome/TX-Ultimate-Easy-ESPHome_hw_vibration.yaml
66
...

ESPHome/TX-Ultimate-Easy-ESPHome_core_common.yaml renamed to ESPHome/TX-Ultimate-Easy-ESPHome_common.yaml

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
##### TX Ultimate Easy for ESPHome #####
33
##### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy #####
44
####################################################################################################
5-
##### Purpose: ESPHome Core - Common #####
5+
##### Purpose: ESPHome - Common #####
66
####################################################################################################
77
##### Author: edwardtfn - https://github.com/edwardtfn - https://buymeacoffee.com/edwardfirmo #####
88
####################################################################################################
@@ -29,14 +29,14 @@ substitutions:
2929

3030
DUMP_CONFIG_CALLER_DELAY: 5s # Delay to dump config after requested
3131

32-
TAG_CORE_COMMON: core.common
32+
TAG_COMMON: tx_ultimate_easy.common
3333

3434
api:
3535
id: api_server
36+
homeassistant_services: true
3637
on_client_connected:
3738
then:
3839
- script.execute: dump_config_caller
39-
- script.execute: publish_device_info
4040

4141
binary_sensor:
4242
- id: bs_pending_restart
@@ -73,18 +73,23 @@ esp32:
7373
flash_size: 8MB
7474
framework:
7575
type: esp-idf
76+
advanced:
77+
loop_task_stack_size: 16384
78+
sdkconfig_options:
79+
CONFIG_ESP32_REV_MIN_3: y
7680

7781
esphome:
7882
name: ${name}
7983
friendly_name: ${friendly_name}
8084
comment: TX Ultimate Easy
81-
min_version: 2025.8.0
85+
min_version: 2025.11.0
8286
project:
8387
name: "edwardtfn.tx_ultimate_easy"
8488
version: ${version}
8589
platformio_options:
8690
build_flags:
87-
- -D TX_ULTIMATE_EASY_CORE_COMMON
91+
- -D TX_ULTIMATE_EASY_COMMON
92+
- -D TX_ULTIMATE_EASY_FIRMWARE_VERSION="${version}"
8893

8994
on_boot:
9095
- priority: 1000 # Very early in boot process
@@ -145,13 +150,7 @@ script:
145150
then:
146151
- lambda: |-
147152
// Send event to Home Assistant
148-
esphome::api::CustomAPIDevice ha_event;
149-
ha_event.fire_homeassistant_event("${EVENT_NAME}", {
150-
{"device_name", id(tx_device_name).state.c_str()},
151-
{"firmware", "${version}"},
152-
{"domain", "boot"},
153-
{"type", type.c_str()}
154-
});
153+
esphome::tx_ultimate_easy::fire_ha_event("boot", type.c_str(), {});
155154
156155
- id: boot_done
157156
mode: restart
@@ -174,6 +173,7 @@ script:
174173
# - HW Buttons
175174
# - HW Relays
176175
# - HW Touch
176+
- script.execute: update_device_name
177177
- script.execute:
178178
id: api_send_ha_event_boot
179179
type: start
@@ -182,16 +182,15 @@ script:
182182
- lambda: return sl_tx_model_format->active_index().has_value();
183183
- lambda: return sl_tx_model_gang->active_index().has_value();
184184
- lambda: |-
185-
id(is_us_model) = (sl_tx_model_format->state == "${TX_MODEL_FORMAT_US_TEXT}");
185+
id(is_us_model) = strcmp(sl_tx_model_format->current_option(), "${TX_MODEL_FORMAT_US_TEXT}") == 0;
186186
id(gang_count) = sl_tx_model_gang->active_index().value() + 1;
187187
if (id(gang_count) < 1 || id(gang_count) > 4) {
188-
ESP_LOGE("${TAG_CORE_COMMON}", "Invalid number of gangs: %" PRIu8, id(gang_count));
188+
ESP_LOGE("${TAG_COMMON}", "Invalid number of gangs: %" PRIu8, id(gang_count));
189189
}
190190
191191
- id: boot_sequence
192192
mode: restart
193193
then:
194-
- script.execute: publish_device_info
195194
- binary_sensor.template.publish:
196195
id: bs_pending_restart
197196
state: false
@@ -202,43 +201,43 @@ script:
202201
# Extended by all modules
203202
- lambda: |-
204203
// Device identification
205-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Device friendly name: ${friendly_name}");
206-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Device name: ${name}");
207-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Device name (HA): %s", tx_device_name->state.c_str());
208-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Device hostname: %s", App.get_name().c_str());
204+
ESP_LOGCONFIG("${TAG_COMMON}", "Device friendly name: ${friendly_name}");
205+
ESP_LOGCONFIG("${TAG_COMMON}", "Device name: ${name}");
206+
ESP_LOGCONFIG("${TAG_COMMON}", "Device name (HA): %s", esphome::tx_ultimate_easy::cached_device_name.c_str());
207+
ESP_LOGCONFIG("${TAG_COMMON}", "Device hostname: %s", App.get_name().c_str());
209208
210209
dump_config_versions->execute();
211210
212211
// Framework detection
213212
#ifdef USE_ARDUINO
214-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Framework: Arduino");
213+
ESP_LOGCONFIG("${TAG_COMMON}", "Framework: Arduino");
215214
#elif defined(USE_ESP_IDF)
216-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Framework: ESP-IDF");
215+
ESP_LOGCONFIG("${TAG_COMMON}", "Framework: ESP-IDF");
217216
#else
218-
ESP_LOGW("${TAG_CORE_COMMON}", "Framework: UNKNOWN");
217+
ESP_LOGW("${TAG_COMMON}", "Framework: UNKNOWN");
219218
#endif
220219
221220
// Model configuration
222-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Model format (selected): %s",
223-
sl_tx_model_format->state.c_str());
224-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Model format (detected): %s",
221+
ESP_LOGCONFIG("${TAG_COMMON}", "Model format (selected): %s",
222+
sl_tx_model_format->current_option());
223+
ESP_LOGCONFIG("${TAG_COMMON}", "Model format (detected): %s",
225224
id(is_us_model) ? "US" : "EU");
226-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Gangs (selected): %s",
227-
sl_tx_model_gang->state.c_str());
228-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Gangs (detected): %" PRIu8 "-Gang%s",
225+
ESP_LOGCONFIG("${TAG_COMMON}", "Gangs (selected): %s",
226+
sl_tx_model_gang->current_option());
227+
ESP_LOGCONFIG("${TAG_COMMON}", "Gangs (detected): %" PRIu8 "-Gang%s",
229228
id(gang_count), id(gang_count) > 1 ? "s" : "");
230229
231230
// Boot completion status
232231
if (bs_boot_completed->state)
233-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Boot completed: Yes");
232+
ESP_LOGCONFIG("${TAG_COMMON}", "Boot completed: Yes");
234233
else
235-
ESP_LOGW("${TAG_CORE_COMMON}", "Boot completed: NO");
234+
ESP_LOGW("${TAG_COMMON}", "Boot completed: NO");
236235
237236
// System state
238237
if (bs_pending_restart->state)
239-
ESP_LOGW("${TAG_CORE_COMMON}", "Pending restart: YES");
238+
ESP_LOGW("${TAG_COMMON}", "Pending restart: YES");
240239
else
241-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "Pending restart: No");
240+
ESP_LOGCONFIG("${TAG_COMMON}", "Pending restart: No");
242241
243242
- id: dump_config_caller
244243
mode: restart
@@ -263,17 +262,10 @@ script:
263262
then:
264263
- lambda: |-
265264
// Version information
266-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "TX Ultimate firmware version: ${version}");
265+
ESP_LOGCONFIG("${TAG_COMMON}", "TX Ultimate firmware version: ${version}");
267266
// ESPHome builder information
268-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "ESPHome builder: " ESPHOME_VERSION);
269-
ESP_LOGCONFIG("${TAG_CORE_COMMON}", "ESPHome build timestamp: %s", App.get_compilation_time().c_str());
270-
271-
- id: publish_device_info
272-
mode: restart
273-
then:
274-
- lambda: |-
275-
tx_fw_version->publish_state("${version}");
276-
tx_device_name->publish_state(App.get_name().c_str());
267+
ESP_LOGCONFIG("${TAG_COMMON}", "ESPHome builder: " ESPHOME_VERSION);
268+
ESP_LOGCONFIG("${TAG_COMMON}", "ESPHome build timestamp: %s", App.get_compilation_time().c_str());
277269
278270
- id: restore_from_nvs
279271
mode: single
@@ -287,6 +279,16 @@ script:
287279
if (id(gang_count) < 1 || id(gang_count) > 4) return 0; // default to 1-Gang
288280
return static_cast<uint8_t>(id(gang_count)) - 1;
289281
282+
- id: update_device_name
283+
mode: single
284+
then:
285+
- lambda: |-
286+
if (esphome::tx_ultimate_easy::cached_device_name.empty()) {
287+
esphome::tx_ultimate_easy::initialize_cached_device_name(App.get_name());
288+
ESP_LOGI("${TAG_COMMON}", "Device name: %s", esphome::tx_ultimate_easy::cached_device_name.c_str());
289+
tx_device_name->publish_state(esphome::tx_ultimate_easy::cached_device_name);
290+
}
291+
290292
select:
291293
- id: sl_tx_model_format
292294
name: Model (Format)
@@ -303,10 +305,8 @@ select:
303305
icon: mdi:tablet-cellphone
304306
on_value:
305307
then:
306-
- binary_sensor.template.publish:
307-
id: bs_pending_restart
308-
state: true
309308
- lambda: |-
309+
bs_pending_restart->publish_state(true);
310310
id(is_us_model) = (x == "${TX_MODEL_FORMAT_US_TEXT}");
311311
312312
- id: sl_tx_model_gang
@@ -326,10 +326,8 @@ select:
326326
icon: mdi:dip-switch
327327
on_value:
328328
then:
329-
- binary_sensor.template.publish:
330-
id: bs_pending_restart
331-
state: true
332329
- lambda: |-
330+
bs_pending_restart->publish_state(true);
333331
id(gang_count) = static_cast<uint8_t>(i) + 1;
334332
tx_ultimate->set_gang_count(id(gang_count));
335333
@@ -353,26 +351,18 @@ text_sensor:
353351
disabled_by_default: false
354352
update_interval: never
355353
lambda: |-
356-
return {"${name}"};
357-
filters:
358-
- lambda: |-
359-
const std::string raw_name = x;
360-
std::string result;
361-
bool last_was_underscore = false;
362-
for (const char& c : raw_name) {
363-
if (isalnum(c)) {
364-
result += tolower(c); // Add alphanumeric characters as lowercase
365-
last_was_underscore = false;
366-
} else if (!last_was_underscore) { // Replace non-alphanumeric with '_' but avoid consecutive '_'
367-
result += '_';
368-
last_was_underscore = true;
369-
}
370-
}
371-
return result;
354+
return { esphome::tx_ultimate_easy::cached_device_name };
372355
373356
tx_ultimate_easy:
374357
id: tx_ultimate
375358

376359
wifi:
377360
id: wifi_component
361+
use_psram: true
362+
363+
on_connect:
364+
then:
365+
- lambda: |-
366+
tx_fw_version->publish_state("${version}");
367+
update_device_name->execute();
378368
...

ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
---
1414
packages:
1515
# yamllint disable rule:colons
16-
core_common: !include TX-Ultimate-Easy-ESPHome_core_common.yaml
17-
core_hw_buttons: !include TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml
18-
core_hw_leds: !include TX-Ultimate-Easy-ESPHome_core_hw_leds.yaml
19-
core_hw_touch: !include TX-Ultimate-Easy-ESPHome_core_hw_touch.yaml
16+
common: !include TX-Ultimate-Easy-ESPHome_common.yaml
17+
hw_buttons: !include TX-Ultimate-Easy-ESPHome_hw_buttons.yaml
18+
hw_leds: !include TX-Ultimate-Easy-ESPHome_hw_leds.yaml
19+
hw_touch: !include TX-Ultimate-Easy-ESPHome_hw_touch.yaml
2020
# yamllint enable rule:colons
2121
...

ESPHome/TX-Ultimate-Easy-ESPHome_standard_hw_audio.yaml renamed to ESPHome/TX-Ultimate-Easy-ESPHome_hw_audio.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
##### TX Ultimate Easy for ESPHome #####
33
##### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy #####
44
####################################################################################################
5-
##### Purpose: ESPHome - Standard - I2S Audio #####
5+
##### Purpose: ESPHome - Hardward - I2S Audio #####
66
####################################################################################################
77
##### Author: edwardtfn - https://github.com/edwardtfn - https://buymeacoffee.com/edwardfirmo #####
88
####################################################################################################
@@ -14,12 +14,12 @@
1414
substitutions:
1515
SWITCH_AUDIO_AMPLIFIER_RESTORE_MODE: RESTORE_DEFAULT_ON
1616

17-
TAG_STD_HW_AUDIO: std.hw.audio
17+
TAG_HW_AUDIO: tx_ultimate_easy.hw.audio
1818

1919
esphome:
2020
platformio_options:
2121
build_flags:
22-
- -D TX_ULTIMATE_EASY_STANDARD_HW_AUDIO
22+
- -D TX_ULTIMATE_EASY_HW_AUDIO
2323

2424
i2s_audio:
2525
- id: if_i2s_audio
@@ -32,12 +32,12 @@ script:
3232
- script.wait: dump_config
3333
- lambda: |-
3434
// Check for requirements
35-
#if !defined(TX_ULTIMATE_EASY_CORE_COMMON)
36-
#error "The package TX-Ultimate-Easy-ESPHome_core_common.yaml is required."
35+
#if !defined(TX_ULTIMATE_EASY_COMMON)
36+
#error "The package TX-Ultimate-Easy-ESPHome_common.yaml is required."
3737
#endif
3838
3939
// Identify itself
40-
ESP_LOGCONFIG(ESPHOME_PROJECT_NAME, " - Standard - Hardware - Audio");
40+
ESP_LOGCONFIG(ESPHOME_PROJECT_NAME, " - Hardware - Audio");
4141
4242
switch:
4343
- id: sw_audio_amplifier

0 commit comments

Comments
 (0)