mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Add ability to lock to set mode (#5924)
This commit is contained in:
		| @@ -96,7 +96,7 @@ void HLW8012Component::update() { | ||||
|     this->energy_sensor_->publish_state(energy); | ||||
|   } | ||||
|  | ||||
|   if (this->change_mode_at_++ == this->change_mode_every_) { | ||||
|   if (this->change_mode_every_ != 0 && this->change_mode_at_++ == this->change_mode_every_) { | ||||
|     this->current_mode_ = !this->current_mode_; | ||||
|     ESP_LOGV(TAG, "Changing mode to %s mode", this->current_mode_ ? "CURRENT" : "VOLTAGE"); | ||||
|     this->change_mode_at_ = 0; | ||||
|   | ||||
| @@ -79,8 +79,9 @@ CONFIG_SCHEMA = cv.Schema( | ||||
|         cv.Optional(CONF_CURRENT_RESISTOR, default=0.001): cv.resistance, | ||||
|         cv.Optional(CONF_VOLTAGE_DIVIDER, default=2351): cv.positive_float, | ||||
|         cv.Optional(CONF_MODEL, default="HLW8012"): cv.enum(MODELS, upper=True), | ||||
|         cv.Optional(CONF_CHANGE_MODE_EVERY, default=8): cv.All( | ||||
|             cv.uint32_t, cv.Range(min=1) | ||||
|         cv.Optional(CONF_CHANGE_MODE_EVERY, default=8): cv.Any( | ||||
|             "never", | ||||
|             cv.All(cv.uint32_t, cv.Range(min=1)), | ||||
|         ), | ||||
|         cv.Optional(CONF_INITIAL_MODE, default=CONF_VOLTAGE): cv.one_of( | ||||
|             *INITIAL_MODES, lower=True | ||||
| @@ -114,6 +115,10 @@ async def to_code(config): | ||||
|         cg.add(var.set_energy_sensor(sens)) | ||||
|     cg.add(var.set_current_resistor(config[CONF_CURRENT_RESISTOR])) | ||||
|     cg.add(var.set_voltage_divider(config[CONF_VOLTAGE_DIVIDER])) | ||||
|     cg.add(var.set_change_mode_every(config[CONF_CHANGE_MODE_EVERY])) | ||||
|     cg.add(var.set_initial_mode(INITIAL_MODES[config[CONF_INITIAL_MODE]])) | ||||
|     cg.add(var.set_sensor_model(config[CONF_MODEL])) | ||||
|  | ||||
|     interval = config[CONF_CHANGE_MODE_EVERY] | ||||
|     if interval == "never": | ||||
|         interval = 0 | ||||
|     cg.add(var.set_change_mode_every(interval)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user