FlowerCare: Add a refresh rate setting

This commit is contained in:
Michael Zanetti 2019-10-14 13:07:46 +02:00
parent be230d9a3b
commit b5d47a0ae2
4 changed files with 30 additions and 2 deletions

View File

@ -1,4 +1,9 @@
# Flowercare
This pluggin provides support for the Bluetooth LE [Xiaomi Flower Care Monitor](https://xiaomi-mi.com/sockets-and-sensors/xiaomi-huahuacaocao-flower-care-smart-monitor/).
This plugin provides support for the Bluetooth LE
[Xiaomi Flower Care Monitor](https://xiaomi-mi.com/sockets-and-sensors/xiaomi-huahuacaocao-flower-care-smart-monitor/).
The Xiaomi Flower Care sensor will provide information about temperature, soil moisture and conductivity as well as light intensity.
By default, the sensor value is refreshed from the sensor every 20 minutes. This setting can be changed to poll the sensor more or
less often, depending if more precise measurements or longer battery life are more important.

View File

@ -117,6 +117,15 @@ void DevicePluginFlowercare::setupDevice(DeviceSetupInfo *info)
connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginFlowercare::onPluginTimer);
}
// Update refresh schedule when the refresh rate setting is changed
connect(device, &Device::settingChanged, flowerCare, [this, device] {
FlowerCare *flowerCare = m_list.value(device);
int refreshInterval = device->setting(flowerCareSettingsRefreshRateParamTypeId).toInt();
if (m_refreshMinutes[flowerCare] > refreshInterval) {
m_refreshMinutes[flowerCare] = refreshInterval;
}
});
info->finish(Device::DeviceErrorNoError);
}
@ -183,5 +192,5 @@ void DevicePluginFlowercare::onSensorDataReceived(quint8 batteryLevel, double de
device->setStateValue(flowerCareMoistureStateTypeId, moisture);
device->setStateValue(flowerCareConductivityStateTypeId, fertility);
m_refreshMinutes[flowerCare] = 20;
m_refreshMinutes[flowerCare] = device->setting(flowerCareSettingsRefreshRateParamTypeId).toInt();
}

View File

@ -23,6 +23,15 @@
"inputType": "MacAddress"
}
],
"settingsTypes": [
{
"id": "e892d118-336e-4495-ae41-0c7cc907efe8",
"name": "refreshRate",
"displayName": "Refresh rate (minutes)",
"type": "uint",
"defaultValue": 20
}
],
"stateTypes": [
{
"id": "6254103a-ff8b-4f62-afda-6b5be1c933ec",

View File

@ -119,5 +119,10 @@ The name of the StateType ({7e0a3b3d-72f4-4547-bd1e-2711be61c1a7}) of DeviceClas
The name of the StateType ({f77608b3-8b5b-43a9-aab6-0dc35c694ec3}) of DeviceClass flowerCare</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Refresh rate (minutes)</source>
<extracomment>The name of the ParamType (DeviceClass: flowerCare, Type: settings, ID: {e892d118-336e-4495-ae41-0c7cc907efe8})</extracomment>
<translation type="unfinished"></translation>
</message>
</context>
</TS>