From d7699c93d6803ba03e61ffd0e9ab6c56578a7032 Mon Sep 17 00:00:00 2001 From: Johan Bloemberg Date: Fri, 8 Jun 2018 11:34:06 +0200 Subject: [PATCH] Fix deprecation of board_flash_mode parameter (#41) * Fix deprecation of board_flash_mode parameter Fixes `Warning! `board_flash_mode` option is deprecated and will be removed in the next release! Please use `board_build.flash_mode` instead.` * Don't break flashing for older installations. --- esphomeyaml/writer.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/esphomeyaml/writer.py b/esphomeyaml/writer.py index 30ad1e1118..a3fd0bb5c9 100644 --- a/esphomeyaml/writer.py +++ b/esphomeyaml/writer.py @@ -82,6 +82,7 @@ def get_build_flags(config, key): def get_ini_content(config): + version_specific_settings = determine_platformio_version_settings() platform = config[CONF_ESPHOMEYAML][CONF_PLATFORM] if platform in PLATFORM_TO_PLATFORMIO: platform = PLATFORM_TO_PLATFORMIO[platform] @@ -119,8 +120,9 @@ def get_ini_content(config): content = INI_CONTENT_FORMAT.format(**options) if CONF_BOARD_FLASH_MODE in config[CONF_ESPHOMEYAML]: + flash_mode_key = version_specific_settings['flash_mode_key'] flash_mode = config[CONF_ESPHOMEYAML][CONF_BOARD_FLASH_MODE] - content += "board_flash_mode = {}\n".format(flash_mode) + content += "{} = {}\n".format(flash_mode_key, flash_mode) return content @@ -194,3 +196,16 @@ def write_cpp(code_s, path): return with codecs.open(path, 'w+', encoding='utf-8') as f_handle: f_handle.write(full_file) + + +def determine_platformio_version_settings(): + import platformio + + settings = {} + + if platformio.VERSION < (3, 5, 3): + settings['flash_mode_key'] = 'board_flash_mode' + else: + settings['flash_mode_key'] = 'board_build.flash_mode' + + return settings