mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 02:02:51 +00:00
[openthread] add mesh_local_eid openthread_info sensor (#13924)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
co-authored by
Jonathan Swoboda
J. Nick Koston
J. Nick Koston
parent
9a35c5229b
commit
21804a75de
@@ -16,6 +16,7 @@ void Eui64OpenThreadInfo::dump_config() { LOG_TEXT_SENSOR("", "Eui64", this); }
|
||||
void NetworkNameOpenThreadInfo::dump_config() { LOG_TEXT_SENSOR("", "Network Name", this); }
|
||||
void NetworkKeyOpenThreadInfo::dump_config() { LOG_TEXT_SENSOR("", "Network Key", this); }
|
||||
void PanIdOpenThreadInfo::dump_config() { LOG_TEXT_SENSOR("", "PAN ID", this); }
|
||||
void MeshLocalEidOpenThreadInfo::dump_config() { LOG_TEXT_SENSOR("", "Mesh Local EID", this); }
|
||||
void ExtPanIdOpenThreadInfo::dump_config() { LOG_TEXT_SENSOR("", "Extended PAN ID", this); }
|
||||
|
||||
} // namespace esphome::openthread_info
|
||||
|
||||
@@ -134,6 +134,24 @@ class ChannelOpenThreadInfo final : public OpenThreadInstancePollingComponent, p
|
||||
uint8_t last_channel_;
|
||||
};
|
||||
|
||||
class MeshLocalEidOpenThreadInfo final : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
|
||||
public:
|
||||
void update_instance(otInstance *instance) override {
|
||||
const otIp6Address *addr = otThreadGetMeshLocalEid(instance);
|
||||
if (otIp6IsAddressEqual(addr, &this->last_addr_)) {
|
||||
return;
|
||||
}
|
||||
this->last_addr_ = *addr;
|
||||
char buf[OT_IP6_ADDRESS_STRING_SIZE];
|
||||
otIp6AddressToString(addr, buf, sizeof(buf));
|
||||
this->publish_state(buf);
|
||||
}
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
otIp6Address last_addr_{};
|
||||
};
|
||||
|
||||
class DatasetOpenThreadInfo : public OpenThreadInstancePollingComponent {
|
||||
public:
|
||||
void update_instance(otInstance *instance) override {
|
||||
|
||||
@@ -14,6 +14,7 @@ from esphome.types import ConfigType
|
||||
CONF_RLOC16 = "rloc16"
|
||||
CONF_EUI64 = "eui64"
|
||||
CONF_EXT_ADDR = "ext_addr"
|
||||
CONF_MESH_LOCAL_EID = "mesh_local_eid"
|
||||
|
||||
|
||||
DEPENDENCIES = ["openthread"]
|
||||
@@ -46,6 +47,9 @@ NetworkKeyOpenThreadInfo = openthread_info_ns.class_(
|
||||
PanIdOpenThreadInfo = openthread_info_ns.class_(
|
||||
"PanIdOpenThreadInfo", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
MeshLocalEidOpenThreadInfo = openthread_info_ns.class_(
|
||||
"MeshLocalEidOpenThreadInfo", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
ExtPanIdOpenThreadInfo = openthread_info_ns.class_(
|
||||
"ExtPanIdOpenThreadInfo", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
@@ -80,6 +84,9 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.Optional(CONF_PAN_ID): text_sensor.text_sensor_schema( # noqa: F821
|
||||
PanIdOpenThreadInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
|
||||
).extend(cv.polling_component_schema("1s")),
|
||||
cv.Optional(CONF_MESH_LOCAL_EID): text_sensor.text_sensor_schema(
|
||||
MeshLocalEidOpenThreadInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
|
||||
).extend(cv.polling_component_schema("1s")),
|
||||
cv.Optional(CONF_EXT_PAN_ID): text_sensor.text_sensor_schema(
|
||||
ExtPanIdOpenThreadInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
|
||||
).extend(cv.polling_component_schema("1s")),
|
||||
@@ -103,4 +110,5 @@ async def to_code(config: ConfigType) -> None:
|
||||
await setup_conf(config, CONF_NETWORK_NAME)
|
||||
await setup_conf(config, CONF_NETWORK_KEY)
|
||||
await setup_conf(config, CONF_PAN_ID)
|
||||
await setup_conf(config, CONF_MESH_LOCAL_EID)
|
||||
await setup_conf(config, CONF_EXT_PAN_ID)
|
||||
|
||||
@@ -26,6 +26,8 @@ text_sensor:
|
||||
name: "Network Key"
|
||||
pan_id:
|
||||
name: "PAN ID"
|
||||
mesh_local_eid:
|
||||
name: "Mesh Local EID"
|
||||
ext_pan_id:
|
||||
name: "Extended PAN ID"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user