Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/ip5306/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor, i2c, sensor
from esphome.const import CONF_ID, CONF_BATTERY_LEVEL, DEVICE_CLASS_VOLTAGE, ICON_PERCENT, UNIT_PERCENT
from esphome.const import CONF_ID, CONF_BATTERY_LEVEL, DEVICE_CLASS_BATTERY, ICON_BATTERY, UNIT_PERCENT

MULTI_CONF = True

Expand All @@ -18,7 +18,7 @@
cv.GenerateID(): cv.declare_id(IP5306),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT,
icon=ICON_PERCENT,
device_class=DEVICE_CLASS_BATTERY,
accuracy_decimals=0,
),
cv.Optional(CONF_CHARGER_CONNECTED): binary_sensor.binary_sensor_schema(),
Expand Down
5 changes: 2 additions & 3 deletions components/ip5306/ip5306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void IP5306::setup() {
}
}

void IP5306::loop() {
void IP5306::update() {
uint8_t data[2];
if (this->battery_level_ != nullptr) {
if (this->read_register(IP5306_REG_LEVEL, data, 1) != i2c::ERROR_OK) {
Expand All @@ -40,8 +40,7 @@ void IP5306::loop() {
case 0x80: value = 75; break;
case 0x00: value = 100; break;
}
if (!this->battery_level_->has_state() || (this->battery_level_->state != value))
this->battery_level_->publish_state(value);
this->battery_level_->publish_state(value);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be indented a little bit more?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Fixed it in my fork, but not sure how to 'republish' this in this pull request.

}
if (this->read_register(IP5306_REG_READ0, data, 2) != i2c::ERROR_OK) {
ESP_LOGE(TAG, "unable to read status");
Expand Down
5 changes: 3 additions & 2 deletions components/ip5306/ip5306.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
namespace esphome {
namespace ip5306 {

class IP5306 : public i2c::I2CDevice, public Component {
class IP5306 : public i2c::I2CDevice, public PollingComponent {
public:
IP5306() : PollingComponent(60000) {}
void setup() override;
void loop() override;
void update() override;

float get_setup_priority() const override;

Expand Down