added connected state to all one wire devices

master
bernhard.trinnes 2020-08-19 21:17:43 +02:00
parent a2bb2ccf10
commit bb28d3417e
5 changed files with 54 additions and 4 deletions

View File

@ -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));
}
}
}

View File

@ -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",

View File

@ -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);

View File

@ -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();
}

View File

@ -44,6 +44,7 @@ public:
QStringList discoverDevices();
bool interfaceIsAvailable();
bool deviceAvailable(const QString &address);
double getTemperature(const QString &address);
private: