diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index f96de2f0bc..d22b3cd106 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -615,6 +615,10 @@ bool Mcp4461Component::set_eeprom_value(Mcp4461EepromLocation location, uint16_t return true; } +ErrorCode Mcp4461Component::get_error_code() { + return this->error_code_; +} + bool Mcp4461Component::is_writing_() { /* Read the EEPROM write-active status from the status register */ bool writing = static_cast((this->get_status_register_() >> 4) & 0x01); diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 547c60a61d..368da076d5 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -38,7 +38,7 @@ enum class Mcp4461Addresses : uint8_t { }; // @brief Class to enumerate allowed channels/wipers -enum Mcp4461WiperIdx : uint8_t { +enum class Mcp4461WiperIdx : uint8_t { MCP4461_WIPER_0 = 0, MCP4461_WIPER_1 = 1, MCP4461_WIPER_2 = 2, @@ -100,22 +100,8 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { /// @param[wiper] wiper for which terminal shall be initialized disabled /// @param[terminal] terminal to disable, one of { 'a', 'b', 'w', 'h' } void initialize_terminal_disabled(Mcp4461WiperIdx wiper, char terminal); - - /// @brief available/required status codes - enum ErrorCode { - MCP4461_STATUS_OK = 0, // CMD completed successfully - MCP4461_FAILED, // component failed - MCP4461_STATUS_I2C_ERROR, // Unable to communicate with device - MCP4461_STATUS_REGISTER_INVALID, // Status register value was invalid - MCP4461_STATUS_REGISTER_ERROR, // Error fetching status register - MCP4461_PROHIBITED_FOR_NONVOLATILE, // - MCP4461_VALUE_INVALID, // Invalid value given for wiper / eeprom - MCP4461_WRITE_PROTECTED, // The value was read, but the CRC over the payload (valid and data) does not match - MCP4461_WIPER_ENABLED, // The wiper is enabled, discard additional enabling actions - MCP4461_WIPER_DISABLED, // The wiper is disabled - all actions for this wiper will be aborted/discarded - MCP4461_WIPER_LOCKED, // The wiper is locked using WiperLock-technology - all actions for this wiper will be - // aborted/discarded - } error_code{MCP4461_STATUS_OK}; + /// @brief get error code + ErrorCode get_error_code(); protected: friend class Mcp4461Wiper; @@ -186,6 +172,22 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { /// @return bool - true if write successful, false if not bool set_terminal_register_(Mcp4461TerminalIdx terminal_connector, uint8_t data); + /// @brief available/required status codes + enum ErrorCode { + MCP4461_STATUS_OK = 0, // CMD completed successfully + MCP4461_FAILED, // component failed + MCP4461_STATUS_I2C_ERROR, // Unable to communicate with device + MCP4461_STATUS_REGISTER_INVALID, // Status register value was invalid + MCP4461_STATUS_REGISTER_ERROR, // Error fetching status register + MCP4461_PROHIBITED_FOR_NONVOLATILE, // + MCP4461_VALUE_INVALID, // Invalid value given for wiper / eeprom + MCP4461_WRITE_PROTECTED, // The value was read, but the CRC over the payload (valid and data) does not match + MCP4461_WIPER_ENABLED, // The wiper is enabled, discard additional enabling actions + MCP4461_WIPER_DISABLED, // The wiper is disabled - all actions for this wiper will be aborted/discarded + MCP4461_WIPER_LOCKED, // The wiper is locked using WiperLock-technology - all actions for this wiper will be + // aborted/discarded + } error_code_{MCP4461_STATUS_OK}; + WiperState reg_[8]; void begin_(); bool last_eeprom_write_timed_out_{false}; diff --git a/esphome/components/mcp4461/output/__init__.py b/esphome/components/mcp4461/output/__init__.py index 941645b9da..6fdd0ca07d 100644 --- a/esphome/components/mcp4461/output/__init__.py +++ b/esphome/components/mcp4461/output/__init__.py @@ -10,7 +10,7 @@ Mcp4461Wiper = mcp4461_ns.class_( "Mcp4461Wiper", output.FloatOutput, cg.Parented.template(Mcp4461Component) ) -Mcp4461WiperIdx = mcp4461_ns.enum("Mcp4461WiperIdx") +Mcp4461WiperIdx = mcp4461_ns.enum("Mcp4461WiperIdx", is_class=True) CHANNEL_OPTIONS = { "A": Mcp4461WiperIdx.MCP4461_WIPER_0, "B": Mcp4461WiperIdx.MCP4461_WIPER_1,