-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
17 changed files
with
219 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import esphome.codegen as cg | ||
from esphome.components import button | ||
import esphome.config_validation as cv | ||
from esphome.const import CONF_ICON, CONF_ID | ||
|
||
from .. import CONF_JBD_BMS_ID, JBD_BMS_COMPONENT_SCHEMA, jbd_bms_ns | ||
|
||
DEPENDENCIES = ["jbd_bms"] | ||
|
||
CODEOWNERS = ["@syssi"] | ||
|
||
CONF_RETRIEVE_HARDWARE_VERSION = "retrieve_hardware_version" | ||
|
||
ICON_CONF_RETRIEVE_HARDWARE_VERSION = "mdi:numeric" | ||
|
||
BUTTONS = { | ||
CONF_RETRIEVE_HARDWARE_VERSION: 0x05, | ||
} | ||
|
||
JbdButton = jbd_bms_ns.class_("JbdButton", button.Button, cg.Component) | ||
|
||
CONFIG_SCHEMA = JBD_BMS_COMPONENT_SCHEMA.extend( | ||
{ | ||
cv.Optional(CONF_RETRIEVE_HARDWARE_VERSION): button.BUTTON_SCHEMA.extend( | ||
{ | ||
cv.GenerateID(): cv.declare_id(JbdButton), | ||
cv.Optional( | ||
CONF_ICON, default=ICON_CONF_RETRIEVE_HARDWARE_VERSION | ||
): cv.icon, | ||
} | ||
).extend(cv.COMPONENT_SCHEMA), | ||
} | ||
) | ||
|
||
|
||
async def to_code(config): | ||
hub = await cg.get_variable(config[CONF_JBD_BMS_ID]) | ||
for key, address in BUTTONS.items(): | ||
if key in config: | ||
conf = config[key] | ||
var = cg.new_Pvariable(conf[CONF_ID]) | ||
await cg.register_component(var, conf) | ||
await button.register_button(var, conf) | ||
cg.add(var.set_parent(hub)) | ||
cg.add(var.set_holding_register(address)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "jbd_button.h" | ||
#include "esphome/core/log.h" | ||
#include "esphome/core/application.h" | ||
|
||
namespace esphome { | ||
namespace jbd_bms { | ||
|
||
static const char *const TAG = "jbd_bms.button"; | ||
|
||
static const uint8_t JBD_CMD_READ = 0xA5; | ||
|
||
void JbdButton::dump_config() { LOG_BUTTON("", "JbdBms Button", this); } | ||
void JbdButton::press_action() { this->parent_->send_command(JBD_CMD_READ, this->holding_register_); } | ||
|
||
} // namespace jbd_bms | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include "../jbd_bms.h" | ||
#include "esphome/core/component.h" | ||
#include "esphome/components/button/button.h" | ||
|
||
namespace esphome { | ||
namespace jbd_bms { | ||
|
||
class JbdBms; | ||
class JbdButton : public button::Button, public Component { | ||
public: | ||
void set_parent(JbdBms *parent) { this->parent_ = parent; }; | ||
void set_holding_register(uint8_t holding_register) { this->holding_register_ = holding_register; }; | ||
void dump_config() override; | ||
void loop() override {} | ||
float get_setup_priority() const override { return setup_priority::DATA; } | ||
|
||
protected: | ||
void press_action() override; | ||
JbdBms *parent_; | ||
uint8_t holding_register_; | ||
}; | ||
|
||
} // namespace jbd_bms | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import esphome.codegen as cg | ||
from esphome.components import button | ||
import esphome.config_validation as cv | ||
from esphome.const import CONF_ICON, CONF_ID | ||
|
||
from .. import CONF_JBD_BMS_BLE_ID, JBD_BMS_BLE_COMPONENT_SCHEMA, jbd_bms_ble_ns | ||
|
||
DEPENDENCIES = ["jbd_bms_ble"] | ||
|
||
CODEOWNERS = ["@syssi"] | ||
|
||
CONF_RETRIEVE_HARDWARE_VERSION = "retrieve_hardware_version" | ||
|
||
ICON_CONF_RETRIEVE_HARDWARE_VERSION = "mdi:numeric" | ||
|
||
BUTTONS = { | ||
CONF_RETRIEVE_HARDWARE_VERSION: 0x05, | ||
} | ||
|
||
JbdButton = jbd_bms_ble_ns.class_("JbdButton", button.Button, cg.Component) | ||
|
||
CONFIG_SCHEMA = JBD_BMS_BLE_COMPONENT_SCHEMA.extend( | ||
{ | ||
cv.Optional(CONF_RETRIEVE_HARDWARE_VERSION): button.BUTTON_SCHEMA.extend( | ||
{ | ||
cv.GenerateID(): cv.declare_id(JbdButton), | ||
cv.Optional( | ||
CONF_ICON, default=ICON_CONF_RETRIEVE_HARDWARE_VERSION | ||
): cv.icon, | ||
} | ||
).extend(cv.COMPONENT_SCHEMA), | ||
} | ||
) | ||
|
||
|
||
async def to_code(config): | ||
hub = await cg.get_variable(config[CONF_JBD_BMS_BLE_ID]) | ||
for key, address in BUTTONS.items(): | ||
if key in config: | ||
conf = config[key] | ||
var = cg.new_Pvariable(conf[CONF_ID]) | ||
await cg.register_component(var, conf) | ||
await button.register_button(var, conf) | ||
cg.add(var.set_parent(hub)) | ||
cg.add(var.set_holding_register(address)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "jbd_button.h" | ||
#include "esphome/core/log.h" | ||
#include "esphome/core/application.h" | ||
|
||
namespace esphome { | ||
namespace jbd_bms_ble { | ||
|
||
static const char *const TAG = "jbd_bms_ble.button"; | ||
|
||
static const uint8_t JBD_CMD_READ = 0xA5; | ||
|
||
void JbdButton::dump_config() { LOG_BUTTON("", "JbdBmsBle Button", this); } | ||
void JbdButton::press_action() { this->parent_->send_command(JBD_CMD_READ, this->holding_register_); } | ||
|
||
} // namespace jbd_bms_ble | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include "../jbd_bms_ble.h" | ||
#include "esphome/core/component.h" | ||
#include "esphome/components/button/button.h" | ||
|
||
namespace esphome { | ||
namespace jbd_bms_ble { | ||
|
||
class JbdBmsBle; | ||
class JbdButton : public button::Button, public Component { | ||
public: | ||
void set_parent(JbdBmsBle *parent) { this->parent_ = parent; }; | ||
void set_holding_register(uint8_t holding_register) { this->holding_register_ = holding_register; }; | ||
void dump_config() override; | ||
void loop() override {} | ||
float get_setup_priority() const override { return setup_priority::DATA; } | ||
|
||
protected: | ||
void press_action() override; | ||
JbdBmsBle *parent_; | ||
uint8_t holding_register_; | ||
}; | ||
|
||
} // namespace jbd_bms_ble | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters