INRO: Fix intial read after connection
Signed-off-by: Simon Stürz <simon.stuerz@nymea.io>master
parent
b52d1e99c1
commit
4041240902
|
|
@ -277,6 +277,8 @@ void IntegrationPluginInro::thingRemoved(Thing *thing)
|
||||||
connection->deleteLater();
|
connection->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_initReadRequired.remove(thing);
|
||||||
|
|
||||||
// Unregister related hardware resources
|
// Unregister related hardware resources
|
||||||
if (m_monitors.contains(thing))
|
if (m_monitors.contains(thing))
|
||||||
hardwareManager()->networkDeviceDiscovery()->unregisterMonitor(m_monitors.take(thing));
|
hardwareManager()->networkDeviceDiscovery()->unregisterMonitor(m_monitors.take(thing));
|
||||||
|
|
@ -325,13 +327,14 @@ void IntegrationPluginInro::setupConnection(ThingSetupInfo *info)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(connection, &Pantabox::initializationFinished, thing, [thing, connection](bool success){
|
connect(connection, &Pantabox::initializationFinished, thing, [this, thing, connection](bool success){
|
||||||
if (success) {
|
if (success) {
|
||||||
thing->setStateValue(pantaboxModbusTcpVersionStateTypeId, Pantabox::modbusVersionToString(connection->modbusTcpVersion()));
|
thing->setStateValue(pantaboxModbusTcpVersionStateTypeId, Pantabox::modbusVersionToString(connection->modbusTcpVersion()));
|
||||||
|
m_initReadRequired[thing] = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(connection, &Pantabox::updateFinished, thing, [thing, connection](){
|
connect(connection, &Pantabox::updateFinished, thing, [this, thing, connection](){
|
||||||
qCDebug(dcInro()) << "Update finished for" << thing;
|
qCDebug(dcInro()) << "Update finished for" << thing;
|
||||||
qCDebug(dcInro()) << connection;
|
qCDebug(dcInro()) << connection;
|
||||||
|
|
||||||
|
|
@ -381,6 +384,15 @@ void IntegrationPluginInro::setupConnection(ThingSetupInfo *info)
|
||||||
thing->setStateValue(pantaboxFirmwareVersionStateTypeId, connection->firmwareVersion());
|
thing->setStateValue(pantaboxFirmwareVersionStateTypeId, connection->firmwareVersion());
|
||||||
thing->setStateValue(pantaboxTotalEnergyConsumedStateTypeId, connection->absoluteEnergy() / 1000.0); // Wh
|
thing->setStateValue(pantaboxTotalEnergyConsumedStateTypeId, connection->absoluteEnergy() / 1000.0); // Wh
|
||||||
|
|
||||||
|
// Sync states only right after the connection
|
||||||
|
if (m_initReadRequired.value(thing, false)) {
|
||||||
|
qCDebug(dcInro()) << "Set initial charging current and charging enabled values.";
|
||||||
|
m_initReadRequired.remove(thing);
|
||||||
|
if (connection->maxChargingCurrent() > 0) {
|
||||||
|
thing->setStateValue(pantaboxMaxChargingCurrentStateTypeId, connection->maxChargingCurrent());
|
||||||
|
}
|
||||||
|
thing->setStateValue(pantaboxPowerStateTypeId, connection->chargingEnabled());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
m_connections.insert(thing, connection);
|
m_connections.insert(thing, connection);
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ private:
|
||||||
PluginTimer *m_refreshTimer = nullptr;
|
PluginTimer *m_refreshTimer = nullptr;
|
||||||
QHash<Thing *, Pantabox *> m_connections;
|
QHash<Thing *, Pantabox *> m_connections;
|
||||||
QHash<Thing *, NetworkDeviceMonitor *> m_monitors;
|
QHash<Thing *, NetworkDeviceMonitor *> m_monitors;
|
||||||
|
QHash<Thing *, bool> m_initReadRequired;
|
||||||
|
|
||||||
|
|
||||||
void setupConnection(ThingSetupInfo *info);
|
void setupConnection(ThingSetupInfo *info);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue