Rename {u,i,p,e}_ref to {voltage,current,power,energy}_reference

This commit is contained in:
Jimmy Wennlund 2024-09-08 22:49:24 +02:00
parent 74a1ffe8ce
commit 81d9d3a9d6
3 changed files with 34 additions and 24 deletions

View file

@ -346,19 +346,19 @@ int32_t BL0910::read_register(uint8_t addr) {
}
float BL0910::getVoltage(uint8_t channel) {
return ((float) read_register(BL0910_REG_RMS[channel])) / this->uref[channel];
return ((float) read_register(BL0910_REG_RMS[channel])) / this->voltage_reference[channel];
}
float BL0910::getCurrent(uint8_t channel) {
return ((float) read_register(BL0910_REG_RMS[channel])) / this->iref[channel];
return ((float) read_register(BL0910_REG_RMS[channel])) / this->current_reference[channel];
}
float BL0910::getPower(uint8_t channel) {
return ((float) read_register(BL0910_REG_WATT[channel])) / this->pref[channel];
return ((float) read_register(BL0910_REG_WATT[channel])) / this->power_reference[channel];
}
float BL0910::getEnergy(uint8_t channel) {
return ((float) read_register(BL0910_REG_CF_CNT[channel])) / this->eref[channel];
return ((float) read_register(BL0910_REG_CF_CNT[channel])) / this->energy_reference[channel];
}
float BL0910::getFreq(void) {

View file

@ -16,21 +16,21 @@ class BL0910 : public PollingComponent,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_TRAILING,
spi::DATA_RATE_1MHZ> {
public:
void set_voltage_sensor(sensor::Sensor *voltage_sensor_, int index, float uref_) {
void set_voltage_sensor(sensor::Sensor *voltage_sensor_, int index, float voltage_reference_) {
voltage_sensor[index - 1] = voltage_sensor_;
uref[index - 1] = uref_;
voltage_reference[index - 1] = voltage_reference_;
}
void set_current_sensor(sensor::Sensor *current_sensor_, int index, float iref_) {
void set_current_sensor(sensor::Sensor *current_sensor_, int index, float current_reference_) {
current_sensor[index - 1] = current_sensor_;
iref[index - 1] = iref_;
current_reference[index - 1] = current_reference_;
}
void set_power_sensor(sensor::Sensor *power_sensor_, int index, float pref_) {
void set_power_sensor(sensor::Sensor *power_sensor_, int index, float power_reference_) {
power_sensor[index - 1] = power_sensor_;
pref[index - 1] = pref_;
power_reference[index - 1] = power_reference_;
}
void set_energy_sensor(sensor::Sensor *energy_sensor_, int index, float eref_) {
void set_energy_sensor(sensor::Sensor *energy_sensor_, int index, float energy_reference_) {
energy_sensor[index - 1] = energy_sensor_;
eref[index - 1] = eref_;
energy_reference[index - 1] = energy_reference_;
}
void set_power_factor_sensor(sensor::Sensor *power_factor_sensor_, int index) {
power_factor_sensor[index - 1] = power_factor_sensor_;
@ -55,10 +55,10 @@ class BL0910 : public PollingComponent,
sensor::Sensor *frequency_sensor{nullptr};
sensor::Sensor *temperature_sensor{nullptr};
float uref[NUM_CHANNELS] = {};
float iref[NUM_CHANNELS] = {};
float pref[NUM_CHANNELS] = {};
float eref[NUM_CHANNELS] = {};
float voltage_reference[NUM_CHANNELS] = {};
float current_reference[NUM_CHANNELS] = {};
float power_reference[NUM_CHANNELS] = {};
float energy_reference[NUM_CHANNELS] = {};
private:
int8_t checksum_calc(uint8_t *data);

View file

@ -34,7 +34,7 @@ VOLTAGE_CB = {
accuracy_decimals=1,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
).extend({cv.Optional("uref", default=1.0): cv.float_})
).extend({cv.Optional("voltage_reference", default=1.0): cv.float_})
for i in SENSOR_RANGE
}
@ -44,7 +44,7 @@ CURRENT_CV = {
accuracy_decimals=2,
device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
).extend({cv.Optional("iref", default=1.0): cv.float_})
).extend({cv.Optional("current_reference", default=1.0): cv.float_})
for i in SENSOR_RANGE
}
@ -54,7 +54,7 @@ ACTIVE_POWER_CV = {
accuracy_decimals=0,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
).extend({cv.Optional("pref", default=1.0): cv.float_})
).extend({cv.Optional("power_reference", default=1.0): cv.float_})
for i in SENSOR_RANGE
}
@ -64,7 +64,7 @@ ENERGY_CV = {
accuracy_decimals=3,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
).extend({cv.Optional("eref", default=1.0): cv.float_})
).extend({cv.Optional("energy_reference", default=1.0): cv.float_})
for i in SENSOR_RANGE
}
@ -120,16 +120,26 @@ async def to_code(config):
for i in SENSOR_RANGE:
if voltage_config := config.get(f"voltage_{i}"):
sens = await sensor.new_sensor(voltage_config)
cg.add(var.set_voltage_sensor(sens, i, voltage_config.get("uref")))
cg.add(
var.set_voltage_sensor(sens, i, voltage_config.get("voltage_reference"))
)
if current_config := config.get(f"current_{i}"):
sens = await sensor.new_sensor(current_config)
cg.add(var.set_current_sensor(sens, i, current_config.get("iref")))
cg.add(
var.set_current_sensor(sens, i, current_config.get("current_reference"))
)
if active_power_config := config.get(f"active_power_{i}"):
sens = await sensor.new_sensor(active_power_config)
cg.add(var.set_power_sensor(sens, i, active_power_config.get("pref")))
cg.add(
var.set_power_sensor(
sens, i, active_power_config.get("power_reference")
)
)
if energy_config := config.get(f"energy_{i}"):
sens = await sensor.new_sensor(energy_config)
cg.add(var.set_energy_sensor(sens, i, energy_config.get("eref")))
cg.add(
var.set_energy_sensor(sens, i, energy_config.get("energy_reference"))
)
if power_factor_config := config.get(f"power_factor_{i}"):
sens = await sensor.new_sensor(power_factor_config)
cg.add(var.set_power_factor_sensor(sens, i))