Added system item support, support for RGBControlers with multiple item backends, and item settings widgets
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
OcupancySensorSource::OcupancySensorSource(QObject *parent, const QString& device, const QString& deviceMac): QObject (parent), deviceMac_(deviceMac), device_(device)
|
||||
{
|
||||
|
||||
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
|
||||
}
|
||||
|
||||
void OcupancySensorSource::sensorEvent(Sensor sensor)
|
||||
@ -15,13 +15,14 @@ void OcupancySensorSource::sensorEvent(Sensor sensor)
|
||||
if(sensor.type == Sensor::TYPE_DOOR && sensor.id == 1 && sensor.field != 0.0f)
|
||||
{
|
||||
if(occupied == false) stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, 1, "Occupancy"));
|
||||
QTimer::singleShot(600000, this, &OcupancySensorSource::Timeout);
|
||||
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
void OcupancySensorSource::Timeout()
|
||||
{
|
||||
int error = 0;
|
||||
qDebug()<<"testing for occupancy";
|
||||
std::vector<uint64_t> devices = ap::connectedDevices(device_.toLatin1().toStdString(), error);
|
||||
if(error == 0)
|
||||
{
|
||||
@ -32,16 +33,19 @@ void OcupancySensorSource::Timeout()
|
||||
if(mac.find(deviceMac_.toLatin1().toStdString()) != std::string::npos)
|
||||
{
|
||||
found = true;
|
||||
qDebug()<<"occupied";
|
||||
break;
|
||||
}
|
||||
}
|
||||
stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, found, "Occupancy"));
|
||||
occupied = found;
|
||||
}
|
||||
else
|
||||
{
|
||||
stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, true, "Occupancy"));
|
||||
qDebug()<<"occupancy sensor error";
|
||||
qDebug()<<"occupancy sensor error "<<error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OcupancySensorSource::store(QJsonObject &json)
|
||||
@ -54,5 +58,4 @@ void OcupancySensorSource::load(const QJsonObject &json)
|
||||
{
|
||||
device_ = json["Device"].toString("wlan0");
|
||||
deviceMac_ = json["MacAddres"].toString("60:BE:B5:25:8C:E0");
|
||||
QTimer::singleShot(600000, this, &OcupancySensorSource::Timeout);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ private:
|
||||
QString deviceMac_;
|
||||
QString device_;
|
||||
bool occupied = true;
|
||||
static constexpr unsigned timeoutMs = (15 * 60) * 1000;
|
||||
|
||||
public:
|
||||
explicit OcupancySensorSource(QObject *parent = nullptr, const QString& device = "wlan0", const QString& deviceMac = "60:BE:B5:25:8C:E0");
|
||||
|
@ -52,6 +52,11 @@ public:
|
||||
}
|
||||
else return Sensor(TYPE_DUMMY, 0, 0, "", true);
|
||||
}
|
||||
QString toString()
|
||||
{
|
||||
return QString("SENSOR TYPE: ")+QString::number(type)+" ID: "+QString::number(id)+" FIELD: "+
|
||||
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field);
|
||||
}
|
||||
inline void generateName()
|
||||
{
|
||||
if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
|
||||
|
Reference in New Issue
Block a user