Add Static Devices

This commit is contained in:
2020-05-01 11:39:46 +02:00
parent 157b1ceb51
commit 21dbdd41d9
12 changed files with 400 additions and 327 deletions
+26 -6
View File
@@ -8,7 +8,7 @@
namespace PresenceDetection {
namespace UniFi {
Device::Device(const std::string& hostname, int port, const std::string& username, const std::string& password, const std::string& cookieFile, int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::Device>& devices) :
Device::Device(const std::string& hostname, int port, const std::string& username, const std::string& password, const std::string& cookieFile, int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::StaticDevice>& staticDevices) :
m_loggedIn(false),
m_hostname(hostname),
m_port(port),
@@ -16,9 +16,10 @@ Device::Device(const std::string& hostname, int port, const std::string& usernam
m_password(password),
m_cookieFile(cookieFile),
m_timeout(timeout),
m_checkInterval(5),
m_inventoryURL(inventoryURL),
m_target(target),
m_staticDevices(devices)
m_staticDevices(staticDevices)
{
if (!m_inventoryURL.empty())
UpdateDevicesFromInventory();
@@ -33,7 +34,8 @@ Device::~Device()
void Device::Start()
{
m_deviceTimer.StartContinuous(5000, static_cast<std::function<void()>>(std::bind(&Device::UpdatePresentDevices, this)));
int checkInterval = m_checkInterval * 1000;
m_deviceTimer.StartContinuous(checkInterval, static_cast<std::function<void()>>(std::bind(&Device::UpdatePresentDevices, this)));
if (!m_inventoryURL.empty())
m_inventoryTimer.StartContinuous(300000, static_cast<std::function<void()>>(std::bind(&Device::UpdateDevicesFromInventory, this)));
}
@@ -129,7 +131,7 @@ void Device::ClearDevices()
}
}
for (std::vector<Util::Device>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
for (std::vector<Util::StaticDevice>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
{
if (it->HasWifiMac())
{
@@ -219,9 +221,18 @@ void Device::UpdatePresentDevices()
addedDevices.push_back(macAddress);
presentDevices.push_back(macAddress);
}
else
{
if (std::find(m_presentDevices.begin(), m_presentDevices.end(), macAddress) != m_presentDevices.end())
{
std::stringstream ss;
ss << "TimeOut (" << m_timeout << "): " << macAddress << std::endl;
Logging::Log(Logging::Severity::Debug, ss.str());
}
}
}
for (std::vector<Util::Device>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
for (std::vector<Util::StaticDevice>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
{
if ((timeStamp - lastSeen) < m_timeout)
{
@@ -232,6 +243,15 @@ void Device::UpdatePresentDevices()
presentDevices.push_back(macAddress);
}
}
else
{
if (std::find(m_presentDevices.begin(), m_presentDevices.end(), macAddress) != m_presentDevices.end())
{
std::stringstream ss;
ss << "TimeOut (" << m_timeout << "): " << macAddress << std::endl;
Logging::Log(Logging::Severity::Debug, ss.str());
}
}
}
}
}
@@ -286,7 +306,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
}
}
for (std::vector<Util::Device>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
for (std::vector<Util::StaticDevice>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
{
if (it->HasWifiMac() && it->WifiMac() == macAddress)
{