diff --git a/esphome/components/bang_bang/climate.py b/esphome/components/bang_bang/climate.py index 88828ef44f..4ef811c55d 100644 --- a/esphome/components/bang_bang/climate.py +++ b/esphome/components/bang_bang/climate.py @@ -7,7 +7,7 @@ from esphome.const import CONF_AWAY_CONFIG, CONF_COOL_ACTION, \ CONF_ID, CONF_IDLE_ACTION, CONF_SENSOR bang_bang_ns = cg.esphome_ns.namespace('bang_bang') -BangBangClimate = bang_bang_ns.class_('BangBangClimate', climate.Climate) +BangBangClimate = bang_bang_ns.class_('BangBangClimate', climate.Climate, cg.Component) BangBangClimateTargetTempConfig = bang_bang_ns.struct('BangBangClimateTargetTempConfig') CONFIG_SCHEMA = cv.All(climate.CLIMATE_SCHEMA.extend({ diff --git a/esphome/components/climate/climate_mode.cpp b/esphome/components/climate/climate_mode.cpp index 32d42b706f..07b97f4f33 100644 --- a/esphome/components/climate/climate_mode.cpp +++ b/esphome/components/climate/climate_mode.cpp @@ -6,13 +6,13 @@ namespace climate { const char *climate_mode_to_string(ClimateMode mode) { switch (mode) { case CLIMATE_MODE_OFF: - return "off"; + return "OFF"; case CLIMATE_MODE_AUTO: - return "auto"; + return "AUTO"; case CLIMATE_MODE_COOL: - return "cool"; + return "COOL"; case CLIMATE_MODE_HEAT: - return "heat"; + return "HEAT"; default: return "UNKNOWN"; } diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index ed14f3c824..217c0cbf0d 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.cpp +++ b/esphome/components/deep_sleep/deep_sleep_component.cpp @@ -19,7 +19,8 @@ void DeepSleepComponent::setup() { void DeepSleepComponent::dump_config() { ESP_LOGCONFIG(TAG, "Setting up Deep Sleep..."); if (this->sleep_duration_.has_value()) { - ESP_LOGCONFIG(TAG, " Sleep Duration: %llu ms", *this->sleep_duration_ / 1000); + uint32_t duration = *this->sleep_duration_ / 1000; + ESP_LOGCONFIG(TAG, " Sleep Duration: %u ms", duration); } if (this->run_duration_.has_value()) { ESP_LOGCONFIG(TAG, " Run Duration: %u ms", *this->run_duration_); diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index 50a0d99d32..ce7422d05b 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -67,7 +67,7 @@ CONFIG_SCHEMA = cv.All(cv.Schema({ cv.Optional(CONF_USE_ADDRESS): cv.string_strict, cv.Optional('hostname'): cv.invalid("The hostname option has been removed in 1.11.0"), -}), validate) +}).extend(cv.COMPONENT_SCHEMA), validate) def manual_ip(config): @@ -84,6 +84,7 @@ def manual_ip(config): @coroutine_with_priority(60.0) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) + yield cg.register_component(var, config) cg.add(var.set_phy_addr(config[CONF_PHY_ADDR])) cg.add(var.set_mdc_pin(config[CONF_MDC_PIN])) diff --git a/esphome/components/homeassistant/binary_sensor/__init__.py b/esphome/components/homeassistant/binary_sensor/__init__.py index b78836f18f..88e2f2fcb2 100644 --- a/esphome/components/homeassistant/binary_sensor/__init__.py +++ b/esphome/components/homeassistant/binary_sensor/__init__.py @@ -6,7 +6,8 @@ from .. import homeassistant_ns DEPENDENCIES = ['api'] HomeassistantBinarySensor = homeassistant_ns.class_('HomeassistantBinarySensor', - binary_sensor.BinarySensor) + binary_sensor.BinarySensor, + cg.Component) CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(HomeassistantBinarySensor), diff --git a/esphome/components/homeassistant/sensor/__init__.py b/esphome/components/homeassistant/sensor/__init__.py index cd5e4a74e2..577efca79b 100644 --- a/esphome/components/homeassistant/sensor/__init__.py +++ b/esphome/components/homeassistant/sensor/__init__.py @@ -6,7 +6,8 @@ from .. import homeassistant_ns DEPENDENCIES = ['api'] -HomeassistantSensor = homeassistant_ns.class_('HomeassistantSensor', sensor.Sensor) +HomeassistantSensor = homeassistant_ns.class_('HomeassistantSensor', sensor.Sensor, + cg.Component) CONFIG_SCHEMA = sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 1).extend({ cv.GenerateID(): cv.declare_id(HomeassistantSensor), diff --git a/esphome/components/mqtt/mqtt_climate.cpp b/esphome/components/mqtt/mqtt_climate.cpp index 590a6db7b4..8085fbf0f2 100644 --- a/esphome/components/mqtt/mqtt_climate.cpp +++ b/esphome/components/mqtt/mqtt_climate.cpp @@ -24,12 +24,12 @@ void MQTTClimateComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryC JsonArray &modes = root.createNestedArray("modes"); // sort array for nice UI in HA if (traits.supports_mode(CLIMATE_MODE_AUTO)) - modes.add(climate_mode_to_string(CLIMATE_MODE_AUTO)); - modes.add(climate_mode_to_string(CLIMATE_MODE_OFF)); + modes.add("auto"); + modes.add("off"); if (traits.supports_mode(CLIMATE_MODE_COOL)) - modes.add(climate_mode_to_string(CLIMATE_MODE_COOL)); + modes.add("cool"); if (traits.supports_mode(CLIMATE_MODE_HEAT)) - modes.add(climate_mode_to_string(CLIMATE_MODE_HEAT)); + modes.add("heat"); if (traits.get_supports_two_point_target_temperature()) { // temperature_low_command_topic diff --git a/esphome/components/status/status_binary_sensor.cpp b/esphome/components/status/status_binary_sensor.cpp index 5485c6ebcd..d004c70b95 100644 --- a/esphome/components/status/status_binary_sensor.cpp +++ b/esphome/components/status/status_binary_sensor.cpp @@ -18,19 +18,16 @@ void StatusBinarySensor::loop() { bool status = network_is_connected(); #ifdef USE_MQTT if (mqtt::global_mqtt_client != nullptr) { - status = mqtt::global_mqtt_client->is_connected(); + status = status && mqtt::global_mqtt_client->is_connected(); } #endif #ifdef USE_API if (api::global_api_server != nullptr) { - status = api::global_api_server->is_connected(); + status = status && api::global_api_server->is_connected(); } #endif - if (this->last_status_ != status) { - this->publish_state(status); - this->last_status_ = status; - } + this->publish_state(status); } void StatusBinarySensor::setup() { this->publish_state(false); } void StatusBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Status Binary Sensor", this); } diff --git a/esphome/components/status/status_binary_sensor.h b/esphome/components/status/status_binary_sensor.h index fa121291a1..08aa0fb32f 100644 --- a/esphome/components/status/status_binary_sensor.h +++ b/esphome/components/status/status_binary_sensor.h @@ -16,9 +16,6 @@ class StatusBinarySensor : public binary_sensor::BinarySensor, public Component float get_setup_priority() const override { return setup_priority::DATA; } bool is_status_binary_sensor() const override { return true; } - - protected: - bool last_status_{false}; }; } // namespace status diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 769a7825da..c65ca919ba 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -257,7 +257,7 @@ std::string to_string(long double val) { optional parse_float(const std::string &str) { char *end; float value = ::strtof(str.c_str(), &end); - if (end == nullptr) + if (end == nullptr || end != str.end().base()) return {}; return value; } diff --git a/script/clang-format b/script/clang-format index d5792c783e..89a5acd746 100755 --- a/script/clang-format +++ b/script/clang-format @@ -13,7 +13,7 @@ import threading import click sys.path.append(os.path.dirname(__file__)) -from helpers import basepath, get_output, walk_files, filter_changed +from helpers import basepath, get_output, git_ls_files, filter_changed is_py2 = sys.version[0] == '2' @@ -83,7 +83,7 @@ def main(): return 1 files = [] - for path in walk_files(basepath): + for path in git_ls_files(): filetypes = ('.cpp', '.h', '.tcc') ext = os.path.splitext(path)[1] if ext in filetypes: diff --git a/script/clang-tidy b/script/clang-tidy index 124008a873..39df87df22 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -18,7 +18,7 @@ import threading sys.path.append(os.path.dirname(__file__)) from helpers import basepath, shlex_quote, get_output, build_compile_commands, \ - build_all_include, temp_header_file, walk_files, filter_changed + build_all_include, temp_header_file, git_ls_files, filter_changed is_py2 = sys.version[0] == '2' @@ -100,7 +100,7 @@ def main(): build_compile_commands() files = [] - for path in walk_files(basepath): + for path in git_ls_files(): filetypes = ('.cpp',) ext = os.path.splitext(path)[1] if ext in filetypes: diff --git a/script/helpers.py b/script/helpers.py index 8b37dce570..243dfde49e 100644 --- a/script/helpers.py +++ b/script/helpers.py @@ -126,3 +126,13 @@ def filter_changed(files): for c in files: print(" {}".format(c)) return files + + +def git_ls_files(): + command = ['git', 'ls-files', '-s'] + proc = subprocess.Popen(command, stdout=subprocess.PIPE) + output, err = proc.communicate() + lines = [x.split() for x in output.decode('utf-8').splitlines()] + return { + s[3].strip(): int(s[0]) for s in lines + } diff --git a/script/lint-python b/script/lint-python index cb702bf362..415efa0ebf 100755 --- a/script/lint-python +++ b/script/lint-python @@ -9,7 +9,7 @@ import re import sys sys.path.append(os.path.dirname(__file__)) -from helpers import basepath, get_output, walk_files, filter_changed +from helpers import get_output, git_ls_files, filter_changed def main(): @@ -21,10 +21,10 @@ def main(): args = parser.parse_args() files = [] - for path in walk_files(basepath): + for path in git_ls_files(): filetypes = ('.py',) ext = os.path.splitext(path)[1] - if ext in filetypes: + if ext in filetypes and path.startswith('esphome'): path = os.path.relpath(path, os.getcwd()) files.append(path) # Match against re @@ -35,6 +35,8 @@ def main(): files = filter_changed(files) files.sort() + if not files: + sys.exit(0) errors = collections.defaultdict(list) cmd = ['flake8'] + files