implement presencesensor in networkdetector
parent
1345fe99ff
commit
9a3e32cced
|
|
@ -66,6 +66,7 @@ void DeviceMonitor::arpLookupFinished(int exitCode)
|
||||||
m_host->setReachable(true);
|
m_host->setReachable(true);
|
||||||
emit reachableChanged(true);
|
emit reachableChanged(true);
|
||||||
}
|
}
|
||||||
|
emit seen();
|
||||||
} else {
|
} else {
|
||||||
// ARP claims the device to be stale... try to ping it.
|
// ARP claims the device to be stale... try to ping it.
|
||||||
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "found in ARP cache but is marked as" << parts.last() << ". Trying to ping it on" << m_host->address();
|
qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "found in ARP cache but is marked as" << parts.last() << ". Trying to ping it on" << m_host->address();
|
||||||
|
|
@ -95,6 +96,7 @@ void DeviceMonitor::pingFinished(int exitCode)
|
||||||
m_host->setReachable(true);
|
m_host->setReachable(true);
|
||||||
emit reachableChanged(true);
|
emit reachableChanged(true);
|
||||||
}
|
}
|
||||||
|
emit seen();
|
||||||
} else {
|
} else {
|
||||||
qDebug(dcNetworkDetector()) << "Could not ping device" << m_host->macAddress() << m_host->address();
|
qDebug(dcNetworkDetector()) << "Could not ping device" << m_host->macAddress() << m_host->address();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void addressChanged(const QString &address);
|
void addressChanged(const QString &address);
|
||||||
void reachableChanged(bool reachable);
|
void reachableChanged(bool reachable);
|
||||||
|
void seen();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void lookupArpCache();
|
void lookupArpCache();
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ DeviceManager::DeviceSetupStatus DevicePluginNetworkDetector::setupDevice(Device
|
||||||
DeviceMonitor *monitor = new DeviceMonitor(device->paramValue(networkDeviceDeviceMacAddressParamTypeId).toString(), device->paramValue(networkDeviceDeviceAddressParamTypeId).toString(), this);
|
DeviceMonitor *monitor = new DeviceMonitor(device->paramValue(networkDeviceDeviceMacAddressParamTypeId).toString(), device->paramValue(networkDeviceDeviceAddressParamTypeId).toString(), this);
|
||||||
connect(monitor, &DeviceMonitor::reachableChanged, this, &DevicePluginNetworkDetector::deviceReachableChanged);
|
connect(monitor, &DeviceMonitor::reachableChanged, this, &DevicePluginNetworkDetector::deviceReachableChanged);
|
||||||
connect(monitor, &DeviceMonitor::addressChanged, this, &DevicePluginNetworkDetector::deviceAddressChanged);
|
connect(monitor, &DeviceMonitor::addressChanged, this, &DevicePluginNetworkDetector::deviceAddressChanged);
|
||||||
|
connect(monitor, &DeviceMonitor::seen, this, &DevicePluginNetworkDetector::deviceSeen);
|
||||||
m_monitors.insert(monitor, device);
|
m_monitors.insert(monitor, device);
|
||||||
|
|
||||||
return DeviceManager::DeviceSetupStatusSuccess;
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
|
|
@ -144,6 +145,7 @@ void DevicePluginNetworkDetector::deviceReachableChanged(bool reachable)
|
||||||
if (device->stateValue(networkDeviceConnectedStateTypeId).toBool() != reachable) {
|
if (device->stateValue(networkDeviceConnectedStateTypeId).toBool() != reachable) {
|
||||||
qCDebug(dcNetworkDetector()) << "Device" << device->paramValue(networkDeviceDeviceMacAddressParamTypeId).toString() << "reachable changed" << reachable;
|
qCDebug(dcNetworkDetector()) << "Device" << device->paramValue(networkDeviceDeviceMacAddressParamTypeId).toString() << "reachable changed" << reachable;
|
||||||
device->setStateValue(networkDeviceConnectedStateTypeId, reachable);
|
device->setStateValue(networkDeviceConnectedStateTypeId, reachable);
|
||||||
|
device->setStateValue(networkDeviceIsPresentStateTypeId, reachable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,3 +157,10 @@ void DevicePluginNetworkDetector::deviceAddressChanged(const QString &address)
|
||||||
device->setParamValue(networkDeviceDeviceAddressParamTypeId.toString(), address);
|
device->setParamValue(networkDeviceDeviceAddressParamTypeId.toString(), address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DevicePluginNetworkDetector::deviceSeen()
|
||||||
|
{
|
||||||
|
DeviceMonitor *monitor = static_cast<DeviceMonitor*>(sender());
|
||||||
|
Device *device = m_monitors.value(monitor);
|
||||||
|
device->setStateValue(networkDeviceLastSeenTimeStateTypeId, QDateTime::currentDateTime().toTime_t());
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ private slots:
|
||||||
|
|
||||||
void deviceReachableChanged(bool reachable);
|
void deviceReachableChanged(bool reachable);
|
||||||
void deviceAddressChanged(const QString &address);
|
void deviceAddressChanged(const QString &address);
|
||||||
|
void deviceSeen();
|
||||||
|
|
||||||
void onPluginTimer();
|
void onPluginTimer();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
"Device",
|
"Device",
|
||||||
"Sensor"
|
"Sensor"
|
||||||
],
|
],
|
||||||
"interfaces": ["connectable"],
|
"interfaces": [ "connectable", "presencesensor" ],
|
||||||
"primaryStateTypeId": "cb43e1b5-4f61-4538-bfa2-c33055c542cf",
|
"primaryStateTypeId": "cb43e1b5-4f61-4538-bfa2-c33055c542cf",
|
||||||
"createMethods": ["user", "discovery"],
|
"createMethods": ["user", "discovery"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
|
|
@ -45,6 +45,24 @@
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false,
|
"defaultValue": false,
|
||||||
"cached": false
|
"cached": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "0a38651c-418d-42b3-80f5-6e7adb6a25fc",
|
||||||
|
"name": "isPresent",
|
||||||
|
"displayName": "Device is present",
|
||||||
|
"displayNameEvent": "Device is present changed",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": false,
|
||||||
|
"cached": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b51d54c9-cce1-43f0-a35d-52fc2d8d302c",
|
||||||
|
"name": "lastSeenTime",
|
||||||
|
"displayName": "Last seen time",
|
||||||
|
"displayNameEvent": "Last seen time changed",
|
||||||
|
"type": "int",
|
||||||
|
"unit": "UnixTime",
|
||||||
|
"defaultValue": 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue