ocupancy sensor now uses libnl to collect connected devices

fixed regulator saving values as int instead of double
This commit is contained in:
Carl Klemm 2020-02-13 19:22:14 +01:00
parent 772d21a982
commit b0b4a985e9
15 changed files with 93 additions and 44 deletions

View file

@ -1,4 +1,4 @@
#include "mainobject.h"
#include "mainobject.h"
MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent) :
QObject(parent),
@ -20,6 +20,8 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
QObject::connect(&globalSensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
sunSensorSource.run();
//connect item store
QObject::connect(&micro, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
QObject::connect(&micro, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
@ -30,6 +32,8 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
items.addItem(rgbItem);
items.addItem(auxItem);
Relay::setMicrocontroller(&micro);
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
if(master)connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
@ -60,6 +64,9 @@ void MainObject::store(QJsonObject &json)
items.store(json);
QJsonObject powerObject;
powerItem.store(powerObject);
QJsonObject ocupancyObject;
ocupancySensor.store(ocupancyObject);
json.insert("Ocupancy", ocupancyObject);
json.insert("Power", powerObject);
}
@ -71,8 +78,9 @@ void MainObject::load(const QJsonObject& json)
powerItem.removeAllActors();
items.addItem(rgbItem);
items.addItem(auxItem);
items.load(json, &micro);
items.load(json);
powerItem.load(json["Power"].toObject());
ocupancySensor.load(json["Ocupancy"].toObject());
qDebug()<<"aray size: "<<json.isEmpty();
if(json["Items"].toArray().size() >= 2)
{
@ -84,7 +92,7 @@ void MainObject::load(const QJsonObject& json)
void MainObject::recivedJson(const QJsonObject json)
{
if(master)storeJsonObjectToDisk(json, settingsPath);
if(master && !noSave)storeJsonObjectToDisk(json, settingsPath);
load(json);
}