Skip to content

Commit

Permalink
Поддержка кластеров homed-zigbee
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheridan committed Sep 5, 2024
1 parent 80a8a70 commit e929c9a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ clean:
-rm -rf ${BUILD_DIR}/debug
-rm -rf ${BUILD_DIR}/release
-rm -rf log

run_debug: debug
reset && rm -f debug.log && ${BUILD_DIR}/debug/homed_exporter -c ./homed-exporter.json --verbose

run_release: release
reset && rm -f release.log && ${BUILD_DIR}/release/homed_exporter -c ./homed-exporter.json --verbose
7 changes: 4 additions & 3 deletions src/model/device/cdevice.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "model/device/cdevice.h"
#include "cdevice.h"
#include "st.h"
#include "model/metrics/cmetricname.h"
#include "defines/metrics.h"
Expand Down Expand Up @@ -120,7 +119,7 @@ void CDevice::updateStatus(const he::mqtt::CTopic *topic, const Json::Value &dat
void CDevice::updateExpose(const he::mqtt::CTopic *topic, const Json::Value &data)
{
HE_LOG_VERBOSE("Updating device " << m_name << " expose");
// HE_LOG_DBG(data.toStyledString());
HE_LOG_DBG("Expose: " << data.toStyledString());
for(const std::string &key : data.getMemberNames())
{
HE_LOG_DBG("Expose key: " << key);
Expand Down Expand Up @@ -210,14 +209,16 @@ void CDevice::updateFd(const he::mqtt::CTopic *topic, const Json::Value &data)

void CDevice::updateMain(const he::mqtt::CTopic *topic, const Json::Value &data, const std::vector<std::string> &keys)
{
// HE_LOG_DBG("json: " << data.toStyledString());
HE_LOG_VERBOSE("Updating device " << m_name << " " << topic->topic());
for(const std::string &key : keys)
{
if(key == "color") { continue; }
if(data[key].isObject() || data[key].isArray()) { continue; }
HE_LOG_DBG(topic->topic() << " key: " << key);
he::model::metrics::TMetricLabels labels = defaultLabels();
if(!topic->deviceEndpoint().empty()) { labels["endpoint"] = topic->deviceEndpoint(); }
if(!topic->deviceEndpoint().empty()) { labels["endpoint" ] = topic->deviceEndpoint(); }
if(!topic->instance ().empty()) { labels["homed_instance"] = topic->instance (); }
he::model::metrics::CMetricValue value = HE_ST.metrics().isExposeEnumeration(key) ? he::model::metrics::CMetricValue(HE_ST.metrics().exposeEnumerationIndex(key, data[key].asString())) : he::model::metrics::CMetricValue(data[key]);
std::string metricName = he::model::metrics::CMetricName::metricName(key, topic->topicType());
switch(HE_ST.metrics().type(metricName))
Expand Down
2 changes: 2 additions & 0 deletions src/model/device/cdevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void CDevices::update(const he::mqtt::CTopic *topic, const Json::Value &data)
for(const Json::Value &device : data)
{
std::string name = device["name"].asString();
HE_LOG_DBG("First device update: " << name);
if(mustIgnore(name)) { continue; }
if(!exists(name))
{
Expand All @@ -42,6 +43,7 @@ void CDevices::update(const he::mqtt::CTopic *topic, const Json::Value &data)
case he::mqtt::ETopic::tDevice:
{
if(topic->device().empty() || mustIgnore(topic->device(), topic->deviceEndpoint()) || !exists(topic->device())) { return; }
// HE_LOG_DBG("Can update")
get(topic->device())->update(topic, data);
} break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt/cpayload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool CPayload::parse(const std::string& payload)
HE_LOG_WRN("MQTT payload parse error: " << err);
return false;
}
// HE_LOG_DBG(m_root.toStyledString());
HE_LOG_DBG(m_root.toStyledString());
return true;
}

Expand Down
12 changes: 8 additions & 4 deletions src/mqtt/ctopic.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "mqtt/ctopic.h"
#include "st.h"

#include <sstream>
#include <iostream>
#include "ctopic.h"
// #include <tuple>
#include "st.h"

namespace he
{
Expand All @@ -15,6 +12,7 @@ CTopic::CTopic(const std::string &topic)
: m_root(HE_ST.config().mqttHomedTopic()),
m_topic(""),
m_service(""),
m_instance(""),
m_device(""),
m_deviceEndpoint("")
{
Expand All @@ -33,8 +31,14 @@ void CTopic::parseTopic(const std::string &topic)
std::getline(stream, root , '/');
std::getline(stream, m_topic , '/');
std::getline(stream, m_service , '/');
if(m_service == "zigbee")
{
std::getline(stream, m_instance , '/');
}
std::getline(stream, m_device , '/');
std::getline(stream, m_deviceEndpoint, '/');

HE_LOG_DBG(root << " | " << m_topic << " | " << m_service << " | " << m_instance << " | " << m_device << " | " << m_deviceEndpoint);
}

ETopic CTopic::mineTopicType()
Expand Down
2 changes: 2 additions & 0 deletions src/mqtt/ctopic.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ class CTopic
HE_SIMPLE_GETTER(std::string, root );
HE_SIMPLE_GETTER(std::string, topic );
HE_SIMPLE_GETTER(std::string, service );
HE_SIMPLE_GETTER(std::string, instance );
HE_SIMPLE_GETTER(std::string, device );
HE_SIMPLE_GETTER(std::string, deviceEndpoint);

private:
std::string m_root;
std::string m_topic;
std::string m_service;
std::string m_instance;
std::string m_device;
std::string m_deviceEndpoint;
ETopic m_topicType;
Expand Down
2 changes: 1 addition & 1 deletion src/st.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

#include "log.h"

#define HE_LOG_VERBOSE(_what) if(HE_ST.cmdLine().option<bool>("verbose")) { HE_LOG_NFO(_what) }
#define HE_LOG_VERBOSE(_what) if(HE_ST.cmdLine().option<bool>("verbose")) { HE_LOG(cout,verbose,_what) }

0 comments on commit e929c9a

Please sign in to comment.