diff --git a/esphome/components/bh1750/bh1750.cpp b/esphome/components/bh1750/bh1750.cpp index 2ec297a6f4..799440fdfc 100644 --- a/esphome/components/bh1750/bh1750.cpp +++ b/esphome/components/bh1750/bh1750.cpp @@ -17,8 +17,8 @@ void BH1750Sensor::setup() { return; } - uint8_t mtreg_hi = (this->measurement_time_ >> 5) & 0b111; - uint8_t mtreg_lo = (this->measurement_time_ >> 0) & 0b11111; + uint8_t mtreg_hi = (this->measurement_duration_ >> 5) & 0b111; + uint8_t mtreg_lo = (this->measurement_duration_ >> 0) & 0b11111; this->write_bytes(BH1750_COMMAND_MT_REG_HI | mtreg_hi, nullptr, 0); this->write_bytes(BH1750_COMMAND_MT_REG_LO | mtreg_lo, nullptr, 0); } @@ -77,7 +77,7 @@ void BH1750Sensor::read_data_() { } float lx = float(raw_value) / 1.2f; - lx *= 69.0f / this->measurement_time_; + lx *= 69.0f / this->measurement_duration_; ESP_LOGD(TAG, "'%s': Got illuminance=%.1flx", this->get_name().c_str(), lx); this->publish_state(lx); this->status_clear_warning(); diff --git a/esphome/components/bh1750/bh1750.h b/esphome/components/bh1750/bh1750.h index 00abd53e92..c88fa10832 100644 --- a/esphome/components/bh1750/bh1750.h +++ b/esphome/components/bh1750/bh1750.h @@ -28,7 +28,7 @@ class BH1750Sensor : public sensor::Sensor, public PollingComponent, public i2c: * @param resolution The new resolution of the sensor. */ void set_resolution(BH1750Resolution resolution); - void set_measurement_time(uint8_t measurement_time) { measurement_time_ = measurement_time; } + void set_measurement_duration(uint8_t measurement_duration) { measurement_duration_ = measurement_duration; } // ========== INTERNAL METHODS ========== // (In most use cases you won't need these) @@ -41,7 +41,7 @@ class BH1750Sensor : public sensor::Sensor, public PollingComponent, public i2c: void read_data_(); BH1750Resolution resolution_{BH1750_RESOLUTION_0P5_LX}; - uint8_t measurement_time_; + uint8_t measurement_duration_; }; } // namespace bh1750 diff --git a/esphome/components/bh1750/sensor.py b/esphome/components/bh1750/sensor.py index 9ad1b7eadb..0e37b2b865 100644 --- a/esphome/components/bh1750/sensor.py +++ b/esphome/components/bh1750/sensor.py @@ -7,6 +7,7 @@ from esphome.const import ( DEVICE_CLASS_ILLUMINANCE, ICON_EMPTY, UNIT_LUX, + CONF_MEASUREMENT_DURATION, ) DEPENDENCIES = ["i2c"] @@ -32,9 +33,12 @@ CONFIG_SCHEMA = ( cv.Optional(CONF_RESOLUTION, default=0.5): cv.enum( BH1750_RESOLUTIONS, float=True ), - cv.Optional(CONF_MEASUREMENT_TIME, default=69): cv.int_range( + cv.Optional(CONF_MEASUREMENT_DURATION, default=69): cv.int_range( min=31, max=254 ), + cv.Optional(CONF_MEASUREMENT_TIME): cv.invalid( + "The 'measurement_time' option has been replaced with 'measurement_duration' in 1.18.0" + ), } ) .extend(cv.polling_component_schema("60s")) @@ -49,4 +53,4 @@ def to_code(config): yield i2c.register_i2c_device(var, config) cg.add(var.set_resolution(config[CONF_RESOLUTION])) - cg.add(var.set_measurement_time(config[CONF_MEASUREMENT_TIME])) + cg.add(var.set_measurement_duration(config[CONF_MEASUREMENT_DURATION])) diff --git a/tests/test1.yaml b/tests/test1.yaml index 0f1e6aa97f..01431eb1fc 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -413,7 +413,7 @@ sensor: retain: False availability: state_topic: livingroom/custom_state_topic - measurement_time: 31 + measurement_duration: 31 - platform: bme280 temperature: name: 'Outside Temperature'