Browse Source

module: add estimated risk level calculation based on UVA light intensity

- thresholds from vendor, take with a grain of salt as these are estimations
three
cn 9 months ago
parent
commit
1bdfe0e54a
2 changed files with 27 additions and 0 deletions
  1. +11
    -0
      tests/veml6070_test.py
  2. +16
    -0
      veml6070/veml6070.py

+ 11
- 0
tests/veml6070_test.py View File

@@ -90,6 +90,17 @@ class TestVeml6070(snapshottest.TestCase):
self.assertEqual(veml.get_uva_light_intensity(), 0x0106 * (0.1/0.1125) * 0.05 / 4)
self.assertMatchSnapshot(mockbus._log)

def test_get_estimated_risk_level(self):
mockbus = setup_mockbus(initial_read={
0x38+1: [0x01, 0x04],
0x38+0: [0x06, 0x01]
})
veml = veml6070.Veml6070()
intensity = veml.get_uva_light_intensity()
self.assertEqual(veml.get_estimated_risk_level(intensity), "low")
intensity = veml.get_uva_light_intensity()
self.assertEqual(veml.get_estimated_risk_level(intensity), "moderate")

def test_get_refresh_time(self):
mockbus = setup_mockbus()
veml = veml6070.Veml6070(rset=veml6070.RSET_240K)


+ 16
- 0
veml6070/veml6070.py View File

@@ -102,3 +102,19 @@ class Veml6070(object):
INTEGRATIONTIME_4T: 4
}
return self.rset * RSET_TO_REFRESHTIME_SCALE * case_refresh_it[self.integration_time]

@staticmethod
def get_estimated_risk_level(intensity):
"""
returns estimated risk level from comparing UVA light intensity value
in W/(m*m) as parameter, thresholds calculated from application notes
"""
if intensity < 24.888:
return "low"
if intensity < 49.800:
return "moderate"
if intensity < 66.400:
return "high"
if intensity < 91.288:
return "very high"
return "extreme"

Loading…
Cancel
Save