diff --git a/esphome/components/duco/__init__.py b/esphome/components/duco/__init__.py index 92d22ecc2d..471f820271 100644 --- a/esphome/components/duco/__init__.py +++ b/esphome/components/duco/__init__.py @@ -22,6 +22,16 @@ CONF_DISCOVERY = "discovery" # A schema for components like sensors DUCO_COMPONENT_SCHEMA = cv.Schema({cv.GenerateID(CONF_DUCO_ID): cv.use_id(Duco)}) +DISCOVERY_SCHEMA = ( + cv.Schema( + { + cv.GenerateID(): cv.declare_id(DucoDiscovery), + } + ) + .extend(cv.polling_component_schema("60s")) + .extend(DUCO_COMPONENT_SCHEMA) +) + CONFIG_SCHEMA = ( cv.Schema( { @@ -30,13 +40,7 @@ CONFIG_SCHEMA = ( CONF_SEND_WAIT_TIME, default="250ms" ): cv.positive_time_period_milliseconds, cv.Optional(CONF_DISABLE_CRC, default=False): cv.boolean, - cv.Optional(CONF_DISCOVERY): cv.Schema( - { - cv.GenerateID(): cv.declare_id(DucoDiscovery), - } - ) - .extend(cv.polling_component_schema("60s")) - .extend(DUCO_COMPONENT_SCHEMA), + cv.Optional(CONF_DISCOVERY): DISCOVERY_SCHEMA, } ) .extend(cv.COMPONENT_SCHEMA) diff --git a/esphome/components/duco/duco.cpp b/esphome/components/duco/duco.cpp index 70aaec4958..76b00b6c78 100644 --- a/esphome/components/duco/duco.cpp +++ b/esphome/components/duco/duco.cpp @@ -197,8 +197,9 @@ const std::string friendly_node_type(uint8_t type_code) { void DucoDiscovery::update() { // display all found nodes + ESP_LOGI(TAG, "Discovered nodes:"); for (auto &node : nodes_) { - ESP_LOGI(TAG, "Node %d: type %d (%s)", std::get<0>(node), std::get<1>(node), + ESP_LOGI(TAG, " Node %d: type %d (%s)", std::get<0>(node), std::get<1>(node), friendly_node_type(std::get<1>(node)).c_str()); } } @@ -225,7 +226,7 @@ void DucoDiscovery::loop() { } void DucoDiscovery::receive_response(DucoMessage message) { - if (message.id == 0x0e) { + if (message.function == 0x0e) { ESP_LOGV(TAG, "Discovery response message: %s", format_hex_pretty(message).c_str()); this->parent_->stop_waiting(message.id);