From c34bebd954a544626f4abac524b823b0475063f8 Mon Sep 17 00:00:00 2001 From: Danny Bloemendaal Date: Tue, 31 May 2016 20:47:48 +0200 Subject: [PATCH 1/2] added updateCustomSensor(value) --- README.md | 3 ++- dzVents/Device.lua | 5 +++++ dzVents/QUICKREF.md | 3 ++- dzVents/dzVents history.txt | 3 +++ dzVents/tests/testDevice.lua | 5 +++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e7dfda..92b3c47 100644 --- a/README.md +++ b/README.md @@ -443,7 +443,8 @@ You can control this fetching in the [settings](#settings). - **updateAirQuality(quality)**: *Function*. - **updateAlertSensor(level, text)**: *Function*. Level can be domoticz.ALERTLEVEL_GREY, ALERTLEVEL_GREE, ALERTLEVEL_YELLOW, ALERTLEVEL_ORANGE, ALERTLEVEL_RED - **updateBarometer(pressure, forecast)**: *Function*. Update barometric pressure. Forecast can be domoticz.BARO_STABLE, BARO_SUNNY, BARO_CLOUDY, BARO_UNSTABLE, BARO_THUNDERSTORM, BARO_UNKNOWN, BARO_CLOUDY_RAIN - - **updateCounter(value)**: *Function*. + - **updateCounter(value)**: *Function*. + - **updateCustomSensor(value)**: *Function*. - **updateDistance(distance)**: *Function*. - **updateElectricity(power, energy)**: *Function*. - **updateGas(usage)**: *Function*. diff --git a/dzVents/Device.lua b/dzVents/Device.lua index c472dd2..63fa238 100644 --- a/dzVents/Device.lua +++ b/dzVents/Device.lua @@ -280,6 +280,11 @@ local function Device(domoticz, name, state, wasChanged) self.update(0, distance) end + function self.updateCustomSensor(value) + self.update(0, value) + end + + function self.updateSetPoint(setPoint, mode, untilDate) if (self.hardwareTypeVal == 15 and self.deviceSubType == 'SetPoint') then -- dummy hardware -- send the command using openURL otherwise, due to a bug in Domoticz, you will get a timeout on the script diff --git a/dzVents/QUICKREF.md b/dzVents/QUICKREF.md index cc3dc25..2aca597 100644 --- a/dzVents/QUICKREF.md +++ b/dzVents/QUICKREF.md @@ -253,7 +253,8 @@ Available on the collections: devices, variables, scenes, groups: - **updateAirQuality(quality)**: *Function*. - **updateAlertSensor(level, text)**: *Function*. Level can be domoticz.ALERTLEVEL_GREY, ALERTLEVEL_GREE, ALERTLEVEL_YELLOW, ALERTLEVEL_ORANGE, ALERTLEVEL_RED - **updateBarometer(pressure, forecast)**: *Function*. Update barometric pressure. Forecast can be domoticz.BARO_STABLE, BARO_SUNNY, BARO_CLOUDY, BARO_UNSTABLE, BARO_THUNDERSTORM, BARO_UNKNOWN, BARO_CLOUDY_RAIN - - **updateCounter(value)**: *Function*. + - **updateCounter(value)**: *Function*. + - **updateCustomSensor(value)**: *Function*. - **updateDistance(distance)**: *Function*. - **updateElectricity(power, energy)**: *Function*. - **updateGas(usage)**: *Function*. diff --git a/dzVents/dzVents history.txt b/dzVents/dzVents history.txt index ae41110..37bfe1f 100644 --- a/dzVents/dzVents history.txt +++ b/dzVents/dzVents history.txt @@ -1,3 +1,6 @@ +[1.0.1] +* Added updateCustomSensor(value) method. + [1.0][1.0-beta2] * Deprecated setNew(). Use add() instead. You can now add multiple values at once in a script by calling multiple add()s in succession. * Fixed printing device logs when a value was boolean or nil diff --git a/dzVents/tests/testDevice.lua b/dzVents/tests/testDevice.lua index 23c176f..a0686d4 100644 --- a/dzVents/tests/testDevice.lua +++ b/dzVents/tests/testDevice.lua @@ -270,6 +270,11 @@ describe('device', function() assert.is_same({{["UpdateDevice"]="100|0|67"}}, commandArray) end) + it('should update a custom sensor', function() + device.updateCustomSensor(67) + assert.is_same({ { ["UpdateDevice"] = "100|0|67" } }, commandArray) + end) + it('should update dummy setpoint', function() device.hardwareTypeVal = 15 device.deviceSubType = 'SetPoint' From d3f8659657deff9ca974b6a05bc882f74772dc7b Mon Sep 17 00:00:00 2001 From: Danny Bloemendaal Date: Tue, 31 May 2016 21:24:52 +0200 Subject: [PATCH 2/2] fixed historical data --- dzVents/HistoricalStorage.lua | 4 +++- dzVents/dzVents history.txt | 1 + dzVents/tests/testEventHelpersStorage.lua | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dzVents/HistoricalStorage.lua b/dzVents/HistoricalStorage.lua index 45183df..f8dc49b 100644 --- a/dzVents/HistoricalStorage.lua +++ b/dzVents/HistoricalStorage.lua @@ -241,7 +241,9 @@ local function HistoricalStorage(data, maxItems, maxHours, maxMinutes, getData) end function self.reset() - self.storage = {} + for k, v in pairs(self.storage) do + self.storage[k] = nil + end self.size = 0 self.newData = nil end diff --git a/dzVents/dzVents history.txt b/dzVents/dzVents history.txt index 37bfe1f..a40887c 100644 --- a/dzVents/dzVents history.txt +++ b/dzVents/dzVents history.txt @@ -1,5 +1,6 @@ [1.0.1] * Added updateCustomSensor(value) method. +* Fixed reset() for historical data. [1.0][1.0-beta2] * Deprecated setNew(). Use add() instead. You can now add multiple values at once in a script by calling multiple add()s in succession. diff --git a/dzVents/tests/testEventHelpersStorage.lua b/dzVents/tests/testEventHelpersStorage.lua index d942b05..f303359 100644 --- a/dzVents/tests/testEventHelpersStorage.lua +++ b/dzVents/tests/testEventHelpersStorage.lua @@ -317,6 +317,7 @@ describe('event helper storage', function() hs.reset() assert.is_same(0, hs.size) assert.is_nil(hs.getLatest()) + assert.is_same({}, hs._getForStorage()) end) it('should return a subset', function()