Skip to content

Commit

Permalink
Replace ifdef with empty string checks
Browse files Browse the repository at this point in the history
  • Loading branch information
torfbolt committed Jan 11, 2025
1 parent f513b77 commit 9340901
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
2 changes: 0 additions & 2 deletions esphome/components/usb_device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ async def to_code(config):
cg.add_define("USE_PRODUCT_ID")
cg.add(var.set_product_id(config[CONF_PRODUCT_ID]))
if CONF_MANUFACTURER_NAME in config:
cg.add_define("USE_MANUFACTURER_NAME")
cg.add(var.set_manufacturer_name(config[CONF_MANUFACTURER_NAME]))
if CONF_PRODUCT_NAME in config:
cg.add_define("USE_PRODUCT_NAME")
cg.add(var.set_product_name(config[CONF_PRODUCT_NAME]))

await cg.register_component(var, config)
Expand Down
20 changes: 6 additions & 14 deletions esphome/components/usb_device/usb_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ void UsbDevice::setup() {
#ifdef USE_PRODUCT_ID
USB.PID(this->product_id_);
#endif
#ifdef USE_MANUFACTURER_NAME
USB.manufacturerName(this->manufacturer_name_.c_str());
#endif
#ifdef USE_PRODUCT_NAME
USB.productName(this->product_name_.c_str());
#endif
if (!this->manufacturer_name_.empty()) {
USB.manufacturerName(this->manufacturer_name_.c_str());
}
if (!this->product_name_.empty()) {
USB.productName(this->product_name_.c_str());
}
USB.begin();
}

Expand Down Expand Up @@ -49,18 +49,10 @@ void UsbDevice::dump_config() {
YESNO(TinyUSBDevice.suspended()), YESNO(TinyUSBDevice.ready()));
}

#ifdef USE_VENDOR_ID
void UsbDevice::set_vendor_id(const uint16_t vid) { this->vendor_id_ = vid; }
#endif
#ifdef USE_PRODUCT_ID
void UsbDevice::set_product_id(const uint16_t pid) { this->product_id_ = pid; }
#endif
#ifdef USE_MANUFACTURER_NAME
void UsbDevice::set_manufacturer_name(const std::string &manufacturer_name) { this->manufacturer_name_ = manufacturer_name; }
#endif
#ifdef USE_PRODUCT_NAME
void UsbDevice::set_product_name(const std::string &product_name) { this->product_name_ = product_name; }
#endif

#ifdef USE_BINARY_SENSOR
void UsbDevice::set_mounted_binary_sensor(binary_sensor::BinarySensor *sensor) { mounted_ = sensor; };
Expand Down
16 changes: 0 additions & 16 deletions esphome/components/usb_device/usb_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,20 @@ class UsbDevice : public PollingComponent {
void update() override;
float get_setup_priority() const override;
void dump_config() override;
#ifdef USE_VENDOR_ID
void set_vendor_id(uint16_t vendor_id);
#endif
#ifdef USE_PRODUCT_ID
void set_product_id(uint16_t product_id);
#endif
#ifdef USE_MANUFACTURER_NAME
void set_manufacturer_name(const std::string &manufacturer_name);
#endif
#ifdef USE_PRODUCT_NAME
void set_product_name(const std::string &product_name);
#endif
#ifdef USE_BINARY_SENSOR
void set_mounted_binary_sensor(binary_sensor::BinarySensor *sensor);
void set_ready_binary_sensor(binary_sensor::BinarySensor *sensor);
void set_suspended_binary_sensor(binary_sensor::BinarySensor *sensor);
#endif
protected:
#ifdef USE_VENDOR_ID
uint16_t vendor_id_;
#endif
#ifdef USE_PRODUCT_ID
uint16_t product_id_;
#endif
#ifdef USE_MANUFACTURER_NAME
std::string manufacturer_name_;
#endif
#ifdef USE_PRODUCT_NAME
std::string product_name_;
#endif
#ifdef USE_BINARY_SENSOR
binary_sensor::BinarySensor *mounted_;
binary_sensor::BinarySensor *ready_;
Expand Down

0 comments on commit 9340901

Please sign in to comment.