implement presencesensor in networkdetector

master
Michael Zanetti 2018-12-20 22:26:11 +01:00
parent 1345fe99ff
commit 9a3e32cced
5 changed files with 32 additions and 1 deletions

View File

@ -66,6 +66,7 @@ void DeviceMonitor::arpLookupFinished(int exitCode)
m_host->setReachable(true);
emit reachableChanged(true);
}
emit seen();
} else {
// 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();
@ -95,6 +96,7 @@ void DeviceMonitor::pingFinished(int exitCode)
m_host->setReachable(true);
emit reachableChanged(true);
}
emit seen();
} else {
qDebug(dcNetworkDetector()) << "Could not ping device" << m_host->macAddress() << m_host->address();
}

View File

@ -19,6 +19,7 @@ public:
signals:
void addressChanged(const QString &address);
void reachableChanged(bool reachable);
void seen();
private:
void lookupArpCache();

View File

@ -80,6 +80,7 @@ DeviceManager::DeviceSetupStatus DevicePluginNetworkDetector::setupDevice(Device
DeviceMonitor *monitor = new DeviceMonitor(device->paramValue(networkDeviceDeviceMacAddressParamTypeId).toString(), device->paramValue(networkDeviceDeviceAddressParamTypeId).toString(), this);
connect(monitor, &DeviceMonitor::reachableChanged, this, &DevicePluginNetworkDetector::deviceReachableChanged);
connect(monitor, &DeviceMonitor::addressChanged, this, &DevicePluginNetworkDetector::deviceAddressChanged);
connect(monitor, &DeviceMonitor::seen, this, &DevicePluginNetworkDetector::deviceSeen);
m_monitors.insert(monitor, device);
return DeviceManager::DeviceSetupStatusSuccess;
@ -144,6 +145,7 @@ void DevicePluginNetworkDetector::deviceReachableChanged(bool reachable)
if (device->stateValue(networkDeviceConnectedStateTypeId).toBool() != reachable) {
qCDebug(dcNetworkDetector()) << "Device" << device->paramValue(networkDeviceDeviceMacAddressParamTypeId).toString() << "reachable changed" << reachable;
device->setStateValue(networkDeviceConnectedStateTypeId, reachable);
device->setStateValue(networkDeviceIsPresentStateTypeId, reachable);
}
}
@ -155,3 +157,10 @@ void DevicePluginNetworkDetector::deviceAddressChanged(const QString &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());
}

View File

@ -57,6 +57,7 @@ private slots:
void deviceReachableChanged(bool reachable);
void deviceAddressChanged(const QString &address);
void deviceSeen();
void onPluginTimer();

View File

@ -17,7 +17,7 @@
"Device",
"Sensor"
],
"interfaces": ["connectable"],
"interfaces": [ "connectable", "presencesensor" ],
"primaryStateTypeId": "cb43e1b5-4f61-4538-bfa2-c33055c542cf",
"createMethods": ["user", "discovery"],
"paramTypes": [
@ -45,6 +45,24 @@
"type": "bool",
"defaultValue": 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
}
]
}