Inital commit, support for rain and wind sensors.

This commit is contained in:
Stefan Persson 2013-09-11 14:29:46 +02:00
parent d1e33dff0c
commit 103eaf05e0
8 changed files with 169 additions and 13 deletions

View file

@ -28,7 +28,9 @@ SET( Plugin_EXTRA
header_bg.png
icon.png
icon_humidity.png
icon_rain.png
icon_temp.png
icon_wind.png
main.qml
HeaderTitle.qml
row_bg.png

View file

@ -110,6 +110,36 @@ Item{
icon: "icon_humidity.png"
lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date()
}
SensorValue {
visible: modelData.hasRainRate
text: visible ? modelData.sensorValue(4).value + ' mm/h' : ''
icon: "icon_rain.png"
lastUpdated: visible ? modelData.sensorValue(4).lastUpdated : new Date()
}
SensorValue {
visible: modelData.hasRainTotal
text: visible ? modelData.sensorValue(8).value + ' mm' : ''
icon: "icon_rain.png"
lastUpdated: visible ? modelData.sensorValue(8).lastUpdated : new Date()
}
SensorValue {
visible: modelData.hasWindDirection
text: visible ? getWindDirection.callWith(modelData.sensorValue(16).value): ''
icon: "icon_wind.png"
lastUpdated: visible ? modelData.sensorValue(16).lastUpdated : new Date()
}
SensorValue {
visible: modelData.hasWindAverage
text: visible ? modelData.sensorValue(32).value + ' m/s' : ''
icon: "icon_wind.png"
lastUpdated: visible ? modelData.sensorValue(32).lastUpdated : new Date()
}
SensorValue {
visible: modelData.hasWindGust
text: visible ? '(' + modelData.sensorValue(64).value + ' m/s)' : ''
icon: "icon_wind.png"
lastUpdated: visible ? modelData.sensorValue(64).lastUpdated : new Date()
}
}
}

View file

@ -27,12 +27,18 @@ com.telldus.sensors = function() {
}
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_TEMPERATURE);
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_HUMIDITY);
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_RAINRATE);
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_RAINTOTAL);
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_WINDDIRECTION);
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_WINDAVERAGE);
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_WINDGUST);
}
com.telldus.core.sensorEvent.connect(sensorEvent);
view = new com.telldus.qml.view({
deleteSensor: deleteSensor
deleteSensor: deleteSensor,
getWindDirection: getWindDirection
});
view.setProperty('sensorModel', sensorList);
@ -82,6 +88,44 @@ com.telldus.sensors = function() {
}
}
function getWindDirection(degrees){
var number = degrees/22.5;
switch(number){
case 1:
return 'NNE';
case 2:
return 'NE';
case 3:
return 'ENE';
case 4:
return 'E';
case 5:
return 'ESE';
case 6:
return 'SE';
case 7:
return 'SSE';
case 8:
return 'S';
case 9:
return 'SSW';
case 10:
return 'SW';
case 11:
return 'WSW';
case 12:
return 'W';
case 13:
return 'WNW';
case 14:
return 'NW';
case 15:
return 'NNW';
default:
return 'N';
}
}
function loadSensorModel(){
var settings = new com.telldus.settings();
var sensors = new com.telldus.qml.array();
@ -99,6 +143,46 @@ com.telldus.sensors = function() {
return sensors;
}
function pickSensorValues(sensor){
var allValues = new Array();
if(sensor.hasHumidity){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_HUMIDITY);
var value = {type: com.telldus.core.TELLSTICK_HUMIDITY, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
if(sensor.hasRainRate){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_RAINRATE);
var value = {type: com.telldus.core.TELLSTICK_RAINRATE, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
if(sensor.hasRainTotal){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_RAINTOTAL);
var value = {type: com.telldus.core.TELLSTICK_RAINTOTAL, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
if(sensor.hasTemperature){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_TEMPERATURE);
var value = {type: com.telldus.core.TELLSTICK_TEMPERATURE, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
if(sensor.hasWindDirection){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_WINDDIRECTION);
var value = {type: com.telldus.core.TELLSTICK_WINDDIRECTION, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
if(sensor.hasWindAverage){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_WINDAVERAGE);
var value = {type: com.telldus.core.TELLSTICK_WINDAVERAGE, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
if(sensor.hasWindGust){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_WINDGUST);
var value = {type: com.telldus.core.TELLSTICK_WINDGUST, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
return allValues;
}
function saveSensorModel(){
var settings = new com.telldus.settings();
var sensorProperties = new Array();
@ -106,17 +190,7 @@ com.telldus.sensors = function() {
for (var i = 0; i < sensorList.length; ++i) {
var sensor = sensorList.get(i);
var allValues = new Array();
if(sensor.hasHumidity){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_HUMIDITY);
var value = {type: com.telldus.core.TELLSTICK_HUMIDITY, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
if(sensor.hasTemperature){
var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_TEMPERATURE);
var value = {type: com.telldus.core.TELLSTICK_TEMPERATURE, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value};
allValues.push(value);
}
var allValues = pickSensorValues(sensor);
var sensorProp = {protocol:sensor.protocol, model:sensor.model, id:sensor.id, values:allValues, name:sensor.name, showInList:sensor.showInList};
sensorProperties.push(sensorProp);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B

View file

@ -5,7 +5,7 @@
class Sensor::PrivateData {
public:
bool hasTemperature, hasHumidity, showInList;
bool hasTemperature, hasHumidity, hasRainRate, hasRainTotal, hasWindDirection, hasWindAverage, hasWindGust, showInList;
int id;
QString model, name, protocol;
QDateTime lastUpdated;
@ -67,10 +67,30 @@ void Sensor::setProtocol(const QString &protocol) {
emit protocolChanged();
}
bool Sensor::hasRainRate() const {
return d->values.contains(TELLSTICK_RAINRATE);
}
bool Sensor::hasRainTotal() const {
return d->values.contains(TELLSTICK_RAINTOTAL);
}
bool Sensor::hasTemperature() const {
return d->values.contains(TELLSTICK_TEMPERATURE);
}
bool Sensor::hasWindDirection() const {
return d->values.contains(TELLSTICK_WINDDIRECTION);
}
bool Sensor::hasWindAverage() const {
return d->values.contains(TELLSTICK_WINDAVERAGE);
}
bool Sensor::hasWindGust() const {
return d->values.contains(TELLSTICK_WINDGUST);
}
QObject * Sensor::sensorValue(int type) {
return (d->values.contains(type) ? d->values[type] : 0);
}
@ -90,6 +110,16 @@ void Sensor::setValue(int type, const QString &value, const QDateTime &timestamp
emit hasTemperatureChanged();
} else if (type == TELLSTICK_HUMIDITY) {
emit hasHumidityChanged();
} else if (type == TELLSTICK_RAINRATE) {
emit hasRainRateChanged();
} else if (type == TELLSTICK_RAINTOTAL) {
emit hasRainTotalChanged();
} else if (type == TELLSTICK_WINDDIRECTION) {
emit hasWindDirectionChanged();
} else if (type == TELLSTICK_WINDAVERAGE) {
emit hasWindAverageChanged();
} else if (type == TELLSTICK_WINDGUST) {
emit hasWindGustChanged();
}
}

View file

@ -13,6 +13,11 @@ class Sensor : public QObject
Q_OBJECT
Q_PROPERTY(bool hasHumidity READ hasHumidity NOTIFY hasHumidityChanged)
Q_PROPERTY(bool hasTemperature READ hasTemperature NOTIFY hasTemperatureChanged)
Q_PROPERTY(bool hasRainRate READ hasRainRate NOTIFY hasRainRateChanged)
Q_PROPERTY(bool hasRainTotal READ hasRainTotal NOTIFY hasRainTotalChanged)
Q_PROPERTY(bool hasWindDirection READ hasWindDirection NOTIFY hasWindDirectionChanged)
Q_PROPERTY(bool hasWindAverage READ hasWindAverage NOTIFY hasWindAverageChanged)
Q_PROPERTY(bool hasWindGust READ hasWindGust NOTIFY hasWindGustChanged)
Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged)
Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
@ -36,7 +41,12 @@ public:
QString protocol() const;
void setProtocol(const QString &protocol);
bool hasRainRate() const;
bool hasRainTotal() const;
bool hasTemperature() const;
bool hasWindDirection() const;
bool hasWindAverage() const;
bool hasWindGust() const;
bool showInList() const;
Q_INVOKABLE QObject *sensorValue(int type);
@ -47,7 +57,12 @@ public:
signals:
void idChanged();
void hasHumidityChanged();
void hasRainRateChanged();
void hasRainTotalChanged();
void hasTemperatureChanged();
void hasWindDirectionChanged();
void hasWindAverageChanged();
void hasWindGustChanged();
void modelChanged();
void nameChanged();
void protocolChanged();

View file

@ -32,6 +32,11 @@ void TelldusCorePlugin::initialize ( const QString & key, QScriptEngine * engine
value.setProperty("TELLSTICK_TEMPERATURE", TELLSTICK_TEMPERATURE);
value.setProperty("TELLSTICK_HUMIDITY", TELLSTICK_HUMIDITY);
value.setProperty("TELLSTICK_RAINRATE", TELLSTICK_RAINRATE);
value.setProperty("TELLSTICK_RAINTOTAL", TELLSTICK_RAINTOTAL);
value.setProperty("TELLSTICK_WINDDIRECTION", TELLSTICK_WINDDIRECTION);
value.setProperty("TELLSTICK_WINDAVERAGE", TELLSTICK_WINDAVERAGE);
value.setProperty("TELLSTICK_WINDGUST", TELLSTICK_WINDGUST);
engine->globalObject().property("com").property("telldus").setProperty("core", value);
}