diff --git a/onewire/integrationpluginonewire.cpp b/onewire/integrationpluginonewire.cpp index a423bde2..958ebe12 100644 --- a/onewire/integrationpluginonewire.cpp +++ b/onewire/integrationpluginonewire.cpp @@ -312,23 +312,29 @@ void IntegrationPluginOneWire::onPluginTimer() if (thing->thingClassId() == temperatureSensorThingClassId) { QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray(); double temperature = 0; + bool connected = false; if (m_owfsInterface) { temperature = m_owfsInterface->getTemperature(address); + connected = m_owfsInterface->isConnected(address); } else if (m_w1Interface) { temperature = m_w1Interface->getTemperature(address); + connected = m_w1Interface->deviceAvailable(address); } thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); + thing->setStateValue(temperatureSensorConnectedStateTypeId, connected); } if (thing->thingClassId() == singleChannelSwitchThingClassId) { QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); + thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } if (thing->thingClassId() == dualChannelSwitchThingClassId) { QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); + thing->setStateValue(dualChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } if (thing->thingClassId() == eightChannelSwitchThingClassId) { @@ -341,6 +347,7 @@ void IntegrationPluginOneWire::onPluginTimer() thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F)); thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G)); thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H)); + thing->setStateValue(eightChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } } } diff --git a/onewire/integrationpluginonewire.json b/onewire/integrationpluginonewire.json index 834091c7..f4979797 100644 --- a/onewire/integrationpluginonewire.json +++ b/onewire/integrationpluginonewire.json @@ -68,6 +68,14 @@ } ], "stateTypes": [ + { + "id": "32305a16-b042-4574-8bd7-ad99d9e8e5da", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "b04ee2a5-9b27-4ffc-9e12-7e05f5a41690", "name": "temperature", @@ -102,7 +110,15 @@ "readOnly": true } ], - "stateTypes": [ + "stateTypes": [ + { + "id": "16bae8e8-bfe1-4648-9018-f6ce610f4236", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40", "name": "digitalOutput", @@ -139,6 +155,14 @@ } ], "stateTypes": [ + { + "id": "fb6e63db-316b-4959-a349-0ff58a679f71", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "f8b6b4a7-355c-4580-a676-8a4d0d619ff9", "name": "digitalOutput1", @@ -186,6 +210,14 @@ } ], "stateTypes": [ + { + "id": "b99585e0-5147-46e3-9474-fba555bac68a", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "78fa12c0-246c-4112-8be6-5943d3c3cda5", "name": "digitalOutput1", diff --git a/onewire/owfs.cpp b/onewire/owfs.cpp index 739f82bb..701fedac 100644 --- a/onewire/owfs.cpp +++ b/onewire/owfs.cpp @@ -111,11 +111,16 @@ bool Owfs::discoverDevices() bool Owfs::interfaceIsAvailable() { return true; + //TODO + //QByteArray fullPath; + //fullPath.append(m_path); + //if(OW_present(fullPath) < 0) + // return false; + //return true; } bool Owfs::isConnected(const QByteArray &address) { - Q_UNUSED(address) QByteArray fullPath; fullPath.append(m_path); fullPath.append(address); diff --git a/onewire/w1.cpp b/onewire/w1.cpp index 1d93d991..34ea7c11 100644 --- a/onewire/w1.cpp +++ b/onewire/w1.cpp @@ -66,12 +66,17 @@ bool W1::interfaceIsAvailable() return w1SysFSDir.exists(); } +bool W1::deviceAvailable(const QString &address) +{ + QDir temperatureSensor("/sys/bus/w1/devices/"+address); + return temperatureSensor.exists(); +} + double W1::getTemperature(const QString &address) { QDir temperatureSensor("/sys/bus/w1/devices/"+address); if (temperatureSensor.exists()) { - qCDebug(dcOneWire()) << "Temperature" << address; - QFile temperature(temperatureSensor.dirName()+"/temperature"); + QFile temperature(temperatureSensor.path() +"/temperature"); if (!temperature.exists()) { qCWarning(dcOneWire()) << "Directory doesn't exist" << temperature.fileName(); } diff --git a/onewire/w1.h b/onewire/w1.h index 2d009784..597eb307 100644 --- a/onewire/w1.h +++ b/onewire/w1.h @@ -44,6 +44,7 @@ public: QStringList discoverDevices(); bool interfaceIsAvailable(); + bool deviceAvailable(const QString &address); double getTemperature(const QString &address); private: