Fix energy consumers history sometimes not loading when a filter is set

This commit is contained in:
Michael Zanetti 2022-10-19 23:04:22 +02:00
parent 5f3783e970
commit a1f25f3a2a
5 changed files with 33 additions and 6 deletions

View File

@ -200,6 +200,11 @@ EnergyLogEntry *EnergyLogs::find(const QDateTime &timestamp)
return m_list.at(index);
}
QList<EnergyLogEntry *> EnergyLogs::entries() const
{
return m_list;
}
void EnergyLogs::appendEntry(EnergyLogEntry *entry, double minValue, double maxValue)
{
entry->setParent(this);

View File

@ -86,6 +86,7 @@ public:
Q_INVOKABLE EnergyLogEntry* get(int index) const;
Q_INVOKABLE EnergyLogEntry* find(const QDateTime &timestamp);
Q_INVOKABLE QList<EnergyLogEntry*> entries() const;
public slots:
void clear();

View File

@ -282,7 +282,9 @@ void ThingPowerLogsLoader::addThingId(const QUuid &thingId)
void ThingPowerLogsLoader::fetchLogs()
{
qCDebug(dcEnergyLogs()) << "dafuq!";
if (!m_engine || m_engine->jsonRpcClient()->experiences().value("Energy").toString() < "1.0") {
qCDebug(dcEnergyLogs()) << "Not fetching logs" << m_engine;
return;
}
@ -335,8 +337,9 @@ void ThingPowerLogsLoader::fetchLogs()
}
m_fetchingData = true;
fetchingDataChanged();
emit fetchingDataChanged();
qCDebug(dcEnergyLogs()) << "Fetching logs";
m_engine->jsonRpcClient()->sendCommand("Energy.GetThingPowerLogs", params, this, "getLogsResponse");
}

View File

@ -152,7 +152,7 @@ StatsBase {
barSet.borderWith = 0
}
Component.onDestruction: {
barSeries.remove(barset)
barSeries.remove(barSet)
}
}
}

View File

@ -89,6 +89,17 @@ Item {
}
return timestamp
}
function update() {
if (!engine.thingManager.fetchingData && !engine.tagsManager.busy && consumersRepeater.count == consumers.count) {
logsLoader.fetchLogs();
}
}
}
Connections {
target: engine.tagsManager
onBusyChanged: d.update()
}
Component {
@ -138,7 +149,7 @@ Item {
onTabSelected: {
d.now = new Date()
powerBalanceLogs.fetchLogs()
logsLoader.fetchLogs();
d.update()
}
}
@ -327,9 +338,16 @@ Item {
id: consumersRepeater
model: consumers.count
Component.onCompleted: {
if (count != 0) {
d.update()
}
}
onCountChanged: {
print("***** count changed", count, "total:", consumers.count)
if (count == consumers.count) {
logsLoader.fetchLogs()
d.update();
}
}
@ -625,7 +643,7 @@ Item {
}
Repeater {
model: consumers
model: consumersRepeater.count
delegate: RowLayout {
id: consumerToolTipDelegate
Rectangle {
@ -640,7 +658,7 @@ Item {
property double rawValue: entry ? entry.currentPower : 0
property double displayValue: rawValue >= 1000 ? rawValue / 1000 : rawValue
property string unit: rawValue >= 1000 ? "kW" : "W"
text: "%1: %2 %3".arg(model.name).arg(displayValue.toFixed(2)).arg(unit)
text: "%1: %2 %3".arg(consumersRepeater.itemAt(index).thing.name).arg(displayValue.toFixed(2)).arg(unit)
font: Style.extraSmallFont
}
}