From f3ee5b55e9c80da13adf92e632ca6229cb50f9e3 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Thu, 28 Feb 2019 10:11:05 +0100 Subject: [PATCH] Add warning if esphome-core dev used without esphome dev --- esphome/__main__.py | 12 +++++++++++- esphome/core.py | 12 +++++++++--- esphome/util.py | 6 ++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/esphome/__main__.py b/esphome/__main__.py index 21572fc115..63ad14fa7b 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -18,7 +18,8 @@ from esphome.cpp_generator import Expression, RawStatement, add, statement from esphome.helpers import color, indent from esphome.py_compat import IS_PY2, safe_input, text_type from esphome.storage_json import StorageJSON, storage_path -from esphome.util import run_external_command, run_external_process, safe_print +from esphome.util import run_external_command, run_external_process, safe_print, \ + is_dev_esphome_version _LOGGER = logging.getLogger(__name__) @@ -157,6 +158,15 @@ def write_cpp(config): def compile_program(args, config): _LOGGER.info("Compiling app...") rc = platformio_api.run_compile(config, args.verbose) + if rc != 0 and CORE.is_dev_esphome_core_version and not is_dev_esphome_version(): + _LOGGER.warning("You're using 'esphome_core_version: dev' but not using the " + "dev version of the ESPHome tool.") + _LOGGER.warning("Expect compile errors if these versions are out of sync.") + _LOGGER.warning("Please install the dev version of ESPHome too when using " + "'esphome_core_version: dev'.") + _LOGGER.warning(" - Hass.io: Install 'ESPHome (dev)' addon") + _LOGGER.warning(" - Docker: docker run [...] esphome/esphome:dev [...]") + _LOGGER.warning(" - PIP: pip install -U https://github.com/esphome/esphome/archive/dev.zip") return rc diff --git a/esphome/core.py b/esphome/core.py index 2d59e4eefc..57393c448f 100644 --- a/esphome/core.py +++ b/esphome/core.py @@ -10,8 +10,8 @@ import re from typing import Any, Dict, List # noqa from esphome.const import CONF_ARDUINO_VERSION, CONF_ESPHOME, CONF_ESPHOME_CORE_VERSION, \ - CONF_LOCAL, \ - CONF_USE_ADDRESS, CONF_WIFI, ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266 + CONF_LOCAL, CONF_USE_ADDRESS, CONF_WIFI, ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266, \ + CONF_REPOSITORY, CONF_BRANCH from esphome.helpers import ensure_unique_string from esphome.py_compat import IS_PY2, integer_types @@ -288,7 +288,7 @@ class ID(object): return hash(self.id) -# pylint: disable=too-many-instance-attributes +# pylint: disable=too-many-instance-attributes,too-many-public-methods class EsphomeCore(object): def __init__(self): # True if command is run from dashboard @@ -328,6 +328,12 @@ class EsphomeCore(object): def esphome_core_version(self): # type: () -> Dict[str, str] return self.config[CONF_ESPHOME][CONF_ESPHOME_CORE_VERSION] + @property + def is_dev_esphome_core_version(self): + if CONF_REPOSITORY not in self.esphome_core_version: + return False + return self.esphome_core_version.get(CONF_BRANCH) == 'dev' + @property def is_local_esphome_core_copy(self): return CONF_LOCAL in self.esphome_core_version diff --git a/esphome/util.py b/esphome/util.py index 3ded9ad721..3f01f0772a 100644 --- a/esphome/util.py +++ b/esphome/util.py @@ -6,6 +6,8 @@ import re import subprocess import sys +from esphome import const + _LOGGER = logging.getLogger(__name__) @@ -147,3 +149,7 @@ def run_external_process(*cmd, **kwargs): if capture_stdout: # pylint: disable=lost-exception return sub_stdout.getvalue() + + +def is_dev_esphome_version(): + return 'dev' in const.__version__