1
0
mirror of https://github.com/cmur2/python-veml6070.git synced 2024-12-21 14:54:23 +01:00

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

- thresholds from vendor, take with a grain of salt as these are estimations
This commit is contained in:
cn 2019-09-19 01:36:31 +02:00
parent 4eda08a9c9
commit 1bdfe0e54a
2 changed files with 27 additions and 0 deletions

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.assertEqual(veml.get_uva_light_intensity(), 0x0106 * (0.1/0.1125) * 0.05 / 4)
self.assertMatchSnapshot(mockbus._log) 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): def test_get_refresh_time(self):
mockbus = setup_mockbus() mockbus = setup_mockbus()
veml = veml6070.Veml6070(rset=veml6070.RSET_240K) veml = veml6070.Veml6070(rset=veml6070.RSET_240K)

View File

@ -102,3 +102,19 @@ class Veml6070(object):
INTEGRATIONTIME_4T: 4 INTEGRATIONTIME_4T: 4
} }
return self.rset * RSET_TO_REFRESHTIME_SCALE * case_refresh_it[self.integration_time] 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"