Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Improvements during startup. Check if openhab system is available (#17)
Browse files Browse the repository at this point in the history
* Improvements during startup. Check if openhab system is available

* code styling

* code style

* Bugfix

* Improvements during reconnection

* code style
  • Loading branch information
miloit authored Dec 23, 2020
1 parent c15bc67 commit e0a77bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/openhab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* Copyright (C) 2019 Christian Riedl <[email protected]>
* Copyright (C) 2020 Andreas Mroß <[email protected]>
* Copyright (C) 2020 Michael Löcher <[email protected]>
*
* This file is part of the YIO-Remote software project.
*
Expand Down Expand Up @@ -29,6 +30,7 @@
#include <QSet>
#include <QString>
#include <QtDebug>
#include <QProcess>

#include "openhab_channelmappings.h"
#include "yio-interface/entities/blindinterface.h"
Expand Down Expand Up @@ -186,12 +188,20 @@ void OpenHAB::connect() {

_myEntities = m_entities->getByIntegration(integrationId());

getItems(true);


_tries = 0;
_userDisconnect = false;
_wasDisconnected = false;
_standby = false;
if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) {
startSse();
_pollingTimer.start();
getItems(true);
setState(CONNECTED);
} else {
qCDebug(m_logCategory) << "openhab not reachable";
}
}

void OpenHAB::disconnect() {
Expand All @@ -213,23 +223,34 @@ void OpenHAB::enterStandby() {
if (_sseReply->isRunning()) {
_sseReply->abort();
}
_pollingTimer.start();
if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) {
_pollingTimer.start();
} else {
qCDebug(m_logCategory) << "openhab not reachable";
}
}

void OpenHAB::leaveStandby() {
_standby = false;

_pollingTimer.stop();
startSse();
getItems(false);
if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) {
// _pollingTimer.stop();
startSse();
getItems(false);
} else {
qCDebug(m_logCategory) << "openhab not reachable";
}
}

void OpenHAB::jsonError(const QString& error) {
qCWarning(m_logCategory) << "JSON error " << error;
}

void OpenHAB::onPollingTimer() {
getItems(false);
if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) {
getItems(false);
} else {
qCDebug(m_logCategory) << "openhab not reachable";
}
}

void OpenHAB::onNetWorkAccessible(QNetworkAccessManager::NetworkAccessibility accessibility) {
Expand All @@ -255,7 +276,6 @@ void OpenHAB::getItems(bool first) {
// called during connect
setState(CONNECTED);
// connect to the SSE source
startSse();
}
processItems(doc, first);
});
Expand Down
1 change: 1 addition & 0 deletions src/openhab.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* Copyright (C) 2019 Christian Riedl <[email protected]>
* Copyright (C) 2020 Andreas Mroß <[email protected]>
* Copyright (C) 2020 Michael Löcher <[email protected]>
*
* This file is part of the YIO-Remote software project.
*
Expand Down

1 comment on commit e0a77bc

@zehnm
Copy link
Member

@zehnm zehnm commented on e0a77bc Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use conventional commit messages when squashing pull requests to get a proper change log in the next release ;-)
Supported prefixes:

enum ConventionalCommitTypes {
  feat = 'Features',
  fix = 'Bug Fixes',
  docs = 'Documentation',
  style = 'Styles',
  refactor = 'Code Refactoring',
  perf = 'Performance Improvements',
  test = 'Tests',
  build = 'Builds',
  ci = 'Continuous Integration',
  chore = 'Chores',
  revert = 'Reverts',
}

Please sign in to comment.