fixed typos
This commit is contained in:
parent
1eb94bea51
commit
c02c10938a
@ -42,9 +42,9 @@ void DevicePluginUniPi::init()
|
||||
|
||||
DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
|
||||
{
|
||||
if (device->deviceClassId() == neuronDeviceClassId) {
|
||||
if (m_webSocket == NULL) {
|
||||
|
||||
int port = device->paramValue(neuronPortParamTypeId).toInt();
|
||||
int port = device->paramValue(uniPiPortParamTypeId).toInt();
|
||||
|
||||
m_webSocket = new QWebSocket();
|
||||
connect(m_webSocket, &QWebSocket::connected, this, &DevicePluginUniPi::onWebSocketConnected);
|
||||
@ -54,49 +54,149 @@ DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
|
||||
url.setPort(port);
|
||||
qCDebug(dcUniPi()) << "Conneting to:" << url.toString();
|
||||
m_webSocket->open(url);
|
||||
m_parentId = device->id();
|
||||
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == relayOutputDeviceClassId) {
|
||||
|
||||
device->setName(QString("Relay Ouput %1").arg(device->paramValue(relayOutputRelayNumberParamTypeId).toString()));
|
||||
device->setParentId(device->paramValue(relayOutputParentIdParamTypeId).toString());
|
||||
m_usedGpios.insert(device->paramValue(relayOutputRelayNumberParamTypeId).toString(), device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == digitalOutputDeviceClassId) {
|
||||
|
||||
device->setName(QString("Digital Output %1").arg(device->paramValue(digitalOutputDigitalOutputNumberParamTypeId).toString()));
|
||||
device->setParentId(device->paramValue(digitalOutputParentIdParamTypeId).toString());
|
||||
m_usedGpios.insert(device->paramValue(digitalOutputDigitalOutputNumberParamTypeId).toString(), device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == digitalInputDeviceClassId) {
|
||||
|
||||
device->setName(QString("Digital Input %1").arg(device->paramValue(digitalInputDigitalInputNumberParamTypeId).toString()));
|
||||
device->setParentId(device->paramValue(digitalInputParentIdParamTypeId).toString());
|
||||
m_usedGpios.insert(device->paramValue(digitalInputDigitalInputNumberParamTypeId).toString(), device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == analogInputDeviceClassId) {
|
||||
|
||||
device->setName(QString("Analog Input %1").arg(device->paramValue(analogInputAnalogInputNumberParamTypeId).toString()));
|
||||
device->setParentId(device->paramValue(analogInputParentIdParamTypeId).toString());
|
||||
m_usedGpios.insert(device->paramValue(analogInputAnalogInputNumberParamTypeId).toString(), device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == analogOutputDeviceClassId) {
|
||||
|
||||
device->setName(QString("Analog Output %1").arg(device->paramValue(analogOutputAnalogOutputNumberParamTypeId).toString()));
|
||||
device->setParentId(device->paramValue(analogOutputParentIdParamTypeId).toString());
|
||||
m_usedGpios.insert(device->paramValue(analogOutputAnalogOutputNumberParamTypeId).toString(), device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == shadingDeviceClassId) {
|
||||
|
||||
m_usedGpios.insert(device->paramValue(shadingOutputUpParamTypeId).toString(), device);
|
||||
m_usedGpios.insert(device->paramValue(shadingOutputDownParamTypeId).toString(), device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == lightDeviceClassId) {
|
||||
|
||||
m_usedGpios.insert(device->paramValue(relayOutputRelayNumberParamTypeId).toString(), device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
return DeviceManager::DeviceSetupStatusFailure;
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
Q_UNUSED(params);
|
||||
|
||||
const DeviceClass deviceClass = deviceManager()->findDeviceClass(deviceClassId);
|
||||
if (deviceClass.vendorId() == unipiVendorId) {
|
||||
|
||||
if (deviceClassId == relayOutputDeviceClassId) {
|
||||
|
||||
// Create the list of available gpios
|
||||
QList<DeviceDescriptor> deviceDescriptors;
|
||||
|
||||
for (int i = 0; i < m_relais.count(); i++) {
|
||||
const QString circuit = m_relais.at(i);
|
||||
|
||||
// Offer only gpios which arn't in use already
|
||||
if (m_usedGpios.contains(circuit)){
|
||||
continue;
|
||||
}
|
||||
|
||||
DeviceDescriptor descriptor(deviceClassId, QString("Relay %1").arg(circuit), circuit);
|
||||
ParamList parameters;
|
||||
parameters.append(Param(relayOutputRelayNumberParamTypeId, circuit));
|
||||
|
||||
descriptor.setParams(parameters);
|
||||
deviceDescriptors.append(descriptor);
|
||||
}
|
||||
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
if (deviceClassId == digitalOutputDeviceClassId) {
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
if (deviceClassId == digitalInputDeviceClassId) {
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
if (deviceClassId == analogInputDeviceClassId) {
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
if (deviceClassId == analogOutputDeviceClassId) {
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
if (deviceClassId == shadingDeviceClassId) {
|
||||
// Create the list of available gpios
|
||||
QList<DeviceDescriptor> deviceDescriptors;
|
||||
|
||||
for (int i = 0; i < m_relais.count(); i++) {
|
||||
const QString circuit = m_relais.at(i);
|
||||
|
||||
// Offer only gpios which aren't in use already
|
||||
if (m_usedGpios.contains(circuit)){
|
||||
continue;
|
||||
}
|
||||
|
||||
DeviceDescriptor descriptor(deviceClassId, QString("Up Relay %1 + Down Relay %2").arg(circuit, m_relais.at(i+1)), circuit);
|
||||
ParamList parameters;
|
||||
parameters.append(Param(shadingOutputUpParamTypeId, circuit));
|
||||
parameters.append(Param(shadingOutputDownParamTypeId, m_relais.at(i+1)));
|
||||
parameters.append(Param(shadingOutputTypeUpParamTypeId, GPIOType::relay));
|
||||
parameters.append(Param(shadingOutputTypeDownParamTypeId, GPIOType::relay));
|
||||
descriptor.setParams(parameters);
|
||||
deviceDescriptors.append(descriptor);
|
||||
}
|
||||
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
if (deviceClassId == lightDeviceClassId) {
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
}
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
void DevicePluginUniPi::setOutput(const QString &circuit, const QString &type, bool value)
|
||||
{
|
||||
QJsonObject json;
|
||||
json["cmd"] = "set";
|
||||
json["dev"] = type;
|
||||
json["circuit"] = circuit;
|
||||
json["value"] = value;
|
||||
|
||||
QJsonDocument doc(json);
|
||||
QByteArray bytes = doc.toJson(QJsonDocument::Compact);
|
||||
qCDebug(dcUniPi()) << "Send command" << bytes;
|
||||
m_webSocket->sendBinaryMessage(bytes);
|
||||
}
|
||||
|
||||
void DevicePluginUniPi::postSetupDevice(Device *device)
|
||||
{
|
||||
Q_UNUSED(device);
|
||||
@ -104,10 +204,12 @@ void DevicePluginUniPi::postSetupDevice(Device *device)
|
||||
|
||||
void DevicePluginUniPi::deviceRemoved(Device *device)
|
||||
{
|
||||
Q_UNUSED(device);
|
||||
m_usedGpios.remove(m_usedGpios.key(device)); //TODO remove multible IOs associated to a single device
|
||||
|
||||
m_webSocket->close();
|
||||
m_webSocket->deleteLater();
|
||||
if (myDevices().isEmpty()) {
|
||||
m_webSocket->close();
|
||||
m_webSocket->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, const Action &action)
|
||||
@ -117,7 +219,7 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
|
||||
|
||||
if (action.actionTypeId() == relayOutputRelayStatusActionTypeId) {
|
||||
QString relayNumber = device->paramValue(relayOutputRelayNumberParamTypeId).toString();
|
||||
int stateValue = action.param(relayOutputRelayStatusStateParamTypeId).value().toInt();
|
||||
int stateValue = action.param(relayOutputRelayStatusActionParamTypeId).value().toInt();
|
||||
|
||||
QJsonObject json;
|
||||
json["cmd"] = "set";
|
||||
@ -138,7 +240,7 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
|
||||
if (device->deviceClassId() == digitalOutputDeviceClassId) {
|
||||
if (action.actionTypeId() == digitalOutputDigitalOutputStatusActionTypeId) {
|
||||
int digitalOutputNumber = device->paramValue(digitalOutputDigitalOutputNumberParamTypeId).toInt();
|
||||
int stateValue = action.param(digitalOutputDigitalOutputStatusStateParamTypeId).value().toInt();
|
||||
int stateValue = action.param(digitalOutputDigitalOutputStatusActionParamTypeId).value().toInt();
|
||||
|
||||
QJsonObject json;
|
||||
json["cmd"] = "set";
|
||||
@ -158,7 +260,7 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
|
||||
|
||||
if (action.actionTypeId() == analogOutputAnalogOutputValueActionTypeId) {
|
||||
int analogOutputNumber = device->paramValue(analogOutputAnalogOutputNumberParamTypeId).toInt();
|
||||
double analogValue = device->paramValue(analogOutputAnalogOutputValueStateParamTypeId).toDouble();
|
||||
double analogValue = action.param(analogOutputAnalogOutputValueActionParamTypeId).value().toDouble();
|
||||
|
||||
QJsonObject json;
|
||||
json["cmd"] = "set";
|
||||
@ -173,74 +275,38 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == shadingDeviceClassId) {
|
||||
|
||||
if (action.actionTypeId() == shadingDownActionTypeId) {
|
||||
QString circuit = device->paramValue(shadingOutputDownParamTypeId).toString();
|
||||
QString type = device->paramValue(shadingOutputTypeDownParamTypeId).toString();
|
||||
setOutput(circuit, type, false);
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
if (action.actionTypeId() == shadingUpActionTypeId) {
|
||||
QString circuit = device->paramValue(shadingOutputDownParamTypeId).toString();
|
||||
QString type = device->paramValue(shadingOutputTypeDownParamTypeId).toString();
|
||||
setOutput(circuit, type, false);
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
if (action.actionTypeId() == shadingStopActionTypeId) {
|
||||
QString circuitUp = device->paramValue(shadingOutputDownParamTypeId).toString();
|
||||
QString typeUp = device->paramValue(shadingOutputTypeDownParamTypeId).toString();
|
||||
setOutput(circuitUp, typeUp, false);
|
||||
|
||||
QString circuitDown = device->paramValue(shadingOutputDownParamTypeId).toString();
|
||||
QString typeDown = device->paramValue(shadingOutputTypeDownParamTypeId).toString();
|
||||
setOutput(circuitDown, typeDown, false);
|
||||
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
void DevicePluginUniPi::createAutoDevice(GPIOType gpioType, DeviceId parentDeviceId, QString deviceName)
|
||||
{
|
||||
ParamList params;
|
||||
|
||||
switch(gpioType){
|
||||
case relay : {
|
||||
QList<DeviceDescriptor> relayOutputDescriptors;
|
||||
DeviceDescriptor descriptor(relayOutputDeviceClassId, "Relay Output", deviceName);
|
||||
params.append(Param(relayOutputRelayNumberParamTypeId, deviceName));
|
||||
params.append(Param(relayOutputParentIdParamTypeId, parentDeviceId));
|
||||
descriptor.setParams(params);
|
||||
relayOutputDescriptors.append(descriptor);
|
||||
emit autoDevicesAppeared(relayOutputDeviceClassId, relayOutputDescriptors);
|
||||
break;
|
||||
}
|
||||
|
||||
case digitalOutput : {
|
||||
QList<DeviceDescriptor> digitalOutputDescriptors;
|
||||
DeviceDescriptor descriptor(digitalOutputDeviceClassId, "Digital Output", deviceName);
|
||||
params.append(Param(digitalOutputDigitalOutputNumberParamTypeId, deviceName));
|
||||
params.append(Param(digitalOutputParentIdParamTypeId, parentDeviceId));
|
||||
descriptor.setParams(params);
|
||||
digitalOutputDescriptors.append(descriptor);
|
||||
emit autoDevicesAppeared(digitalOutputDeviceClassId, digitalOutputDescriptors);
|
||||
break;
|
||||
}
|
||||
|
||||
case digitalInput: {
|
||||
QList<DeviceDescriptor> digitalInputDescriptors;
|
||||
DeviceDescriptor descriptor(digitalInputDeviceClassId, "Digital Input", deviceName);
|
||||
params.append(Param(digitalInputDigitalInputNumberParamTypeId, deviceName));
|
||||
params.append(Param(digitalInputParentIdParamTypeId, parentDeviceId));
|
||||
descriptor.setParams(params);
|
||||
digitalInputDescriptors.append(descriptor);
|
||||
emit autoDevicesAppeared(digitalInputDeviceClassId, digitalInputDescriptors);
|
||||
break;
|
||||
}
|
||||
|
||||
case analogOutput: {
|
||||
QList<DeviceDescriptor> analogOutputDescriptors;
|
||||
DeviceDescriptor descriptor(analogOutputDeviceClassId, "Analog Output", deviceName);
|
||||
params.append(Param(analogOutputAnalogOutputNumberParamTypeId, deviceName));
|
||||
params.append(Param(analogOutputParentIdParamTypeId, parentDeviceId));
|
||||
descriptor.setParams(params);
|
||||
analogOutputDescriptors.append(descriptor);
|
||||
emit autoDevicesAppeared(analogOutputDeviceClassId, analogOutputDescriptors);
|
||||
break;
|
||||
}
|
||||
|
||||
case analogInput: {
|
||||
QList<DeviceDescriptor> analogInputDescriptors;
|
||||
DeviceDescriptor descriptor(analogInputDeviceClassId, "Analog Input", deviceName);
|
||||
params.append(Param(analogInputAnalogInputNumberParamTypeId, deviceName));
|
||||
params.append(Param(analogInputParentIdParamTypeId, parentDeviceId));
|
||||
descriptor.setParams(params);
|
||||
analogInputDescriptors.append(descriptor);
|
||||
emit autoDevicesAppeared(analogInputDeviceClassId, analogInputDescriptors);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DevicePluginUniPi::onWebSocketConnected()
|
||||
{
|
||||
@ -290,106 +356,133 @@ void DevicePluginUniPi::onWebSocketTextMessageReceived(QString message)
|
||||
if (obj["cmd"] == "all") {
|
||||
//read model number
|
||||
qCDebug(dcUniPi()) << message;
|
||||
|
||||
}
|
||||
|
||||
if (obj["dev"] == "relay") {
|
||||
qCDebug(dcUniPi()) << "Relay:" << obj["dev"].toString() << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toInt();
|
||||
|
||||
bool newDevice = true;
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == relayOutputDeviceClassId) {
|
||||
if (obj["circuit"] == device->paramValue(relayOutputRelayNumberParamTypeId).toString()) {
|
||||
device->setStateValue(relayOutputRelayStatusStateTypeId, QVariant(obj["value"].toInt()).toBool());
|
||||
newDevice = false;
|
||||
break;
|
||||
QString circuit = obj["circuit"].toString();
|
||||
bool value = QVariant(obj["value"].toInt()).toBool();
|
||||
|
||||
if (!m_relais.contains(circuit)) {
|
||||
//New Device detected
|
||||
m_relais.append(circuit);
|
||||
} else {
|
||||
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == relayOutputDeviceClassId) {
|
||||
if (circuit == device->paramValue(relayOutputRelayNumberParamTypeId).toString()) {
|
||||
device->setStateValue(relayOutputRelayStatusStateTypeId, value);
|
||||
break;
|
||||
}
|
||||
} else if (device->deviceClassId() == shadingDeviceClassId) {
|
||||
if (circuit == device->paramValue(shadingOutputUpParamTypeId).toString()) {
|
||||
if (value && device->stateValue(shadingStatusStateTypeId).toString().contains("stop")) {
|
||||
device->setStateValue(shadingStatusStateTypeId, "up");
|
||||
} else if (!value && device->stateValue(shadingStatusStateTypeId).toString().contains("up")) {
|
||||
device->setStateValue(shadingStatusStateTypeId, "stop");
|
||||
} else {
|
||||
qWarning(dcUniPi()) << "Shading" << device << "Output Up:" << value << "Status: " << device->stateValue(shadingStatusStateTypeId).toString();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
if (circuit == device->paramValue(shadingOutputDownParamTypeId).toString()) {
|
||||
if (value && device->stateValue(shadingStatusStateTypeId).toString().contains("stop")) {
|
||||
device->setStateValue(shadingStatusStateTypeId, "down");
|
||||
} else if (!value && device->stateValue(shadingStatusStateTypeId).toString().contains("down")) {
|
||||
device->setStateValue(shadingStatusStateTypeId, "stop");
|
||||
} else {
|
||||
qWarning(dcUniPi()) << "Shading" << device << "Output Down:" << value << "Status: " << device->stateValue(shadingStatusStateTypeId).toString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (device->deviceClassId() == lightDeviceClassId) {
|
||||
if (circuit == device->paramValue(lightOutputParamTypeId).toString()) {
|
||||
device->setStateValue(lightStatusStateTypeId, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newDevice) {
|
||||
qCDebug(dcUniPi()) << "New Device detected";
|
||||
createAutoDevice(GPIOType::relay, m_parentId, obj["circuit"].toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (obj["dev"] == "input") {
|
||||
qCDebug(dcUniPi()) << "Input:" << obj["dev"].toString() << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toInt();
|
||||
|
||||
bool newDevice = true;
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == digitalInputDeviceClassId) {
|
||||
if (obj["circuit"] == device->paramValue(digitalInputDigitalInputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(digitalInputDigitalInputStatusStateTypeId, QVariant(obj["value"].toInt()).toBool());
|
||||
newDevice = false;
|
||||
break;
|
||||
if (!m_digitalInputs.contains(obj["circuit"].toString())){
|
||||
//New Device detected
|
||||
m_digitalInputs.append(obj["circuit"].toString());
|
||||
} else {
|
||||
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == digitalInputDeviceClassId) {
|
||||
if (obj["circuit"] == device->paramValue(digitalInputDigitalInputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(digitalInputDigitalInputStatusStateTypeId, QVariant(obj["value"].toInt()).toBool());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newDevice){
|
||||
//New Device detected
|
||||
createAutoDevice(GPIOType::digitalInput, m_parentId, obj["circuit"].toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (obj["dev"] == "output") {
|
||||
qCDebug(dcUniPi()) << "Output:" << obj["dev"].toString() << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toInt();
|
||||
|
||||
bool newDevice = true;
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == digitalOutputDeviceClassId) {
|
||||
if (!m_digitalOutputs.contains(obj["circuit"].toString())){
|
||||
//New Device detected
|
||||
m_digitalOutputs.append(obj["circuit"].toString());
|
||||
} else {
|
||||
|
||||
if (obj["circuit"] == device->paramValue(digitalOutputDigitalOutputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(digitalOutputDigitalOutputStatusStateTypeId, QVariant(obj["value"].toInt()).toBool());
|
||||
newDevice = false;
|
||||
break;
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == digitalOutputDeviceClassId) {
|
||||
|
||||
if (obj["circuit"] == device->paramValue(digitalOutputDigitalOutputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(digitalOutputDigitalOutputStatusStateTypeId, QVariant(obj["value"].toInt()).toBool());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newDevice){
|
||||
//New Device detected
|
||||
createAutoDevice(GPIOType::digitalOutput, m_parentId, obj["circuit"].toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (obj["dev"] == "ao") {
|
||||
qCDebug(dcUniPi()) << "Analog Output:" << obj["dev"] << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toDouble();
|
||||
if (obj["dev"] == "ao") {
|
||||
qCDebug(dcUniPi()) << "Analog Output:" << obj["dev"] << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toDouble();
|
||||
|
||||
bool newDevice = true;
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == analogOutputDeviceClassId) {
|
||||
if (!m_analogOutputs.contains(obj["circuit"].toString())){
|
||||
//New Device detected
|
||||
m_analogOutputs.append(obj["circuit"].toString());
|
||||
|
||||
if (obj["circuit"] == device->paramValue(analogOutputAnalogOutputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(analogOutputAnalogOutputValueStateTypeId, obj["value"].toDouble());
|
||||
newDevice = false;
|
||||
break;
|
||||
} else {
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == analogOutputDeviceClassId) {
|
||||
if (obj["circuit"] == device->paramValue(analogOutputAnalogOutputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(analogOutputAnalogOutputValueStateTypeId, obj["value"].toDouble());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newDevice){
|
||||
//New Device detected
|
||||
createAutoDevice(GPIOType::analogOutput, m_parentId, obj["circuit"].toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (obj["dev"] == "ai") {
|
||||
qCDebug(dcUniPi()) << "Analog Input:" << obj["dev"] << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toDouble();
|
||||
if (obj["dev"] == "ai") {
|
||||
qCDebug(dcUniPi()) << "Analog Input:" << obj["dev"] << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toDouble();
|
||||
|
||||
bool newDevice = true;
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == analogInputDeviceClassId) {
|
||||
if (!m_analogInputs.contains(obj["circuit"].toString())){
|
||||
//New Device detected
|
||||
m_analogInputs.append(obj["circuit"].toString());
|
||||
} else {
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->deviceClassId() == analogInputDeviceClassId) {
|
||||
|
||||
if (obj["circuit"] == device->paramValue(analogInputAnalogInputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(analogInputAnalogInputValueStateTypeId, obj["value"].toDouble());
|
||||
newDevice = false;
|
||||
break;
|
||||
if (obj["circuit"] == device->paramValue(analogInputAnalogInputNumberParamTypeId).toString()) {
|
||||
device->setStateValue(analogInputAnalogInputValueStateTypeId, obj["value"].toDouble());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newDevice){
|
||||
//New Device detected
|
||||
createAutoDevice(GPIOType::analogInput, m_parentId, obj["circuit"].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end for loop
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +45,8 @@ public:
|
||||
void postSetupDevice(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@ -56,10 +58,18 @@ private:
|
||||
analogOutput
|
||||
};
|
||||
|
||||
DeviceId m_parentId;
|
||||
QHash<QString, Device*> m_usedGpios;
|
||||
|
||||
QList<QString> m_relais;
|
||||
QList<QString> m_digitalOutputs;
|
||||
QList<QString> m_digitalInputs;
|
||||
QList<QString> m_analogOutputs;
|
||||
QList<QString> m_analogInputs;
|
||||
QList<QString> m_temperatureSensors;
|
||||
|
||||
QWebSocket *m_webSocket = nullptr;
|
||||
|
||||
void createAutoDevice(GPIOType gpioType, DeviceId parentDeviceId, QString deviceName);
|
||||
void setOutput(const QString &circuit, const QString &type, bool value);
|
||||
|
||||
private slots:
|
||||
void onWebSocketConnected();
|
||||
|
||||
@ -1,39 +1,28 @@
|
||||
{
|
||||
"displayName": "Uni pi",
|
||||
"displayName": "UniPi",
|
||||
"name": "UniPi",
|
||||
"id": "26cba644-35ae-40a6-9c48-924198893a5f",
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "5329655d-7e91-4b16-9abf-2abc82bf1b3c",
|
||||
"name": "port",
|
||||
"displayName": "Port",
|
||||
"type": "int",
|
||||
"defaultValue": "8080"
|
||||
}
|
||||
],
|
||||
"vendors": [
|
||||
{
|
||||
"displayName": "UniPi",
|
||||
"name": "unipi",
|
||||
"id": "c82bfe27-d14d-40bd-b12f-ddba214b5fc5",
|
||||
"deviceClasses": [
|
||||
{
|
||||
"id": "f1663756-657d-4dbd-9568-e2edf513589f",
|
||||
"name": "neuron",
|
||||
"displayName": "Neuron",
|
||||
"deviceIcon": "Gateway",
|
||||
"createMethods": ["user"],
|
||||
"interface": [ ],
|
||||
"basicTags": ["Device", "Gateway"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "5329655d-7e91-4b16-9abf-2abc82bf1b3c",
|
||||
"name": "port",
|
||||
"displayName": "Port",
|
||||
"type": "int",
|
||||
"defaultValue": "8080"
|
||||
}
|
||||
],
|
||||
"actionTypes": [ ],
|
||||
"stateTypes": [ ]
|
||||
},
|
||||
{
|
||||
"id": "58f9db7f-fd33-45af-8c98-047b67ae5267",
|
||||
"name": "relayOutput",
|
||||
"displayName": "Relay output",
|
||||
"deviceIcon": "Power",
|
||||
"createMethods": ["auto"],
|
||||
"createMethods": ["discover"],
|
||||
"interface": [ ],
|
||||
"basicTags": ["Device"],
|
||||
"paramTypes": [
|
||||
@ -42,12 +31,6 @@
|
||||
"name": "relayNumber",
|
||||
"displayName": "Relay number",
|
||||
"type": "QString"
|
||||
},
|
||||
{
|
||||
"id": "84d4474b-86b4-4da1-8776-61d587cb9d0f",
|
||||
"name": "parentId",
|
||||
"displayName": "Parent ID",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
@ -68,20 +51,14 @@
|
||||
"name": "digitalInput",
|
||||
"displayName": "Digital input",
|
||||
"deviceIcon": "Switch",
|
||||
"createMethods": ["auto"],
|
||||
"createMethods": ["discover"],
|
||||
"interface": [ ],
|
||||
"basicTags": ["Sensor"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "9c84d9b8-fdc7-41c1-9559-08f061ffc7a6",
|
||||
"name": "digitalInputNumber",
|
||||
"displayName": "input number",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"id": "ebbf4c9c-25a9-45c1-be72-cc01aaea959c",
|
||||
"name": "parentId",
|
||||
"displayName": "parent ID",
|
||||
"displayName": "Input number",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
@ -101,20 +78,14 @@
|
||||
"name": "digitalOutput",
|
||||
"displayName": "Digital output",
|
||||
"deviceIcon": "Power",
|
||||
"createMethods": ["auto"],
|
||||
"createMethods": ["discover"],
|
||||
"interface": [ ],
|
||||
"basicTags": ["Device"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "c01d5bde-de5d-42c5-b462-79745827875a",
|
||||
"name": "digitalOutputNumber",
|
||||
"displayName": "Input number",
|
||||
"type": "QString"
|
||||
},
|
||||
{
|
||||
"id": "c697d10d-28ba-4680-9db9-094d4af7c6da",
|
||||
"name": "parentId",
|
||||
"displayName": "Parent ID",
|
||||
"displayName": "Output number",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
@ -136,7 +107,7 @@
|
||||
"name": "analogOutput",
|
||||
"displayName": "Analog output",
|
||||
"deviceIcon": "Power",
|
||||
"createMethods": ["auto"],
|
||||
"createMethods": ["discover"],
|
||||
"interface": [ ],
|
||||
"basicTags": ["Device"],
|
||||
"paramTypes": [
|
||||
@ -145,12 +116,6 @@
|
||||
"name": "analogOutputNumber",
|
||||
"displayName": "Analog output number",
|
||||
"type": "QString"
|
||||
},
|
||||
{
|
||||
"id": "120ed3a4-bd76-4e86-b550-3b1f1daabfa2",
|
||||
"name": "parentId",
|
||||
"displayName": "Parent ID",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
@ -174,7 +139,7 @@
|
||||
"name": "analogInput",
|
||||
"displayName": "Analog Input",
|
||||
"deviceIcon": "Power",
|
||||
"createMethods": ["auto"],
|
||||
"createMethods": ["discover"],
|
||||
"interface": [ ],
|
||||
"basicTags": ["Sensor"],
|
||||
"paramTypes": [
|
||||
@ -183,12 +148,6 @@
|
||||
"name": "analogInputNumber",
|
||||
"displayName": "Analog input number",
|
||||
"type": "QString"
|
||||
},
|
||||
{
|
||||
"id": "a4688cb3-54fa-478c-a108-d48cbb3d10e1",
|
||||
"name": "parentId",
|
||||
"displayName": "Parent ID",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
@ -202,6 +161,113 @@
|
||||
"defaultValue": 0.00
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "eadddc99-ce7d-4169-a2f9-a829fa105ad2",
|
||||
"name": "shading",
|
||||
"displayName": "Shading",
|
||||
"deviceIcon": "Blinds",
|
||||
"createMethods": ["discover"],
|
||||
"interface": [ ],
|
||||
"basicTags": ["Actuator"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "7878ef4b-2395-4995-b17d-b69cb7d280e1",
|
||||
"name": "outputUp",
|
||||
"displayName": "Output Up",
|
||||
"type": "QString"
|
||||
},
|
||||
{
|
||||
"id": "4aa113d0-294b-403d-9dd1-ad0abe833176",
|
||||
"name": "outputDown",
|
||||
"displayName": "Output Down",
|
||||
"type": "QString"
|
||||
},
|
||||
{
|
||||
"id": "a030f030-4f26-4f33-aadf-ec3c3a5141a7",
|
||||
"name": "outputTypeUp",
|
||||
"displayName": "Output Type Up",
|
||||
"type": "QString",
|
||||
"readOnly": true
|
||||
},
|
||||
{
|
||||
"id": "fde509c5-8db1-411b-9e71-36997c39ee6b",
|
||||
"name": "outputTypeDown",
|
||||
"displayName": "Output Type Down",
|
||||
"type": "QString",
|
||||
"readOnly": true
|
||||
}
|
||||
],
|
||||
"stateTypes":[
|
||||
{
|
||||
"id": "b8955f33-780a-48a5-9c50-c1bccf09918f",
|
||||
"name": "status",
|
||||
"displayName": "Status",
|
||||
"type": "QString",
|
||||
"possibleValues":[
|
||||
"up",
|
||||
"stop",
|
||||
"down"
|
||||
],
|
||||
"defaultValue": "stop"
|
||||
}
|
||||
],
|
||||
"actionTypes":[
|
||||
{
|
||||
"id": "cc8a13ae-2a3d-440a-a127-962fb912e511",
|
||||
"name": "up",
|
||||
"displayName": "Up",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"id": "19bda8bb-1a78-4f2f-9927-ff543012462e",
|
||||
"name": "stop",
|
||||
"displayName": "Stop",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"id": "7dc32e36-6a5c-46e1-8507-d9283067ac21",
|
||||
"name": "down",
|
||||
"displayName": "Down",
|
||||
"type": "bool"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "34fc941e-3465-4618-acf6-dda9c7242e27",
|
||||
"name": "light",
|
||||
"displayName": "Light",
|
||||
"deviceIcon": "Light",
|
||||
"createMethods": ["discover"],
|
||||
"interface": [""],
|
||||
"basicTags": ["Actuator"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "e1375def-edd6-4886-8e87-73cf3ebc819d",
|
||||
"name": "output",
|
||||
"displayName": "Output",
|
||||
"type": "QString"
|
||||
},
|
||||
{
|
||||
"id": "5853de25-94c6-4f50-95cd-f1e3ef2ebc59",
|
||||
"name": "outputType",
|
||||
"displayName": "Output Type",
|
||||
"type": "QString",
|
||||
"readOnly": true
|
||||
}
|
||||
],
|
||||
"stateTypes":[
|
||||
{
|
||||
"id": "3d0d6abc-87b9-42af-820e-e3bc7bde1743",
|
||||
"name": "status",
|
||||
"displayName": "Light",
|
||||
"displayNameEvent": "Light power changed",
|
||||
"displayNameAction": "Set light power",
|
||||
"type": "bool",
|
||||
"defaultValue": false,
|
||||
"writable": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
30
unipi/iodescriptor.cpp
Normal file
30
unipi/iodescriptor.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017 Bernhard Trinnes <bernhard.trinnes@guh.io> *
|
||||
* Copyright (C) 2018 Simon Stürz <simon.stuerz@guh.io> *
|
||||
* *
|
||||
* This file is part of nymea. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "iodescriptor.h"
|
||||
|
||||
ioDescriptor::ioDescriptor(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
40
unipi/iodescriptor.h
Normal file
40
unipi/iodescriptor.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017 Bernhard Trinnes <bernhard.trinnes@guh.io> *
|
||||
* Copyright (C) 2018 Simon Stürz <simon.stuerz@guh.io> *
|
||||
* *
|
||||
* This file is part of nymea. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef IODESCRIPTOR_H
|
||||
#define IODESCRIPTOR_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class ioDescriptor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ioDescriptor(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // IODESCRIPTOR_H
|
||||
@ -4,8 +4,10 @@ TARGET = $$qtLibraryTarget(nymea_devicepluginunipi)
|
||||
|
||||
SOURCES += \
|
||||
devicepluginunipi.cpp \
|
||||
iodescriptor.cpp
|
||||
|
||||
HEADERS += \
|
||||
devicepluginunipi.h \
|
||||
iodescriptor.h
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user