fixed w1 temperature sensor setup
This commit is contained in:
parent
df59d45e83
commit
eab94cda96
@ -143,26 +143,31 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info)
|
|||||||
} else if (thing->thingClassId() == temperatureSensorThingClassId) {
|
} else if (thing->thingClassId() == temperatureSensorThingClassId) {
|
||||||
|
|
||||||
qCDebug(dcOneWire) << "Setup one wire temperature sensor" << thing->params();
|
qCDebug(dcOneWire) << "Setup one wire temperature sensor" << thing->params();
|
||||||
QString address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray();
|
if (!thing->parentId().isNull()) {
|
||||||
if (myThings().findById(thing->parentId())->thingClassId() == oneWireInterfaceThingClassId) {
|
// If there is a parent then it is from an OWFS interface
|
||||||
if (m_owfsInterface) {
|
Thing *parentThing = myThings().findById(thing->parentId());
|
||||||
thing->setStateValue(temperatureSensorConnectedStateTypeId, m_owfsInterface->isConnected(address.toUtf8()));
|
if (!parentThing) {
|
||||||
thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address.toUtf8()));
|
qCWarning(dcOneWire()) << "Could not find parent thing for" << thing->name();
|
||||||
return info->finish(Thing::ThingErrorNoError);
|
}
|
||||||
|
if (parentThing->setupComplete()) {
|
||||||
|
setupOwfsTemperatureSensor(info);
|
||||||
} else {
|
} else {
|
||||||
//OWFS Interface is not yet initialized try a setup in 3 seconds
|
connect(parentThing, &Thing::setupStatusChanged, [info, this] {
|
||||||
QTimer::singleShot(3000, this, [this, info]{setupThing(info);});
|
setupOwfsTemperatureSensor(info);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!m_w1Interface) {
|
if (!m_w1Interface) {
|
||||||
m_w1Interface = new W1(this);
|
m_w1Interface = new W1(this);
|
||||||
}
|
}
|
||||||
if (m_w1Interface->interfaceIsAvailable()) {
|
if (m_w1Interface->interfaceIsAvailable()) {
|
||||||
|
QString address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toString();
|
||||||
thing->setStateValue(temperatureSensorConnectedStateTypeId, m_w1Interface->deviceAvailable(address));
|
thing->setStateValue(temperatureSensorConnectedStateTypeId, m_w1Interface->deviceAvailable(address));
|
||||||
thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_w1Interface->getTemperature(address));
|
thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_w1Interface->getTemperature(address));
|
||||||
return info->finish(Thing::ThingErrorNoError);
|
return info->finish(Thing::ThingErrorNoError);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcOneWire()) << "W1 interface is not available";
|
qCWarning(dcOneWire()) << "W1 interface is not available";
|
||||||
|
return info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,6 +308,20 @@ void IntegrationPluginOneWire::thingRemoved(Thing *thing)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginOneWire::setupOwfsTemperatureSensor(ThingSetupInfo *info)
|
||||||
|
{
|
||||||
|
Thing *thing = info->thing();
|
||||||
|
QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray();
|
||||||
|
if (m_owfsInterface) {
|
||||||
|
thing->setStateValue(temperatureSensorConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||||
|
thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address));
|
||||||
|
return info->finish(Thing::ThingErrorNoError);
|
||||||
|
} else {
|
||||||
|
qCWarning(dcOneWire()) << "OWFS interface is not available";
|
||||||
|
return info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void IntegrationPluginOneWire::onPluginTimer()
|
void IntegrationPluginOneWire::onPluginTimer()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user