#include "systemitem.h"
#include <QProcess>

void SystemItem::enactValue(uint8_t value)
{
	QProcess::execute(value ? onCommand_ : offCommand_);
}

SystemItem::SystemItem(uint32_t itemIdIn, QString name, uint8_t value,  QObject *parent):
	Item(itemIdIn, name, value, parent)
{

}

SystemItem::SystemItem(const ItemData& itemData,  QObject *parent):
	Item(itemData, parent)
{

}

void SystemItem::setOnCommand(const QString& in)
{
	onCommand_ = in;
}

void SystemItem::setOffCommand(const QString& in)
{
	offCommand_ = in;
}

void SystemItem::store(QJsonObject& json)
{
	json["Type"] = "System";
	Item::store(json);
	json["OnCommand"] = onCommand_;
	json["OffCommand"] = offCommand_;
}
void SystemItem::load(const QJsonObject& json, const bool preserve)
{
	Item::load(json,preserve);
	onCommand_ = json["OnCommand"].toString("");
	offCommand_ = json["OffCommand"].toString("");
}
