Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
AzonInc committed Oct 25, 2024
1 parent 23cdc54 commit 205ad56
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
23 changes: 1 addition & 22 deletions components/tc_bus/tc_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ namespace esphome
this->pref_.save(&this->model_);
}

#ifdef USE_SELECT
if (this->intercom_model_select_ != nullptr)
this->intercom_model_select_->publish_state(model_to_string(model_));
#endif

#if defined(USE_ESP_IDF) || (defined(USE_ARDUINO) && defined(ESP32))
ESP_LOGD(TAG, "Check for Doorman Hardware");
Expand Down Expand Up @@ -101,10 +99,8 @@ namespace esphome
}
#endif

#ifdef USE_TEXT_SENSOR
if (this->hardware_version_text_sensor_ != nullptr)
this->hardware_version_text_sensor_->publish_state(this->hardware_version_str_);
#endif

this->rx_pin_->setup();
this->tx_pin_->setup();
Expand All @@ -116,15 +112,11 @@ namespace esphome
this->rx_pin_->attach_interrupt(TCBusComponentStore::gpio_intr, &this->store_, gpio::INTERRUPT_ANY_EDGE);

// Reset Sensors
#ifdef USE_TEXT_SENSOR
if (this->bus_command_text_sensor_ != nullptr)
this->bus_command_text_sensor_->publish_state("");
#endif

#ifdef USE_BINARY_SENSOR
if (this->door_readiness_binary_sensor_ != nullptr)
this->door_readiness_binary_sensor_->publish_initial_state(false);
#endif

for (auto &listener : listeners_)
{
Expand All @@ -149,16 +141,12 @@ namespace esphome

ESP_LOGCONFIG(TAG, " Hardware: %s", this->hardware_version_str_.c_str());

#ifdef USE_BINARY_SENSOR
ESP_LOGCONFIG(TAG, "Binary Sensors:");
LOG_BINARY_SENSOR(" ", "Door readiness", this->door_readiness_binary_sensor_);
#endif

#ifdef USE_TEXT_SENSOR
ESP_LOGCONFIG(TAG, "Text Sensors:");
LOG_TEXT_SENSOR(" ", "Last Bus Command", this->bus_command_text_sensor_);
LOG_TEXT_SENSOR(" ", "Hardware Version", this->hardware_version_text_sensor_);
#endif
}

void TCBusComponent::loop()
Expand Down Expand Up @@ -411,20 +399,15 @@ namespace esphome
bool door_readiness_state = cmd_data.payload == 1;
ESP_LOGD(TAG, "Door readiness: %s", YESNO(door_readiness_state));

#ifdef USE_BINARY_SENSOR
if (this->door_readiness_binary_sensor_ != nullptr)
this->door_readiness_binary_sensor_->publish_state(door_readiness_state);
#endif
}
else if (cmd_data.type == COMMAND_TYPE_END_OF_DOOR_READINESS)
{
ESP_LOGD(TAG, "Door readiness: %s", YESNO(false));

#ifdef USE_BINARY_SENSOR
if (this->door_readiness_binary_sensor_ != nullptr)
this->door_readiness_binary_sensor_->publish_state(false);
#endif
}
this->door_readiness_binary_sensor_->publish_state(false); }
else if (cmd_data.type == COMMAND_TYPE_PROGRAMMING_MODE)
{
ESP_LOGD(TAG, "Programming Mode: %s", YESNO(cmd_data.payload == 1));
Expand Down Expand Up @@ -455,10 +438,8 @@ namespace esphome
}

// Publish Command to Last Bus Command Sensor
#ifdef USE_TEXT_SENSOR
if (this->bus_command_text_sensor_ != nullptr)
this->bus_command_text_sensor_->publish_state(cmd_data.command_hex);
#endif

// If the command was received, notify the listeners
if (received)
Expand Down Expand Up @@ -935,7 +916,6 @@ namespace esphome
}
}

#ifdef USE_SELECT
void IntercomModelSelect::control(const std::string &value)
{
this->publish_state(value);
Expand All @@ -944,7 +924,6 @@ namespace esphome
this->parent_->model_ = model;
this->parent_->pref_.save(&model);
}
#endif

} // namespace tc_bus
} // namespace esphome
13 changes: 0 additions & 13 deletions components/tc_bus/tc_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"

#ifdef USE_TEXT_SENSOR
#include "esphome/components/text_sensor/text_sensor.h"
#endif
#ifdef USE_SELECT
#include "esphome/components/select/select.h"
#endif

namespace esphome
{
Expand Down Expand Up @@ -71,16 +66,10 @@ namespace esphome

class TCBusComponent : public Component
{
#ifdef USE_SELECT
SUB_SELECT(intercom_model)
#endif
#ifdef USE_TEXT_SENSOR
SUB_TEXT_SENSOR(bus_command)
SUB_TEXT_SENSOR(hardware_version)
#endif
#ifdef USE_BINARY_SENSOR
SUB_BINARY_SENSOR(door_readiness)
#endif

public:
void set_rx_pin(InternalGPIOPin *pin) { this->rx_pin_ = pin; }
Expand Down Expand Up @@ -145,14 +134,12 @@ namespace esphome
ESPPreferenceObject pref_;
};

#ifdef USE_SELECT
class IntercomModelSelect : public select::Select, public Parented<TCBusComponent> {
public:
IntercomModelSelect() = default;
protected:
void control(const std::string &value) override;
};
#endif

} // namespace tc_bus

Expand Down

0 comments on commit 205ad56

Please sign in to comment.