Skip to content

Commit

Permalink
Rework thermometers handling
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Oct 21, 2022
1 parent 9093941 commit f5f54e8
Show file tree
Hide file tree
Showing 13 changed files with 605 additions and 356 deletions.
2 changes: 2 additions & 0 deletions Theengs.pro
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ SOURCES += src/main.cpp \
src/devices/device_theengs_motionsensors.cpp \
src/devices/device_theengs_probes.cpp \
src/devices/device_theengs_scales.cpp \
src/devices/device_theengs_thermometers.cpp \
src/thirdparty/RC4/rc4.cpp

HEADERS += src/SettingsManager.h \
Expand Down Expand Up @@ -112,6 +113,7 @@ HEADERS += src/SettingsManager.h \
src/devices/device_theengs_motionsensors.h \
src/devices/device_theengs_probes.h \
src/devices/device_theengs_scales.h \
src/devices/device_theengs_thermometers.h \
src/thirdparty/RC4/rc4.h

INCLUDEPATH += src/ src/thirdparty/
Expand Down
2 changes: 1 addition & 1 deletion qml/DeviceWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Item {

function initBoxData() {
// Set icon
imageDevice.source = UtilsDeviceSensors.getDeviceIcon(boxDevice, hasHygro)
imageDevice.source = UtilsDeviceSensors.getDeviceIconTheengs(boxDevice, hasHygro)

// Load indicators
if (!loaderIndicators.sourceComponent) {
Expand Down
16 changes: 16 additions & 0 deletions qml/components_js/UtilsDeviceSensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ function getDeviceIcon(device, devicePlanted) {
return src
}

function getDeviceIconTheengs(device, devicePlanted) {
var src = ""

if (device.isProbe) {
src = "qrc:/assets/icons_material/baseline-settings_input_component-24px.svg"
} else if (device.isScale) {
src = "qrc:/assets/icons_material/baseline-monitor_weight-24px.svg"
} else if (device.isMotionSensor) {
src = "qrc:/assets/icons_material/baseline-sensors-24px.svg"
} else {
src = getDeviceIcon(device, devicePlanted)
}

return src
}

/* ************************************************************************** */

function getDeviceStatusText(deviceStatus) {
Expand Down
16 changes: 3 additions & 13 deletions src/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#include "SettingsManager.h"
#include "MqttManager.h"

#include "utils_app.h"

#include "device.h"
#include "device_theengs.h"
#include "devices/device_flowercare.h"
#include "devices/device_flowercare_tuya.h"
#include "devices/device_ropot.h"
#include "devices/device_hygrotemp_cgd1.h"
#include "devices/device_hygrotemp_cgdk2.h"
Expand All @@ -34,13 +36,6 @@
#include "devices/device_hygrotemp_lywsdcgq.h"
#include "devices/device_thermobeacon.h"
#include "devices/device_jqjcy01ym.h"
#include "devices/device_theengs_generic.h"
#include "devices/device_theengs_beacons.h"
#include "devices/device_theengs_probes.h"
#include "devices/device_theengs_scales.h"
#include "devices/device_theengs_motionsensors.h"

#include "utils_app.h"

#include <QList>
#include <QDateTime>
Expand Down Expand Up @@ -120,8 +115,6 @@ DeviceManager::DeviceManager(bool daemon)

if (deviceName == "Flower care" || deviceName == "Flower mate" || deviceName == "Grow care garden")
d = new DeviceFlowerCare(deviceAddr, deviceName, this);
else if (deviceName == "TY")
d = new DeviceFlowerCare_tuya(deviceAddr, deviceName, this);
else if (deviceName == "ropot")
d = new DeviceRopot(deviceAddr, deviceName, this);

Expand Down Expand Up @@ -1347,7 +1340,6 @@ void DeviceManager::addBleDevice(const QBluetoothDeviceInfo &info)
// Regular WatchFlower device
if (info.name() == "Flower care" || info.name() == "Flower mate" ||
info.name() == "Grow care garden" ||
info.name() == "TY" ||
info.name() == "ropot" ||
info.name().startsWith("Flower power") ||
info.name().startsWith("Parrot pot") ||
Expand All @@ -1368,8 +1360,6 @@ void DeviceManager::addBleDevice(const QBluetoothDeviceInfo &info)
// Create the device
if (info.name() == "Flower care" || info.name() == "Flower mate" || info.name() == "Grow care garden")
d = new DeviceFlowerCare(info, this);
else if (info.name() == "TY")
d = new DeviceFlowerCare_tuya(info, this);
else if (info.name() == "ropot")
d = new DeviceRopot(info, this);

Expand Down
8 changes: 8 additions & 0 deletions src/DeviceManager_advertisement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
serializeJson(obj, output);
//qDebug() << "output:" << output.c_str();

if (doc["model_id"] == "IBEACON") continue;
if (doc["model_id"] == "MS-CDP") continue;
if (doc["model_id"] == "GAEN") continue;

dd->setTheengsModelId(QString::fromStdString(doc["model"]), QString::fromStdString(doc["model_id"]));

DeviceTheengs *ddd = dynamic_cast<DeviceTheengs*>(dd);
Expand Down Expand Up @@ -148,6 +152,10 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
serializeJson(obj, output);
//qDebug() << "output:" << output.c_str();

if (doc["model_id"] == "IBEACON") continue;
if (doc["model_id"] == "MS-CDP") continue;
if (doc["model_id"] == "GAEN") continue;

dd->setTheengsModelId(QString::fromStdString(doc["model"]), QString::fromStdString(doc["model_id"]));

DeviceTheengs *ddd = dynamic_cast<DeviceTheengs*>(dd);
Expand Down
11 changes: 6 additions & 5 deletions src/DeviceManager_theengs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "devices/device_theengs_probes.h"
#include "devices/device_theengs_scales.h"
#include "devices/device_theengs_motionsensors.h"
#include "devices/device_theengs_thermometers.h"

#include <string>

Expand All @@ -46,6 +47,8 @@ Device * DeviceManager::createTheengsDevice_fromDb(const QString &deviceName,
const QString &deviceModel_theengs,
const QString &deviceAddr)
{
//qDebug() << "createTheengsDevice_fromDb(" << deviceName << "/" << deviceModel_theengs << "/" << deviceAddr << ")";

DeviceTheengs *device = nullptr;

QString device_props = QString::fromUtf8(TheengsDecoder().getTheengProperties(deviceModel_theengs.toLocal8Bit()));
Expand Down Expand Up @@ -124,9 +127,8 @@ Device * DeviceManager::createTheengsDevice_fromDb(const QString &deviceName,
deviceModel_theengs == "TP357/8" ||
deviceModel_theengs == "WS02/WS08")
{
device = new DeviceTheengsGeneric(deviceAddr, deviceName,
deviceModel_theengs, device_props, this);
device->setThermometer();
device = new DeviceTheengsThermometers(deviceAddr, deviceName,
deviceModel_theengs, device_props, this);
}
else
{
Expand Down Expand Up @@ -282,8 +284,7 @@ Device * DeviceManager::createTheengsDevice_fromAdv(const QBluetoothDeviceInfo &
device_modelid_theengs == "TP357/8" ||
device_modelid_theengs == "WS02/WS08")
{
device = new DeviceTheengsGeneric(deviceInfo, device_modelid_theengs, device_props, this);
device->setThermometer();
device = new DeviceTheengsThermometers(deviceInfo, device_modelid_theengs, device_props, this);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class Device: public QObject
bool hasBluetoothAdvertisement() const { return (m_deviceBluetoothMode & DeviceUtils::DEVICE_BLE_ADVERTISEMENT); }

bool isPlantSensor() const { return (m_deviceType == DeviceUtils::DEVICE_PLANTSENSOR); }
bool isThermometer() const { return (m_deviceType == DeviceUtils::DEVICE_THERMOMETER); }
bool isThermometer() const { return (m_deviceType == DeviceUtils::DEVICE_THERMOMETER || m_deviceType == DeviceUtils::DEVICE_THEENGS_THERMOMETER); }
bool isEnvironmentalSensor() const { return (m_deviceType == DeviceUtils::DEVICE_ENVIRONMENTAL); }
bool isLight() const { return (m_deviceType == DeviceUtils::DEVICE_LIGHT); }
//bool isBeacon() const { return (m_deviceType == DeviceUtils::DEVICE_BEACON); }
Expand Down
1 change: 1 addition & 0 deletions src/device_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DeviceUtils: public QObject
DEVICE_THEENGS_BEACON,
DEVICE_THEENGS_PROBE,
DEVICE_THEENGS_SCALE,
DEVICE_THEENGS_THERMOMETER,
DEVICE_THEENGS_MOTIONSENSOR,
DEVICE_THEENGS_SMARTWATCH,
DEVICE_THEENGS_GENERIC,
Expand Down
Loading

0 comments on commit f5f54e8

Please sign in to comment.