GithubHelp home page GithubHelp logo

ip5306 about esphome_components HOT 7 OPEN

ssieb avatar ssieb commented on July 24, 2024
ip5306

from esphome_components.

Comments (7)

ssieb avatar ssieb commented on July 24, 2024

In order to see setup messages, you have to watch the serial logs over USB.

from esphome_components.

MichaKersloot avatar MichaKersloot commented on July 24, 2024

Ah, yes, that works. I also found out the battery level only updates on a device reset.

from esphome_components.

MichaKersloot avatar MichaKersloot commented on July 24, 2024

As the battery level only updated on a device reset, I've changed the component from Component to PollingComponent. The diffs:

ip5306.h

@@ -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;

ip5306.cpp

@@ -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) {
@@ -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);
   }
   if (this->read_register(IP5306_REG_READ0, data, 2) != i2c::ERROR_OK) {
     ESP_LOGE(TAG, "unable to read status");

from esphome_components.

landonr avatar landonr commented on July 24, 2024

what device are you using? I think my m5stack fire gets battery level updates with the current implementation but I'll check to be sure

from esphome_components.

MichaKersloot avatar MichaKersloot commented on July 24, 2024

Hi, I've activated the ip5306 on my T-Journal as stated in https://discord.com/channels/429907082951524364/951213660905287761/1061049798402265228 . It looks like
the removed if statement is not doing what you expect? I suspect it only publishes the state on the first run to create it and never runs again. To me it also seems better to use the PollingComponent instead of Component to limit the updates to a reasonable rate.

from esphome_components.

ssieb avatar ssieb commented on July 24, 2024

I don't see what that PR fixes. The current code will update when the battery level changes. If that's not working, then polling is not going to work either since it's still the same code.

from esphome_components.

MichaKersloot avatar MichaKersloot commented on July 24, 2024

The code only publishes on a device reset. Or maybe when the battery level changes, i've not seen this happening. This means when Homeassistant restarts there is no value reported and it's shown as NA. So changing it to a PollinComponent that reports the current value on polling fixes this. Both changes work together.

from esphome_components.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.