Forráskód Böngészése

Added support for hwmons with their sensors in the device subdirectory

Malte Veerman 5 éve
szülő
commit
241acf3d63

+ 18 - 12
import/src/fan.cpp

@@ -37,13 +37,19 @@
 namespace Fancontrol
 {
 
-Fan::Fan(uint index, Hwmon *parent) : Sensor(parent, index, parent ? parent->name() + "/fan" + QString::number(index) : QString()),
+Fan::Fan(uint index, Hwmon *parent, bool device) :
+    Sensor(parent, index, QStringLiteral("fan"), device),
     m_rpmStream(new QTextStream),
     m_rpm(0)
 {
-    if (m_parent && parent && QDir(parent->path()).isReadable())
+    if (!parent)
+        return;
+
+    auto path = device ? parent->path() + "/device" : parent->path();
+
+    if (QDir(path).isReadable())
     {
-        const auto rpmFile = new QFile(parent->path() + "/fan" + QString::number(index) + "_input", this);
+        const auto rpmFile = new QFile(path + "/fan" + QString::number(index) + "_input", this);
 
         if (rpmFile->open(QFile::ReadOnly))
         {
@@ -68,11 +74,11 @@ Fan::~Fan()
 QString Fan::name() const
 {
     const auto names = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("names");
-    const auto localNames = names.group(m_parent ? m_parent->name() : QStringLiteral(TEST_HWMON_NAME));
-    const auto name = localNames.readEntry("fan" + QString::number(m_index), QString());
+    const auto localNames = names.group(parent() ? parent()->name() : QStringLiteral(TEST_HWMON_NAME));
+    const auto name = localNames.readEntry("fan" + QString::number(index()), QString());
 
     if (name.isEmpty())
-        return "fan" + QString::number(m_index);
+        return "fan" + QString::number(index());
 
     return name;
 }
@@ -80,27 +86,27 @@ QString Fan::name() const
 void Fan::setName(const QString &name)
 {
     const auto names = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("names");
-    auto localNames = names.group(m_parent ? m_parent->name() : QStringLiteral(TEST_HWMON_NAME));
+    auto localNames = names.group(parent() ? parent()->name() : QStringLiteral(TEST_HWMON_NAME));
 
-    if (name != localNames.readEntry("fan" + QString::number(m_index), QString())
+    if (name != localNames.readEntry("fan" + QString::number(index()), QString())
         && !name.isEmpty())
     {
-        localNames.writeEntry("fan" + QString::number(m_index), name);
+        localNames.writeEntry("fan" + QString::number(index()), name);
         emit nameChanged();
     }
 }
 
 void Fan::toDefault()
 {
-    if (m_rpmStream->device() && m_parent)
+    if (m_rpmStream->device() && parent())
     {
         auto device = m_rpmStream->device();
         m_rpmStream->setDevice(Q_NULLPTR);
         delete device;
 
-        if (QDir(m_parent->path()).isReadable())
+        if (QDir(parent()->path()).isReadable())
         {
-            const auto rpmFile = new QFile(m_parent->path() + "/fan" + QString::number(m_index) + "_input", this);
+            const auto rpmFile = new QFile(parent()->path() + "/fan" + QString::number(index()) + "_input", this);
 
             if (rpmFile->open(QFile::ReadOnly))
             {

+ 1 - 1
import/src/fan.h

@@ -37,7 +37,7 @@ class Fan : public Sensor
 
 public:
 
-    explicit Fan(uint index, Hwmon *parent = Q_NULLPTR);
+    explicit Fan(uint index, Hwmon *parent, bool device = false);
     virtual ~Fan();
 
     int rpm() const { return m_rpm; }

+ 65 - 0
import/src/hwmon.cpp

@@ -139,6 +139,71 @@ void Hwmon::initialize()
             }
         }
     }
+
+    if (isEmpty())
+    {
+        QDir deviceDir(m_path + "/device");
+        const auto entries = deviceDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
+        for (const auto &entry : entries)
+        {
+            if (!entry.contains(QStringLiteral("input")))
+                continue;
+
+            auto str = entry;
+            auto success = false;
+            const auto index = str.remove(QRegExp("\\D+")).toUInt(&success);
+
+            if (!success)
+            {
+                emit error(i18n("Not a valid sensor: \'%1\'", entry));
+                continue;
+            }
+
+            if (entry.contains(QStringLiteral("fan")))
+            {
+                if (QFile::exists(m_path + "/pwm" + QString::number(index)))
+                {
+                    if (!m_pwmFans.contains(index))
+                    {
+                        auto newPwmFan = new PwmFan(index, this);
+                        connect(this, &Hwmon::sensorsUpdateNeeded, newPwmFan, &PwmFan::update);
+
+                        if (m_parent)
+                            connect(newPwmFan, &PwmFan::testStatusChanged, m_parent, &Loader::handleTestStatusChanged);
+
+                        m_pwmFans.insert(index, newPwmFan);
+                        emit pwmFansChanged();
+
+                        m_fans.insert(index, newPwmFan);
+                        emit fansChanged();
+                    }
+                }
+                else
+                {
+                    if (!m_fans.contains(index))
+                    {
+                        auto newFan = new Fan(index, this);
+                        connect(this, &Hwmon::sensorsUpdateNeeded, newFan, &Fan::update);
+
+                        m_fans.insert(index, newFan);
+                        emit fansChanged();
+                    }
+                }
+            }
+
+            if (entry.contains(QStringLiteral("temp")))
+            {
+                if (!m_temps.contains(index))
+                {
+                    auto newTemp = new Temp(index, this);
+                    connect(this, &Hwmon::sensorsUpdateNeeded, newTemp, &Temp::update);
+
+                    m_temps.insert(index, newTemp);
+                    emit tempsChanged();
+                }
+            }
+        }
+    }
 }
 
 QList<QObject *> Hwmon::fansAsObjects() const

+ 1 - 0
import/src/hwmon.h

@@ -61,6 +61,7 @@ public:
     Q_INVOKABLE void testFans();
     Q_INVOKABLE void abortTestingFans();
 
+    bool isEmpty() const { return m_temps.isEmpty() && m_fans.isEmpty() && m_pwmFans.isEmpty(); }
     bool isValid() const { return m_valid; }
     bool testing() const;
     void toDefault() const;

+ 25 - 14
import/src/loader.cpp

@@ -171,13 +171,13 @@ QPair<uint, uint> Loader::getEntryNumbers(const QString &entry)
         return QPair<uint, uint>(0, 0);
 
     auto list = entry.split('/', QString::SkipEmptyParts);
-    if (list.size() != 2)
+    if (list.size() < 2)
     {
         emit error(i18n("Invalid entry: \'%1\'", entry));
         return QPair<uint, uint>(0, 0);
     }
-    auto &hwmon = list[0];
-    auto &sensor = list[1];
+    auto &hwmon = list.first();
+    auto &sensor = list.last();
 
     if (!hwmon.startsWith(QStringLiteral("hwmon")))
     {
@@ -689,9 +689,11 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                configFile += "hwmon" + QString::number(pwmFan->temp()->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->temp()->parent()->index());
+                configFile += pwmFan->temp()->device() ? "/device/" : "/";
                 configFile += "temp" + QString::number(pwmFan->temp()->index()) + "_input ";
             }
             configFile += QChar(QChar::LineFeed);
@@ -700,9 +702,11 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "fan" + QString::number(pwmFan->index()) + "_input ";
             }
             configFile += QChar(QChar::LineFeed);
@@ -711,7 +715,8 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minTemp()) + QChar(QChar::Space);
             }
@@ -721,7 +726,8 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->maxTemp()) + QChar(QChar::Space);
             }
@@ -731,7 +737,8 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minStart()) + QChar(QChar::Space);
             }
@@ -741,7 +748,8 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minStop()) + QChar(QChar::Space);
             }
@@ -751,7 +759,8 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->minPwm()) + QChar(QChar::Space);
             }
@@ -761,7 +770,8 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->maxPwm()) + QChar(QChar::Space);
             }
@@ -771,7 +781,8 @@ QString Loader::createConfig() const
 
             for (const auto &pwmFan : qAsConst(usedFans))
             {
-                configFile += "hwmon" + QString::number(pwmFan->parent()->index()) + "/";
+                configFile += "hwmon" + QString::number(pwmFan->parent()->index());
+                configFile += pwmFan->device() ? "/device/" : "/";
                 configFile += "pwm" + QString::number(pwmFan->index()) + "=";
                 configFile += QString::number(pwmFan->average()) + QChar(QChar::Space);
             }

+ 58 - 56
import/src/pwmfan.cpp

@@ -43,7 +43,7 @@
 namespace Fancontrol
 {
 
-PwmFan::PwmFan(uint index, Hwmon *parent) : Fan(index, parent),
+PwmFan::PwmFan(uint index, Hwmon *parent, bool device) : Fan(index, parent, device),
     m_pwmStream(new QTextStream),
     m_enableStream(new QTextStream),
     m_pwm(0),
@@ -60,56 +60,58 @@ PwmFan::PwmFan(uint index, Hwmon *parent) : Fan(index, parent),
     m_zeroRpm(0),
     m_testStatus(NotStarted)
 {
-    if (parent)
+    if (!parent)
+        return;
+
+    connect(this, &PwmFan::tempChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::hasTempChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::minTempChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::maxTempChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::minPwmChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::maxPwmChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::minStartChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::minStopChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::averageChanged, parent, &Hwmon::configUpdateNeeded);
+    connect(this, &PwmFan::testStatusChanged, parent, &Hwmon::configUpdateNeeded);
+
+    auto path = device ? parent->path() + "/device" : parent->path();
+
+    if (QDir(path).isReadable())
     {
-        connect(this, &PwmFan::tempChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::hasTempChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::minTempChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::maxTempChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::minPwmChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::maxPwmChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::minStartChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::minStopChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::averageChanged, parent, &Hwmon::configUpdateNeeded);
-        connect(this, &PwmFan::testStatusChanged, parent, &Hwmon::configUpdateNeeded);
-
-        if (QDir(parent->path()).isReadable())
-        {
-            const auto pwmFile = new QFile(parent->path() + "/pwm" + QString::number(index), this);
+        const auto pwmFile = new QFile(path + "/pwm" + QString::number(index), this);
 
-            if (pwmFile->open(QFile::ReadWrite))
-            {
-                m_pwmStream->setDevice(pwmFile);
-                PwmFan::setPwm(m_pwmStream->readAll().toInt(), false);
-            }
-            else if (pwmFile->open(QFile::ReadOnly))
-            {
-                m_pwmStream->setDevice(pwmFile);
-                PwmFan::setPwm(m_pwmStream->readAll().toInt(), false);
-            }
-            else
-            {
-                emit error(i18n("Can't open pwm file: \'%1\'", pwmFile->fileName()));
-                delete pwmFile;
-            }
+        if (pwmFile->open(QFile::ReadWrite))
+        {
+            m_pwmStream->setDevice(pwmFile);
+            PwmFan::setPwm(m_pwmStream->readAll().toInt(), false);
+        }
+        else if (pwmFile->open(QFile::ReadOnly))
+        {
+            m_pwmStream->setDevice(pwmFile);
+            PwmFan::setPwm(m_pwmStream->readAll().toInt(), false);
+        }
+        else
+        {
+            emit error(i18n("Can't open pwm file: \'%1\'", pwmFile->fileName()));
+            delete pwmFile;
+        }
 
-            const auto pwmEnableFile = new QFile(parent->path() + "/pwm" + QString::number(index) + "_enable", this);
+        const auto pwmEnableFile = new QFile(path + "/pwm" + QString::number(index) + "_enable", this);
 
-            if (pwmEnableFile->open(QFile::ReadWrite))
-            {
-                m_enableStream->setDevice(pwmEnableFile);
-                setPwmEnable((PwmEnable)m_enableStream->readAll().toInt(), false);
-            }
-            else if (pwmEnableFile->open(QFile::ReadOnly))
-            {
-                m_enableStream->setDevice(pwmEnableFile);
-                setPwmEnable((PwmEnable)m_enableStream->readAll().toInt(), false);
-            }
-            else
-            {
-                emit error(i18n("Can't open pwm_enable file: \'%1\'", pwmEnableFile->fileName()));
-                delete pwmEnableFile;
-            }
+        if (pwmEnableFile->open(QFile::ReadWrite))
+        {
+            m_enableStream->setDevice(pwmEnableFile);
+            setPwmEnable((PwmEnable)m_enableStream->readAll().toInt(), false);
+        }
+        else if (pwmEnableFile->open(QFile::ReadOnly))
+        {
+            m_enableStream->setDevice(pwmEnableFile);
+            setPwmEnable((PwmEnable)m_enableStream->readAll().toInt(), false);
+        }
+        else
+        {
+            emit error(i18n("Can't open pwm_enable file: \'%1\'", pwmEnableFile->fileName()));
+            delete pwmEnableFile;
         }
     }
 }
@@ -157,7 +159,7 @@ void PwmFan::toDefault()
         emit testStatusChanged();
     }
 
-    if (m_pwmStream->device() && m_enableStream->device() && m_parent)
+    if (m_pwmStream->device() && m_enableStream->device() && parent())
     {
         auto device = m_pwmStream->device();
         m_pwmStream->setDevice(Q_NULLPTR);
@@ -167,7 +169,7 @@ void PwmFan::toDefault()
         m_enableStream->setDevice(Q_NULLPTR);
         delete device;
 
-        const auto pwmFile = new QFile(m_parent->path() + "/pwm" + QString::number(m_index), this);
+        const auto pwmFile = new QFile(parent()->path() + "/pwm" + QString::number(index()), this);
 
         if (pwmFile->open(QFile::ReadWrite))
         {
@@ -185,7 +187,7 @@ void PwmFan::toDefault()
             delete pwmFile;
         }
 
-        const auto pwmEnableFile = new QFile(m_parent->path() + "/pwm" + QString::number(m_index) + "_enable", this);
+        const auto pwmEnableFile = new QFile(parent()->path() + "/pwm" + QString::number(index()) + "_enable", this);
 
         if (pwmEnableFile->open(QFile::ReadWrite))
         {
@@ -491,7 +493,7 @@ void PwmFan::continueTest()
                 setMinStop(qMin(255, m_pwm + 5));
                 setMinPwm(qMin(m_minPwm, m_minStop));
                 setPwm(255);
-//                qDebug() << "Finished testing PwmFan" << m_index;
+//                qDebug() << "Finished testing PwmFan" << index();
             }
         }
         break;
@@ -509,17 +511,17 @@ bool PwmFan::testing() const
 bool PwmFan::active() const
 {
     const auto active = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("active");
-    const auto localActive = active.group(m_parent ? m_parent->name() : QStringLiteral(TEST_HWMON_NAME));
-    return localActive.readEntry("pwmfan" + QString::number(m_index), true);
+    const auto localActive = active.group(parent() ? parent()->name() : QStringLiteral(TEST_HWMON_NAME));
+    return localActive.readEntry("pwmfan" + QString::number(index()), true);
 }
 
 void PwmFan::setActive(bool a)
 {
     const auto active = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("active");
-    auto localActive = active.group(m_parent ? m_parent->name() : QStringLiteral(TEST_HWMON_NAME));
-    if (a != localActive.readEntry("pwmfan" + QString::number(m_index), true))
+    auto localActive = active.group(parent() ? parent()->name() : QStringLiteral(TEST_HWMON_NAME));
+    if (a != localActive.readEntry("pwmfan" + QString::number(index()), true))
     {
-        localActive.writeEntry("pwmfan" + QString::number(m_index), a);
+        localActive.writeEntry("pwmfan" + QString::number(index()), a);
         emit activeChanged();
     }
 }

+ 1 - 1
import/src/pwmfan.h

@@ -73,7 +73,7 @@ public:
     };
     Q_ENUM(PwmEnable)
 
-    explicit PwmFan(uint index, Hwmon *parent = Q_NULLPTR);
+    explicit PwmFan(uint index, Hwmon *parent, bool device = false);
     virtual ~PwmFan();
 
     int pwm() const Q_DECL_OVERRIDE { return m_pwm; }

+ 1 - 1
import/src/pwmfanmodel.cpp

@@ -60,7 +60,7 @@ QVariant PwmFanModel::data(const QModelIndex& index, int role) const
     switch (role)
     {
         case DisplayRole:
-            return fan->name() + "  (" + fan->path() + ")";
+            return fan->name() + "  (" + fan->id() + ")";
 
         case ObjectRole:
             return QVariant::fromValue(fan);

+ 8 - 4
import/src/sensor.cpp

@@ -26,13 +26,17 @@
 namespace Fancontrol
 {
 
-Sensor::Sensor(Hwmon *parent, uint index, const QString &path) : QObject(parent),
+Sensor::Sensor(Hwmon *parent, uint index, const QString &type, bool device) : QObject(parent),
     m_parent(parent),
     m_index(index),
-    m_path(path)
+    m_device(device)
 {
-    if (parent)
-        connect(this, &Sensor::error, parent, &Hwmon::error);
+    if (!parent)
+        return;
+
+    m_id = device ? parent->name() + "/device/" + type + QString::number(index) : parent->name() + "/" + type + QString::number(index);
+
+    connect(this, &Sensor::error, parent, &Hwmon::error);
 }
 
 }

+ 9 - 7
import/src/sensor.h

@@ -34,24 +34,25 @@ class Sensor : public QObject
     Q_OBJECT
     Q_PROPERTY(uint index READ index CONSTANT)
     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
-    Q_PROPERTY(QString path READ path CONSTANT)
+    Q_PROPERTY(QString id READ id CONSTANT)
     Q_PROPERTY(Hwmon * parent READ parent CONSTANT)
 
 public:
 
-    explicit Sensor(Hwmon *parent = Q_NULLPTR, uint index = 0, const QString &path = QString());
+    explicit Sensor(Hwmon *parent, uint index, const QString &type, bool device = false);
 
     virtual QString name() const = 0;
     virtual void setName(const QString &name) = 0;
     virtual void toDefault() = 0;
     virtual bool isValid() const = 0;
     virtual void update() = 0;
-    QString path() const { return m_path; }
+    QString id() const { return m_id; }
     Hwmon * parent() const { return m_parent; }
     uint index() const { return m_index; }
+    bool device() const { return m_device; }
 
-    bool operator==(const Sensor &other) { return m_path == other.path(); }
-    bool operator!=(const Sensor &other) { return m_path != other.path(); }
+    bool operator==(const Sensor &other) { return m_id == other.id(); }
+    bool operator!=(const Sensor &other) { return m_id != other.id(); }
 
 
 signals:
@@ -60,11 +61,12 @@ signals:
     void error(QString, bool = false);
 
 
-protected:
+private:
 
     Hwmon *const m_parent;
     const uint m_index;
-    const QString m_path;
+    QString m_id;
+    bool m_device;
 };
 
 }

+ 24 - 19
import/src/temp.cpp

@@ -39,14 +39,19 @@
 namespace Fancontrol
 {
 
-Temp::Temp(uint index, Hwmon *parent) :
-    Sensor(parent, index, parent ? parent->name() + QStringLiteral("/temp") + QString::number(index) : QString()),
+Temp::Temp(uint index, Hwmon *parent, bool device) :
+    Sensor(parent, index, QStringLiteral("temp"), device),
     m_valueStream(new QTextStream)
 {
-    if (parent && QDir(parent->path()).isReadable())
+    if (!parent)
+        return;
+
+    auto path = device ? parent->path() + "/device" : parent->path();
+
+    if (QDir(path).isReadable())
     {
-        const auto valueFile = new QFile(parent->path() + "/temp" + QString::number(index) + "_input", this);
-        const auto labelFile = new QFile(parent->path() + "/temp" + QString::number(index) + "_label");
+        const auto valueFile = new QFile(path + "/temp" + QString::number(index) + "_input", this);
+        const auto labelFile = new QFile(path + "/temp" + QString::number(index) + "_label");
 
         if (valueFile->open(QFile::ReadOnly))
         {
@@ -57,7 +62,7 @@ Temp::Temp(uint index, Hwmon *parent) :
         else
         {
             delete valueFile;
-            emit error(i18n("Can't open value file: \'%1\'", parent->path() + "/temp" + QString::number(index) + "_input"));
+            emit error(i18n("Can't open value file: \'%1\'", path + "/temp" + QString::number(index) + "_input"));
         }
 
         if (labelFile->exists())
@@ -65,10 +70,10 @@ Temp::Temp(uint index, Hwmon *parent) :
             if (labelFile->open(QFile::ReadOnly))
                 m_label = QTextStream(labelFile).readLine();
             else
-                emit error(i18n("Can't open label file: \'%1\'", parent->path() + "/temp" + QString::number(index) + "_label"));
+                emit error(i18n("Can't open label file: \'%1\'", path + "/temp" + QString::number(index) + "_label"));
         }
         else
-            emit error(i18n("Temp has no label: \'%1\'", parent->path() + "/temp" + QString::number(index)));
+            emit error(i18n("Temp has no label: \'%1\'", path + "/temp" + QString::number(index)));
 
         delete labelFile;
     }
@@ -84,13 +89,13 @@ Temp::~Temp()
 QString Temp::name() const
 {
     const auto names = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("names");
-    const auto localNames = names.group(m_parent ? m_parent->name() : QStringLiteral(TEST_HWMON_NAME));
-    const auto name = localNames.readEntry("temp" + QString::number(m_index), QString());
+    const auto localNames = names.group(parent() ? parent()->name() : QStringLiteral(TEST_HWMON_NAME));
+    const auto name = localNames.readEntry("temp" + QString::number(index()), QString());
 
     if (name.isEmpty())
     {
         if (m_label.isEmpty())
-            return "temp" + QString::number(m_index);
+            return "temp" + QString::number(index());
 
         return m_label;
     }
@@ -100,27 +105,27 @@ QString Temp::name() const
 void Temp::setName(const QString &name)
 {
     const auto names = KSharedConfig::openConfig(QStringLiteral("fancontrol-gui"))->group("names");
-    auto localNames = names.group(m_parent ? m_parent->name() : QStringLiteral(TEST_HWMON_NAME));
+    auto localNames = names.group(parent() ? parent()->name() : QStringLiteral(TEST_HWMON_NAME));
 
-    if (name != localNames.readEntry("temp" + QString::number(m_index), QString())
+    if (name != localNames.readEntry("temp" + QString::number(index()), QString())
         && !name.isEmpty())
     {
-        localNames.writeEntry("temp" + QString::number(m_index), name);
+        localNames.writeEntry("temp" + QString::number(index()), name);
         emit nameChanged();
     }
 }
 
 void Temp::toDefault()
 {
-    if (m_valueStream->device() && m_parent)
+    if (m_valueStream->device() && parent())
     {
         auto device = m_valueStream->device();
         m_valueStream->setDevice(Q_NULLPTR);
         delete device;
 
-        if (QDir(m_parent->path()).isReadable())
+        if (QDir(parent()->path()).isReadable())
         {
-            const auto valueFile = new QFile(m_parent->path() + "/temp" + QString::number(m_index) + "_input", this);
+            const auto valueFile = new QFile(parent()->path() + "/temp" + QString::number(index()) + "_input", this);
 
             if (valueFile->open(QFile::ReadOnly))
             {
@@ -129,7 +134,7 @@ void Temp::toDefault()
                 m_value /= 1000;
             }
             else
-                emit error(i18n("Can't open value file: \'%1\'", m_parent->path() + "/temp" + QString::number(m_index) + "_input"));
+                emit error(i18n("Can't open value file: \'%1\'", parent()->path() + "/temp" + QString::number(index()) + "_input"));
         }
     }
 }
@@ -142,7 +147,7 @@ void Temp::update()
     const auto value = m_valueStream->readAll().toInt(&success) / 1000;
 
     if (!success)
-        emit error(i18n("Can't update value of temp: \'%1\'", m_parent->path() + "/temp" + QString::number(m_index)));
+        emit error(i18n("Can't update value of temp: \'%1\'", parent()->path() + "/temp" + QString::number(index())));
 
     if (value != m_value)
     {

+ 1 - 1
import/src/temp.h

@@ -40,7 +40,7 @@ class Temp : public Sensor
 
 public:
 
-    explicit Temp(uint index, Hwmon *parent = Q_NULLPTR);
+    explicit Temp(uint index, Hwmon *parent, bool device = false);
     virtual ~Temp();
 
     QString label() const { return m_label; }

+ 1 - 1
import/src/tempmodel.cpp

@@ -61,7 +61,7 @@ QVariant TempModel::data(const QModelIndex& index, int role) const
     switch (role)
     {
         case DisplayRole:
-            return temp->name() + ": " + QString::number(temp->value()) + m_unit + "   (" + temp->path() + ")";
+            return temp->name() + ": " + QString::number(temp->value()) + m_unit + "   (" + temp->id() + ")";
 
         case ObjectRole:
             return QVariant::fromValue(temp);