diff --git a/esphome/arduino8266/framework.py b/esphome/arduino8266/framework.py index 219d0f2fb9..e7b55e1b7c 100644 --- a/esphome/arduino8266/framework.py +++ b/esphome/arduino8266/framework.py @@ -61,16 +61,16 @@ MIN_FRAMEWORK_VERSION = Version(3, 1, 1) def framework_package_version(ver: Version) -> str: """Map an Arduino core version (e.g. 3.1.2) to its package version. - Same encoding as the PlatformIO package registry uses for core 3.x - releases (3.1.2 -> 3.30102.0). The native toolchain only supports core - 3.x: 1.x/2.x fall below MIN_FRAMEWORK_VERSION, and a future major bump - needs its own encoding and toolchain pin rather than a registry lookup - for a package that cannot exist. + Same encoding as the PlatformIO package registry uses for every core + above 2.6.2 (3.1.2 -> 3.30102.0, and 2.7.4 -> 3.20704.0: the leading 3 + is the package major, not the core major). A future core 4.x needs its + own encoding and toolchain pin rather than a registry lookup for a + package that cannot exist. """ - if ver.major != 3: + if ver.major > 3: raise EsphomeError( - f"The native toolchain does not support Arduino core {ver} " - "(only 3.x); use 'toolchain: platformio'" + f"Arduino core {ver} has no known package encoding; " + "use 'toolchain: platformio'" ) return f"3.{ver.major}{ver.minor:02d}{ver.patch:02d}.0" diff --git a/tests/unit_tests/test_arduino8266_framework.py b/tests/unit_tests/test_arduino8266_framework.py index 0d84d024ea..334f081bcb 100644 --- a/tests/unit_tests/test_arduino8266_framework.py +++ b/tests/unit_tests/test_arduino8266_framework.py @@ -22,8 +22,10 @@ def _clear_caches(tmp_path: Path) -> None: def test_framework_package_version() -> None: assert framework.framework_package_version(cv.Version(3, 1, 2)) == "3.30102.0" assert framework.framework_package_version(cv.Version(3, 2, 0)) == "3.30200.0" + # 2.6.3+ cores use the same package-major-3 encoding (PlatformIO path) + assert framework.framework_package_version(cv.Version(2, 7, 4)) == "3.20704.0" # A future major bump needs its own encoding, not a doomed registry lookup - with pytest.raises(EsphomeError, match="only 3.x"): + with pytest.raises(EsphomeError, match="no known package encoding"): framework.framework_package_version(cv.Version(4, 0, 0))