diff --git a/esphome/__main__.py b/esphome/__main__.py index 3209e59a1f..55eaf59428 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -1173,7 +1173,9 @@ def parse_args(argv): "configuration", help="Your YAML configuration file(s).", nargs="+" ) - parser_clean_all = subparsers.add_parser("clean-all", help="Clean all files.") + parser_clean_all = subparsers.add_parser( + "clean-all", help="Clean all build and platform files." + ) parser_clean_all.add_argument( "configuration", help="Your YAML configuration directory.", nargs="*" ) diff --git a/esphome/components/cover/cover.cpp b/esphome/components/cover/cover.cpp index 700bceec01..3378279371 100644 --- a/esphome/components/cover/cover.cpp +++ b/esphome/components/cover/cover.cpp @@ -1,5 +1,6 @@ #include "cover.h" #include "esphome/core/log.h" +#include namespace esphome { namespace cover { diff --git a/esphome/components/valve/valve.cpp b/esphome/components/valve/valve.cpp index 0ee710fc02..b041fe8449 100644 --- a/esphome/components/valve/valve.cpp +++ b/esphome/components/valve/valve.cpp @@ -1,5 +1,6 @@ #include "valve.h" #include "esphome/core/log.h" +#include namespace esphome { namespace valve { diff --git a/esphome/components/voice_assistant/voice_assistant.cpp b/esphome/components/voice_assistant/voice_assistant.cpp index 743c90e700..a0cf1a155b 100644 --- a/esphome/components/voice_assistant/voice_assistant.cpp +++ b/esphome/components/voice_assistant/voice_assistant.cpp @@ -242,7 +242,6 @@ void VoiceAssistant::loop() { msg.flags = flags; msg.audio_settings = audio_settings; msg.set_wake_word_phrase(StringRef(this->wake_word_)); - this->wake_word_ = ""; // Reset media player state tracking #ifdef USE_MEDIA_PLAYER diff --git a/esphome/writer.py b/esphome/writer.py index 403cd8165d..b5cfd9b667 100644 --- a/esphome/writer.py +++ b/esphome/writer.py @@ -340,10 +340,15 @@ def clean_all(configuration: list[str]): # Clean entire build dir for dir in configuration: - buid_dir = Path(dir) / ".esphome" - if buid_dir.is_dir(): - _LOGGER.info("Deleting %s", buid_dir) - shutil.rmtree(buid_dir) + build_dir = Path(dir) / ".esphome" + if build_dir.is_dir(): + _LOGGER.info("Cleaning %s", build_dir) + # Don't remove storage as it will cause the dashboard to regenerate all configs + for item in build_dir.iterdir(): + if item.is_file(): + item.unlink() + elif item.name != "storage" and item.is_dir(): + shutil.rmtree(item) # Clean PlatformIO project files try: diff --git a/requirements.txt b/requirements.txt index 42db2cc56f..0b6820e7b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile esptool==5.1.0 click==8.1.7 esphome-dashboard==20250904.0 -aioesphomeapi==41.10.0 +aioesphomeapi==41.11.0 zeroconf==0.147.2 puremagic==1.30 ruamel.yaml==0.18.15 # dashboard_import diff --git a/tests/components/analog_threshold/test.nrf52-adafruit.yaml b/tests/components/analog_threshold/test.nrf52-adafruit.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/analog_threshold/test.nrf52-adafruit.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/analog_threshold/test.nrf52-mcumgr.yaml b/tests/components/analog_threshold/test.nrf52-mcumgr.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/analog_threshold/test.nrf52-mcumgr.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/bang_bang/test.nrf52-adafruit.yaml b/tests/components/bang_bang/test.nrf52-adafruit.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/bang_bang/test.nrf52-adafruit.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/bang_bang/test.nrf52-mcumgr.yaml b/tests/components/bang_bang/test.nrf52-mcumgr.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/bang_bang/test.nrf52-mcumgr.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/restart/test.nrf52-adafruit.yaml b/tests/components/restart/test.nrf52-adafruit.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/restart/test.nrf52-adafruit.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/restart/test.nrf52-mcumgr.yaml b/tests/components/restart/test.nrf52-mcumgr.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/restart/test.nrf52-mcumgr.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/script/test.nrf52-adafruit.yaml b/tests/components/script/test.nrf52-adafruit.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/script/test.nrf52-adafruit.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/script/test.nrf52-mcumgr.yaml b/tests/components/script/test.nrf52-mcumgr.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/script/test.nrf52-mcumgr.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/sprinkler/test.nrf52-adafruit.yaml b/tests/components/sprinkler/test.nrf52-adafruit.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/sprinkler/test.nrf52-adafruit.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/sprinkler/test.nrf52-mcumgr.yaml b/tests/components/sprinkler/test.nrf52-mcumgr.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/sprinkler/test.nrf52-mcumgr.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/template/common.yaml b/tests/components/template/common.yaml index ae7dc98e57..efbb83ee06 100644 --- a/tests/components/template/common.yaml +++ b/tests/components/template/common.yaml @@ -341,6 +341,7 @@ datetime: time: - platform: sntp # Required for datetime + id: sntp_time wifi: # Required for sntp time ap: diff --git a/tests/components/template/test.nrf52-adafruit.yaml b/tests/components/template/test.nrf52-adafruit.yaml new file mode 100644 index 0000000000..6a8c01560a --- /dev/null +++ b/tests/components/template/test.nrf52-adafruit.yaml @@ -0,0 +1,6 @@ +packages: !include common.yaml + +time: + - id: !remove sntp_time + +wifi: !remove diff --git a/tests/components/template/test.nrf52-mcumgr.yaml b/tests/components/template/test.nrf52-mcumgr.yaml new file mode 100644 index 0000000000..6a8c01560a --- /dev/null +++ b/tests/components/template/test.nrf52-mcumgr.yaml @@ -0,0 +1,6 @@ +packages: !include common.yaml + +time: + - id: !remove sntp_time + +wifi: !remove diff --git a/tests/components/thermostat/test.nrf52-adafruit.yaml b/tests/components/thermostat/test.nrf52-adafruit.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/thermostat/test.nrf52-adafruit.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/thermostat/test.nrf52-mcumgr.yaml b/tests/components/thermostat/test.nrf52-mcumgr.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/thermostat/test.nrf52-mcumgr.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/unit_tests/test_writer.py b/tests/unit_tests/test_writer.py index 821d8500db..bcb069db83 100644 --- a/tests/unit_tests/test_writer.py +++ b/tests/unit_tests/test_writer.py @@ -791,16 +791,21 @@ def test_clean_all( with caplog.at_level("INFO"): clean_all([str(config1_dir), str(config2_dir)]) - # Verify deletions - assert not build_dir1.exists() - assert not build_dir2.exists() + # Verify deletions - .esphome directories remain but contents are cleaned + # The .esphome directory itself is not removed because it may contain storage + assert build_dir1.exists() + assert build_dir2.exists() + + # Verify that files in .esphome were removed + assert not (build_dir1 / "dummy.txt").exists() + assert not (build_dir2 / "dummy.txt").exists() assert not pio_cache.exists() assert not pio_packages.exists() assert not pio_platforms.exists() assert not pio_core.exists() # Verify logging mentions each - assert "Deleting" in caplog.text + assert "Cleaning" in caplog.text assert str(build_dir1) in caplog.text assert str(build_dir2) in caplog.text assert "PlatformIO cache" in caplog.text @@ -809,6 +814,55 @@ def test_clean_all( assert "PlatformIO core" in caplog.text +@patch("esphome.writer.CORE") +def test_clean_all_preserves_storage( + mock_core: MagicMock, + tmp_path: Path, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test clean_all preserves storage directory.""" + # Create build directory with storage subdirectory + config_dir = tmp_path / "config" + config_dir.mkdir() + + build_dir = config_dir / ".esphome" + build_dir.mkdir() + (build_dir / "dummy.txt").write_text("x") + (build_dir / "other_file.txt").write_text("y") + + # Create storage directory with content + storage_dir = build_dir / "storage" + storage_dir.mkdir() + (storage_dir / "storage.json").write_text('{"test": "data"}') + (storage_dir / "other_storage.txt").write_text("storage content") + + # Call clean_all + from esphome.writer import clean_all + + with caplog.at_level("INFO"): + clean_all([str(config_dir)]) + + # Verify .esphome directory still exists + assert build_dir.exists() + + # Verify storage directory still exists with its contents + assert storage_dir.exists() + assert (storage_dir / "storage.json").exists() + assert (storage_dir / "other_storage.txt").exists() + + # Verify storage contents are intact + assert (storage_dir / "storage.json").read_text() == '{"test": "data"}' + assert (storage_dir / "other_storage.txt").read_text() == "storage content" + + # Verify other files were removed + assert not (build_dir / "dummy.txt").exists() + assert not (build_dir / "other_file.txt").exists() + + # Verify logging mentions deletion + assert "Cleaning" in caplog.text + assert str(build_dir) in caplog.text + + @patch("esphome.writer.CORE") def test_clean_all_platformio_not_available( mock_core: MagicMock, @@ -834,8 +888,8 @@ def test_clean_all_platformio_not_available( ): clean_all([str(config_dir)]) - # Build dir removed, PlatformIO dirs remain - assert not build_dir.exists() + # Build dir contents cleaned, PlatformIO dirs remain + assert build_dir.exists() assert pio_cache.exists() # No PlatformIO-specific logs @@ -867,4 +921,68 @@ def test_clean_all_partial_exists( clean_all([str(config_dir)]) - assert not build_dir.exists() + assert build_dir.exists() + + +@patch("esphome.writer.CORE") +def test_clean_all_removes_non_storage_directories( + mock_core: MagicMock, + tmp_path: Path, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test clean_all removes directories other than storage.""" + # Create build directory with various subdirectories + config_dir = tmp_path / "config" + config_dir.mkdir() + + build_dir = config_dir / ".esphome" + build_dir.mkdir() + + # Create files + (build_dir / "file1.txt").write_text("content1") + (build_dir / "file2.txt").write_text("content2") + + # Create storage directory (should be preserved) + storage_dir = build_dir / "storage" + storage_dir.mkdir() + (storage_dir / "storage.json").write_text('{"test": "data"}') + + # Create other directories (should be removed) + cache_dir = build_dir / "cache" + cache_dir.mkdir() + (cache_dir / "cache_file.txt").write_text("cache content") + + logs_dir = build_dir / "logs" + logs_dir.mkdir() + (logs_dir / "log1.txt").write_text("log content") + + temp_dir = build_dir / "temp" + temp_dir.mkdir() + (temp_dir / "temp_file.txt").write_text("temp content") + + # Call clean_all + from esphome.writer import clean_all + + with caplog.at_level("INFO"): + clean_all([str(config_dir)]) + + # Verify .esphome directory still exists + assert build_dir.exists() + + # Verify storage directory and its contents are preserved + assert storage_dir.exists() + assert (storage_dir / "storage.json").exists() + assert (storage_dir / "storage.json").read_text() == '{"test": "data"}' + + # Verify files were removed + assert not (build_dir / "file1.txt").exists() + assert not (build_dir / "file2.txt").exists() + + # Verify non-storage directories were removed + assert not cache_dir.exists() + assert not logs_dir.exists() + assert not temp_dir.exists() + + # Verify logging mentions cleaning + assert "Cleaning" in caplog.text + assert str(build_dir) in caplog.text