From 5cf6d2aad5bbfd2cc30c1e428d5bc1e4d325c649 Mon Sep 17 00:00:00 2001 From: cn Date: Wed, 18 Sep 2019 22:11:53 +0200 Subject: [PATCH] module: respect shutdown settings when writing command - this fixes a serious flaw where until now this library never powered the sensor down - not noticable directly as the sensor still takes measurements but wastes power in between --- README.md | 6 + tests/snapshots/snap_veml6070_test.py | 254 +++++++++++++------------- veml6070/veml6070.py | 2 +- 3 files changed, 134 insertions(+), 128 deletions(-) diff --git a/README.md b/README.md index edb2f6c..7eb2d8b 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ Consult the [datasheet](https://www.vishay.com/docs/84277/veml6070.pdf), the [ap Not all functions of the chip are supported, especially not the interrupt handling since I had no use for this. Please send pull requests for improvements and bug fixes! +## Serious Flaws before September 2019 + +In September 2019 it was discovered (and fixed) that: + +- previously the sensor was never shutdown between measurements which wastes power but still takes measurements successfully + ## License Python files in this repository are released under the [MIT license](LICENSE). diff --git a/tests/snapshots/snap_veml6070_test.py b/tests/snapshots/snap_veml6070_test.py index bcd13e0..0413a4c 100644 --- a/tests/snapshots/snap_veml6070_test.py +++ b/tests/snapshots/snap_veml6070_test.py @@ -7,6 +7,131 @@ from snapshottest import Snapshot snapshots = Snapshot() +snapshots['TestVeml6070::test_disable 1'] = [ + ( + 'w', + 56, + 6 + ), + ( + 'w', + 56, + 7 + ), + ( + 'w', + 56, + 7 + ) +] + +snapshots['TestVeml6070::test_enable 1'] = [ + ( + 'w', + 56, + 6 + ), + ( + 'w', + 56, + 7 + ), + ( + 'w', + 56, + 6 + ) +] + +snapshots['TestVeml6070::test_integration_time 1'] = [ + ( + 'w', + 56, + 2 + ), + ( + 'w', + 56, + 3 + ), + ( + 'w', + 56, + 15 + ) +] + +snapshots['TestVeml6070::test_setup 1'] = [ + ( + 'w', + 56, + 6 + ), + ( + 'w', + 56, + 7 + ) +] + +snapshots['TestVeml6070::test_uva_light_intensity 1'] = [ + ( + 'w', + 56, + 6 + ), + ( + 'w', + 56, + 7 + ), + ( + 'w', + 56, + 6 + ), + ( + 'r', + 57, + 1 + ), + ( + 'r', + 56, + 6 + ), + ( + 'w', + 56, + 7 + ), + ( + 'w', + 56, + 15 + ), + ( + 'w', + 56, + 14 + ), + ( + 'r', + 57, + 1 + ), + ( + 'r', + 56, + 6 + ), + ( + 'w', + 56, + 15 + ) +] + snapshots['TestVeml6070::test_uva_light_intensity_raw 1'] = [ ( 'w', @@ -16,7 +141,7 @@ snapshots['TestVeml6070::test_uva_light_intensity_raw 1'] = [ ( 'w', 56, - 6 + 7 ), ( 'w', @@ -36,131 +161,6 @@ snapshots['TestVeml6070::test_uva_light_intensity_raw 1'] = [ ( 'w', 56, - 6 - ) -] - -snapshots['TestVeml6070::test_disable 1'] = [ - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ) -] - -snapshots['TestVeml6070::test_enable 1'] = [ - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ) -] - -snapshots['TestVeml6070::test_integration_time 1'] = [ - ( - 'w', - 56, - 2 - ), - ( - 'w', - 56, - 2 - ), - ( - 'w', - 56, - 14 - ) -] - -snapshots['TestVeml6070::test_setup 1'] = [ - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ) -] - -snapshots['TestVeml6070::test_uva_light_intensity 1'] = [ - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ), - ( - 'r', - 57, - 1 - ), - ( - 'r', - 56, - 6 - ), - ( - 'w', - 56, - 6 - ), - ( - 'w', - 56, - 14 - ), - ( - 'w', - 56, - 14 - ), - ( - 'r', - 57, - 1 - ), - ( - 'r', - 56, - 6 - ), - ( - 'w', - 56, - 14 + 7 ) ] diff --git a/veml6070/veml6070.py b/veml6070/veml6070.py index 2f0f43c..beb83bc 100644 --- a/veml6070/veml6070.py +++ b/veml6070/veml6070.py @@ -64,7 +64,7 @@ class Veml6070(object): assembles the command byte for the current state """ cmd = (self.shutdown & 0x01) << 0 # SD - cmd = (self.integration_time & 0x03) << 2 # IT + cmd = cmd | (self.integration_time & 0x03) << 2 # IT cmd = ((cmd | 0x02) & 0x3F) # reserved bits return cmd