wildekek / rdtech-esphome

Add Home Assistant support to your RDTech power supply
MIT License
33 stars 7 forks source link

Simplify binary sensor states #7

Closed wildekek closed 1 year ago

wildekek commented 1 year ago
          https://github.com/wildekek/riden-esphome/blob/main/rd6006-controller.yaml#L321-L326

This format can be replaced with just lambda: return id(protection_status).state == 1;

Originally posted by @ShayBox in https://github.com/wildekek/riden-esphome/issues/5#issuecomment-1698852593

wildekek commented 1 year ago

@ShayBox: I don't think this helps with readability. The protection_status represents an enumerated state, not a binary state. So it would not work for the over current protection state. What is the problem you're trying to solve here?

ShayBox commented 1 year ago

id(protection_status).state is an enumerated state, but once you add the condition == 2 it becomes a binary state expression. Instead of checking if the boolean expression and returning true for true and false for false you can just return the expression. It just simplifies the code.

EDIT: For the one you linked it would be lambda: return id(protection_status).state == 2;

wildekek commented 1 year ago

Indeed I get it, thanks! What I think makes it even more simple is to specify the enumerated states and publish them inside the protection_status sensor. I'll work on that an push a fix.

wildekek commented 1 year ago

I used bitmasking to get the binary sensor states, cleanest solution imo.