Commit to allow debugging of setupThing
This commit is contained in:
parent
af93c6c9a0
commit
0dfb894fcb
@ -38,6 +38,8 @@ IntegrationPluginIdm::IntegrationPluginIdm()
|
|||||||
|
|
||||||
void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info)
|
void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info)
|
||||||
{
|
{
|
||||||
|
qCDebug(dcIdm()) << "discoverThings called";
|
||||||
|
|
||||||
if (info->thingClassId() == navigator2ThingClassId) {
|
if (info->thingClassId() == navigator2ThingClassId) {
|
||||||
// TODO Is a discovery method actually possible?
|
// TODO Is a discovery method actually possible?
|
||||||
// The plugin has a parameter for the IP address
|
// The plugin has a parameter for the IP address
|
||||||
@ -54,21 +56,40 @@ void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
|
|
||||||
void IntegrationPluginIdm::setupThing(ThingSetupInfo *info)
|
void IntegrationPluginIdm::setupThing(ThingSetupInfo *info)
|
||||||
{
|
{
|
||||||
|
qCDebug(dcIdm()) << "setupThing called";
|
||||||
|
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
|
|
||||||
if (thing->thingClassId() == navigator2ThingClassId) {
|
if (thing->thingClassId() == navigator2ThingClassId) {
|
||||||
QHostAddress hostAddress = QHostAddress(thing->paramValue(navigator2ThingIpAddressParamTypeId).toString());
|
QHostAddress hostAddress = QHostAddress(thing->paramValue(navigator2ThingIpAddressParamTypeId).toString());
|
||||||
|
|
||||||
if (hostAddress.isNull() == false) {
|
if (hostAddress.isNull() == false) {
|
||||||
|
QString msg = "User entered address: ";
|
||||||
|
msg += hostAddress.toString();
|
||||||
|
|
||||||
|
qCDebug(dcIdm()) << msg;
|
||||||
|
|
||||||
/* Check, if address is already in use for another device */
|
/* Check, if address is already in use for another device */
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (QHash<Thing *, Idm *>::iterator item=m_idmConnections.begin(); item != m_idmConnections.end(); item++) {
|
for (QHash<Thing *, Idm *>::iterator item=m_idmConnections.begin(); item != m_idmConnections.end(); item++) {
|
||||||
if (hostAddress.isEqual(item.value()->getIdmAddress()))
|
if (hostAddress.isEqual(item.value()->getIdmAddress())) {
|
||||||
|
msg = "Addr of thing: ";
|
||||||
|
msg += item.value()->getIdmAddress().toString();
|
||||||
|
qCDebug(dcIdm()) << msg;
|
||||||
|
|
||||||
|
qCDebug(dcIdm()) << "Address in use already";
|
||||||
found = true;
|
found = true;
|
||||||
|
} else {
|
||||||
|
msg = "Different addr of other thing: ";
|
||||||
|
msg += item.value()->getIdmAddress().toString();
|
||||||
|
qCDebug(dcIdm()) << msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found == false) {
|
if (found == false) {
|
||||||
|
qCDebug(dcIdm()) << "Creating Idm object";
|
||||||
|
|
||||||
/* Create new Idm object and store it in hash table */
|
/* Create new Idm object and store it in hash table */
|
||||||
Idm *idm = new Idm(hostAddress, this);
|
Idm *idm = new Idm(hostAddress, this);
|
||||||
m_idmConnections.insert(thing, idm);
|
m_idmConnections.insert(thing, idm);
|
||||||
@ -76,30 +97,41 @@ void IntegrationPluginIdm::setupThing(ThingSetupInfo *info)
|
|||||||
/* Store thing info in hash table */
|
/* Store thing info in hash table */
|
||||||
m_idmInfos.insert(thing, info);
|
m_idmInfos.insert(thing, info);
|
||||||
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
msg = "Added IDM heatpump with address ";
|
||||||
|
msg += hostAddress.toString();
|
||||||
|
|
||||||
|
info->thing()->setStateValue(navigator2ConnectedStateTypeId, true);
|
||||||
|
info->finish(Thing::ThingErrorNoError, msg.toStdString().c_str());
|
||||||
} else {
|
} else {
|
||||||
info->finish(Thing::ThingErrorThingInUse);
|
info->finish(Thing::ThingErrorThingInUse, "IP address already in use");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
info->finish(Thing::ThingErrorInvalidParameter, "No IP address given");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginIdm::postSetupThing(Thing *thing)
|
void IntegrationPluginIdm::postSetupThing(Thing *thing)
|
||||||
{
|
{
|
||||||
|
qCDebug(dcIdm()) << "postSetupThing called";
|
||||||
|
|
||||||
if (!m_refreshTimer) {
|
if (!m_refreshTimer) {
|
||||||
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
|
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
|
||||||
connect(m_refreshTimer, &PluginTimer::timeout, this, &IntegrationPluginIdm::onRefreshTimer);
|
connect(m_refreshTimer, &PluginTimer::timeout, this, &IntegrationPluginIdm::onRefreshTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thing->thingClassId() == navigator2ThingClassId) {
|
if (thing->thingClassId() == navigator2ThingClassId) {
|
||||||
|
qCDebug(dcIdm()) << "Thing id: " << thing->id();
|
||||||
Idm *idm = m_idmConnections.value(thing);
|
Idm *idm = m_idmConnections.value(thing);
|
||||||
|
|
||||||
connect(idm, &Idm::statusUpdated, this, &IntegrationPluginIdm::onStatusUpdated);
|
if (idm != nullptr) {
|
||||||
|
connect(idm, &Idm::statusUpdated, this, &IntegrationPluginIdm::onStatusUpdated);
|
||||||
|
|
||||||
qCDebug(dcIdm()) << "Thing set up, calling update";
|
qCDebug(dcIdm()) << "Thing set up, calling update";
|
||||||
update(thing);
|
update(thing);
|
||||||
|
|
||||||
thing->setStateValue(navigator2ConnectedStateTypeId, true);
|
thing->setStateValue(navigator2ConnectedStateTypeId, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +207,8 @@ void IntegrationPluginIdm::onStatusUpdated(IdmInfo *info)
|
|||||||
|
|
||||||
void IntegrationPluginIdm::onRefreshTimer()
|
void IntegrationPluginIdm::onRefreshTimer()
|
||||||
{
|
{
|
||||||
|
qCDebug(dcIdm()) << "onRefreshTimer called";
|
||||||
|
|
||||||
foreach (Thing *thing, myThings().filterByThingClassId(navigator2ThingClassId)) {
|
foreach (Thing *thing, myThings().filterByThingClassId(navigator2ThingClassId)) {
|
||||||
update(thing);
|
update(thing);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
"name": "navigator2",
|
"name": "navigator2",
|
||||||
"displayName": "Navigator 2.0",
|
"displayName": "Navigator 2.0",
|
||||||
"id": "1c95ac91-4eca-4cbf-b0f4-d60d35d069ed",
|
"id": "1c95ac91-4eca-4cbf-b0f4-d60d35d069ed",
|
||||||
"createMethods": ["User","Discovery"],
|
"createMethods": ["User"],
|
||||||
"interfaces": ["temperaturesensor", "connectable"],
|
"interfaces": ["temperaturesensor", "connectable"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user