Added system item support, support for RGBControlers with multiple item backends, and item settings widgets

This commit is contained in:
2020-05-05 22:29:43 +02:00
parent a761eb4317
commit 5fb9ca7cc0
56 changed files with 635 additions and 210 deletions

View File

@ -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);
}

View File

@ -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");

View File

@ -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);