Add more debug prints to script console when ThingState fails

This commit is contained in:
Michael Zanetti 2023-12-30 18:08:41 +01:00
parent a3be47b815
commit c716f57e9c

View File

@ -126,6 +126,7 @@ QVariant ScriptState::value() const
{ {
Thing* thing = m_thingManager->findConfiguredThing(ThingId(m_thingId)); Thing* thing = m_thingManager->findConfiguredThing(ThingId(m_thingId));
if (!thing) { if (!thing) {
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "No thing with Id" << m_thingId << "found.";
return QVariant(); return QVariant();
} }
StateTypeId stateTypeId = StateTypeId(m_stateTypeId); StateTypeId stateTypeId = StateTypeId(m_stateTypeId);
@ -146,13 +147,13 @@ void ScriptState::setValue(const QVariant &value)
Thing* thing = m_thingManager->findConfiguredThing(ThingId(m_thingId)); Thing* thing = m_thingManager->findConfiguredThing(ThingId(m_thingId));
if (!thing) { if (!thing) {
m_valueCache = value; m_valueCache = value;
qCDebug(dcScriptEngine()) << "No thing with id" << m_thingId << "found."; QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "No thing with Id" << m_thingId << "found.";
return; return;
} }
if (thing->setupStatus() != Thing::ThingSetupStatusComplete) { if (thing->setupStatus() != Thing::ThingSetupStatusComplete) {
m_valueCache = value; m_valueCache = value;
qCDebug(dcScriptEngine()) << "Thing is not ready yet..."; QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Thing" << thing->name() << "(" << m_thingId << ") is not ready yet";
return; return;
} }
@ -261,7 +262,7 @@ void ScriptState::connectToThing()
} }
Thing *thing = m_thingManager->findConfiguredThing(ThingId(m_thingId)); Thing *thing = m_thingManager->findConfiguredThing(ThingId(m_thingId));
if (!thing) { if (!thing) {
qCDebug(dcScriptEngine()) << "Can't find thing with id" << m_thingId << "(yet)"; QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "No thing with Id" << m_thingId << "found (yet - it may still appear).";
return; return;
} }
@ -270,12 +271,12 @@ void ScriptState::connectToThing()
setValue(m_valueCache); setValue(m_valueCache);
} }
} else { } else {
qCDebug(dcScriptEngine()) << "Thing setup for" << thing->name() << "not complete yet"; QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Setup for thing" << thing->name() << "(" << m_thingId << ") is not completed yet.";
} }
m_connection = connect(thing, &Thing::setupStatusChanged, this, [this, thing](){ m_connection = connect(thing, &Thing::setupStatusChanged, this, [this, thing](){
if (thing->setupStatus() == Thing::ThingSetupStatusComplete) { if (thing->setupStatus() == Thing::ThingSetupStatusComplete) {
qCDebug(dcScriptEngine()) << "Thing setup for" << thing->name() << "completed"; QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Setup for" << thing->name() << "(" << m_thingId << ") completed.";
if (!m_valueCache.isNull()) { if (!m_valueCache.isNull()) {
setValue(m_valueCache); setValue(m_valueCache);
} }