added 1-Wire temperature sensor
This commit is contained in:
parent
6195535528
commit
4d6e564227
@ -115,6 +115,11 @@ DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
|
|||||||
return DeviceManager::DeviceSetupStatusSuccess;
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device->deviceClassId() == temperatureSensorDeviceClassId) {
|
||||||
|
|
||||||
|
m_usedTemperatureSensors.insert(device->paramValue(temperatureSensorDeviceAddressParamTypeId).toString(), device);
|
||||||
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
|
}
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,6 +352,27 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
|
|||||||
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deviceClassId == temperatureSensorDeviceClassId) {
|
||||||
|
// Create the list of available temperature sensor
|
||||||
|
QList<DeviceDescriptor> deviceDescriptors;
|
||||||
|
for (int i = 0; i < m_temperatureSensors.count(); i++) {
|
||||||
|
const QString circuit = m_temperatureSensors.at(i);
|
||||||
|
|
||||||
|
// Offer only temperature sensors which aren't in use already
|
||||||
|
if (m_usedTemperatureSensors.contains(circuit)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DeviceDescriptor descriptor(deviceClassId, QString("Temperature Sensor %1").arg(circuit), circuit);
|
||||||
|
ParamList parameters;
|
||||||
|
parameters.append(Param(temperatureSensorDeviceAddressParamTypeId, circuit));
|
||||||
|
parameters.append(Param(temperatureSensorDeviceTypeParamTypeId, circuit));
|
||||||
|
descriptor.setParams(parameters);
|
||||||
|
deviceDescriptors.append(descriptor);
|
||||||
|
}
|
||||||
|
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
||||||
|
return DeviceManager::DeviceErrorAsync;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
}
|
}
|
||||||
@ -420,8 +446,11 @@ void DevicePluginUniPi::deviceRemoved(Device *device)
|
|||||||
DimmerSwitch *dimmerSwitch = m_dimmerSwitches.key(device);
|
DimmerSwitch *dimmerSwitch = m_dimmerSwitches.key(device);
|
||||||
m_dimmerSwitches.remove(dimmerSwitch);
|
m_dimmerSwitches.remove(dimmerSwitch);
|
||||||
dimmerSwitch->deleteLater();
|
dimmerSwitch->deleteLater();
|
||||||
|
} else if (device->deviceClassId() == temperatureSensorDeviceClassId) {
|
||||||
|
m_usedTemperatureSensors.remove(device->paramValue(temperatureSensorDeviceAddressParamTypeId).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (myDevices().isEmpty()) {
|
if (myDevices().isEmpty()) {
|
||||||
m_webSocket->close();
|
m_webSocket->close();
|
||||||
m_webSocket->deleteLater();
|
m_webSocket->deleteLater();
|
||||||
@ -702,7 +731,7 @@ void DevicePluginUniPi::onWebSocketTextMessageReceived(QString message)
|
|||||||
} else {
|
} else {
|
||||||
if (m_usedAnalogOutputs.contains(obj["circuit"].toString())) {
|
if (m_usedAnalogOutputs.contains(obj["circuit"].toString())) {
|
||||||
double value = QVariant(obj["value"]).toDouble();
|
double value = QVariant(obj["value"]).toDouble();
|
||||||
Device *device = m_usedDigitalInputs.value(obj["circuit"].toString());
|
Device *device = m_usedAnalogOutputs.value(obj["circuit"].toString());
|
||||||
|
|
||||||
if (device->deviceClassId() == analogOutputDeviceClassId) {
|
if (device->deviceClassId() == analogOutputDeviceClassId) {
|
||||||
device->setStateValue(analogOutputOutputValueStateTypeId, value);
|
device->setStateValue(analogOutputOutputValueStateTypeId, value);
|
||||||
@ -720,7 +749,7 @@ void DevicePluginUniPi::onWebSocketTextMessageReceived(QString message)
|
|||||||
} else {
|
} else {
|
||||||
if (m_usedAnalogInputs.contains(obj["circuit"].toString())) {
|
if (m_usedAnalogInputs.contains(obj["circuit"].toString())) {
|
||||||
double value = QVariant(obj["value"]).toDouble();
|
double value = QVariant(obj["value"]).toDouble();
|
||||||
Device *device = m_usedDigitalInputs.value(obj["circuit"].toString());
|
Device *device = m_usedAnalogInputs.value(obj["circuit"].toString());
|
||||||
|
|
||||||
if (device->deviceClassId() == analogInputDeviceClassId) {
|
if (device->deviceClassId() == analogInputDeviceClassId) {
|
||||||
device->setStateValue(analogInputInputValueStateTypeId, value);
|
device->setStateValue(analogInputInputValueStateTypeId, value);
|
||||||
@ -728,6 +757,23 @@ void DevicePluginUniPi::onWebSocketTextMessageReceived(QString message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj["dev"] == "temp") {
|
||||||
|
qCDebug(dcUniPi()) << "Temperature Sensor:" << obj["typ"] << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toDouble();
|
||||||
|
if (!m_temperatureSensors.contains(obj["circuit"].toString())){
|
||||||
|
//New temperature sensor detected
|
||||||
|
m_temperatureSensors.append(obj["circuit"].toString());
|
||||||
|
} else {
|
||||||
|
if (m_usedTemperatureSensors.contains(obj["circuit"].toString())) {
|
||||||
|
double value = QVariant(obj["value"]).toDouble();
|
||||||
|
Device *device = m_usedTemperatureSensors.value(obj["circuit"].toString());
|
||||||
|
|
||||||
|
if (device->deviceClassId() == temperatureSensorDeviceClassId) {
|
||||||
|
device->setStateValue(temperatureSensorTemperatureStateTypeId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ private:
|
|||||||
QHash<QString, Device*> m_usedDigitalInputs;
|
QHash<QString, Device*> m_usedDigitalInputs;
|
||||||
QHash<QString, Device*> m_usedAnalogOutputs;
|
QHash<QString, Device*> m_usedAnalogOutputs;
|
||||||
QHash<QString, Device*> m_usedAnalogInputs;
|
QHash<QString, Device*> m_usedAnalogInputs;
|
||||||
QHash<QString, Device*> m_usedSensors;
|
QHash<QString, Device*> m_usedTemperatureSensors;
|
||||||
QHash<QString, Device*> m_usedLeds;
|
QHash<QString, Device*> m_usedLeds;
|
||||||
|
|
||||||
QHash<DimmerSwitch *, Device*> m_dimmerSwitches;
|
QHash<DimmerSwitch *, Device*> m_dimmerSwitches;
|
||||||
@ -74,7 +74,7 @@ private:
|
|||||||
QList<QString> m_digitalInputs;
|
QList<QString> m_digitalInputs;
|
||||||
QList<QString> m_analogOutputs;
|
QList<QString> m_analogOutputs;
|
||||||
QList<QString> m_analogInputs;
|
QList<QString> m_analogInputs;
|
||||||
QList<QString> m_sensors;
|
QList<QString> m_temperatureSensors;
|
||||||
QList<QString> m_leds;
|
QList<QString> m_leds;
|
||||||
|
|
||||||
QWebSocket *m_webSocket = nullptr;
|
QWebSocket *m_webSocket = nullptr;
|
||||||
|
|||||||
@ -319,6 +319,45 @@
|
|||||||
"writable": true
|
"writable": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4f0b3cfd-603a-47ec-9719-2db7eeae1143",
|
||||||
|
"name": "temperatureSensor",
|
||||||
|
"displayName": "Temperature sensor",
|
||||||
|
"deviceIcon": "Temperature",
|
||||||
|
"createMethods": ["discovery"],
|
||||||
|
"interfaces": ["temperaturesensor", "connectable"],
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "9dd8f7e9-a24c-4a67-82cd-1e25e911cf5d",
|
||||||
|
"name": "type",
|
||||||
|
"displayName": "Type",
|
||||||
|
"type": "QString"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4684cee2-674e-4aa4-823d-096bd49f18ee",
|
||||||
|
"name": "address",
|
||||||
|
"displayName": "Address",
|
||||||
|
"type": "QString"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateTypes":[
|
||||||
|
{
|
||||||
|
"id": "7641d379-b832-40fc-a29b-7d32bba79236",
|
||||||
|
"name": "connected",
|
||||||
|
"displayName": "Connected",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "7fd10e94-f11d-4084-8d03-414fd5592b6a",
|
||||||
|
"displayName": "Temperature",
|
||||||
|
"displayNameEvent": "Temperature changed",
|
||||||
|
"name": "temperature",
|
||||||
|
"type": "double",
|
||||||
|
"defaultValue": 0.00
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user