mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Code tidy
This commit is contained in:
		| @@ -1,12 +1,12 @@ | ||||
| #include "oralb_ble.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
| #ifdef USE_ESP32 | ||||
|  | ||||
| namespace esphome { | ||||
| namespace oralb_ble { | ||||
|  | ||||
| static const char *TAG = "oralb_ble"; | ||||
| static const char *const TAG = "oralb_ble"; | ||||
|  | ||||
| bool parse_oralb_data_byte(const esp32_ble_tracker::adv_data_t &adv_data, OralbParseResult &result) { | ||||
|   result.state = adv_data[3]; | ||||
| @@ -45,4 +45,4 @@ bool OralbListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { | ||||
| }  // namespace oralb_ble | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
| #endif  // USE_ESP32 | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" | ||||
|  | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
| #ifdef USE_ESP32 | ||||
|  | ||||
| namespace esphome { | ||||
| namespace oralb_ble { | ||||
| @@ -24,4 +24,4 @@ class OralbListener : public esp32_ble_tracker::ESPBTDeviceListener { | ||||
| }  // namespace oralb_ble | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
| #endif  // USE_ESP32 | ||||
|   | ||||
| @@ -1,19 +1,33 @@ | ||||
| #include "oralb_brush.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
| #ifdef USE_ESP32 | ||||
|  | ||||
| namespace esphome { | ||||
| namespace oralb_brush { | ||||
|  | ||||
| static const char *TAG = "oralb_brush"; | ||||
| static const char *const TAG = "oralb_brush"; | ||||
|  | ||||
| void OralbBrush::dump_config() { | ||||
|   ESP_LOGCONFIG(TAG, "OralbBrush"); | ||||
|   LOG_SENSOR("  ", "State", this->state_); | ||||
| } | ||||
|  | ||||
| bool OralbBrush::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { | ||||
|   if (device.address_uint64() != this->address_) | ||||
|     return false; | ||||
|  | ||||
|   auto res = oralb_ble::parse_oralb(device); | ||||
|   if (!res.has_value()) | ||||
|     return false; | ||||
|  | ||||
|   if (res->state.has_value() && this->state_ != nullptr) | ||||
|     this->state_->publish_state(*res->state); | ||||
|  | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| }  // namespace oralb_brush | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
| #endif  // USE_ESP32 | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
| #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" | ||||
| #include "esphome/components/oralb_ble/oralb_ble.h" | ||||
|  | ||||
| #ifdef ARDUINO_ARCH_ESP32 | ||||
| #ifdef USE_ESP32 | ||||
|  | ||||
| namespace esphome { | ||||
| namespace oralb_brush { | ||||
| @@ -14,19 +14,7 @@ class OralbBrush : public Component, public esp32_ble_tracker::ESPBTDeviceListen | ||||
|  public: | ||||
|   void set_address(uint64_t address) { address_ = address; } | ||||
|  | ||||
|   bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override { | ||||
|     if (device.address_uint64() != this->address_) | ||||
|       return false; | ||||
|  | ||||
|     auto res = oralb_ble::parse_oralb(device); | ||||
|     if (!res.has_value()) | ||||
|       return false; | ||||
|  | ||||
|     if (res->state.has_value() && this->state_ != nullptr) | ||||
|       this->state_->publish_state(*res->state); | ||||
|  | ||||
|     return true; | ||||
|   } | ||||
|   bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; | ||||
|  | ||||
|   void dump_config() override; | ||||
|   float get_setup_priority() const override { return setup_priority::DATA; } | ||||
| @@ -40,4 +28,4 @@ class OralbBrush : public Component, public esp32_ble_tracker::ESPBTDeviceListen | ||||
| }  // namespace oralb_brush | ||||
| }  // namespace esphome | ||||
|  | ||||
| #endif | ||||
| #endif  // USE_ESP32 | ||||
|   | ||||
| @@ -1,27 +1,27 @@ | ||||
| import esphome.codegen as cg | ||||
| import esphome.config_validation as cv | ||||
| from esphome.components import sensor, esp32_ble_tracker | ||||
| from esphome.const import CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_TEMPERATURE, \ | ||||
|     CONF_PRESSURE, CONF_ACCELERATION, CONF_ACCELERATION_X, CONF_ACCELERATION_Y, \ | ||||
|     CONF_ACCELERATION_Z, CONF_BATTERY_VOLTAGE, CONF_TX_POWER, \ | ||||
|     CONF_MEASUREMENT_SEQUENCE_NUMBER, CONF_MOVEMENT_COUNTER, UNIT_CELSIUS, \ | ||||
|     ICON_THERMOMETER, UNIT_PERCENT, UNIT_VOLT, UNIT_HECTOPASCAL, UNIT_G, \ | ||||
|     UNIT_DECIBEL_MILLIWATT, UNIT_EMPTY, ICON_WATER_PERCENT, ICON_BATTERY, \ | ||||
|     ICON_GAUGE, ICON_ACCELERATION, ICON_ACCELERATION_X, ICON_ACCELERATION_Y, \ | ||||
|     ICON_ACCELERATION_Z, ICON_SIGNAL, CONF_ID, ICON_EMPTY, CONF_STATE | ||||
| from esphome.const import CONF_MAC_ADDRESS, CONF_ID, CONF_STATE | ||||
|  | ||||
| DEPENDENCIES = ['esp32_ble_tracker'] | ||||
| AUTO_LOAD = ['oralb_ble'] | ||||
| DEPENDENCIES = ["esp32_ble_tracker"] | ||||
| AUTO_LOAD = ["oralb_ble"] | ||||
|  | ||||
| oralb_brush_ns = cg.esphome_ns.namespace('oralb_brush') | ||||
| oralb_brush_ns = cg.esphome_ns.namespace("oralb_brush") | ||||
| OralbBrush = oralb_brush_ns.class_( | ||||
|     'OralbBrush', esp32_ble_tracker.ESPBTDeviceListener, cg.Component) | ||||
|     "OralbBrush", esp32_ble_tracker.ESPBTDeviceListener, cg.Component | ||||
| ) | ||||
|  | ||||
| CONFIG_SCHEMA = cv.Schema({ | ||||
|     cv.GenerateID(): cv.declare_id(OralbBrush), | ||||
|     cv.Required(CONF_MAC_ADDRESS): cv.mac_address, | ||||
|     cv.Optional(CONF_STATE): sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 0), | ||||
| }).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA) | ||||
| CONFIG_SCHEMA = ( | ||||
|     cv.Schema( | ||||
|         { | ||||
|             cv.GenerateID(): cv.declare_id(OralbBrush), | ||||
|             cv.Required(CONF_MAC_ADDRESS): cv.mac_address, | ||||
|             cv.Optional(CONF_STATE): sensor.sensor_schema(accuracy_decimals=0), | ||||
|         } | ||||
|     ) | ||||
|     .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) | ||||
|     .extend(cv.COMPONENT_SCHEMA) | ||||
| ) | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user