|
| 1 | +# coding=utf-8 |
| 2 | +import copy |
| 3 | +import time |
| 4 | + |
| 5 | +from mycodo.inputs.base_input import AbstractInput |
| 6 | + |
| 7 | +# Measurements |
| 8 | +measurements_dict = { |
| 9 | + 0: { |
| 10 | + 'measurement': 'light', |
| 11 | + 'unit': 'lux' |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +# Input information |
| 16 | +INPUT_INFORMATION = { |
| 17 | + 'input_name_unique': 'VEML7700', |
| 18 | + 'input_manufacturer': 'VISHAY', |
| 19 | + 'input_name': 'VEML7700', |
| 20 | + 'input_library': 'adafruit-circuitpython-veml7700', |
| 21 | + 'measurements_name': 'Light', |
| 22 | + 'measurements_dict': measurements_dict, |
| 23 | + 'url_datasheet': 'https://www.vishay.com/docs/84286/veml7700.pdf', |
| 24 | + 'url_product_purchase': 'https://www.adafruit.com/product/4162', |
| 25 | + |
| 26 | + 'options_enabled': [ |
| 27 | + 'i2c_location', |
| 28 | + 'period', |
| 29 | + 'pre_output' |
| 30 | + ], |
| 31 | + 'options_disabled': ['interface'], |
| 32 | + |
| 33 | + 'dependencies_module': [ |
| 34 | + ('pip-pypi', 'usb.core', 'pyusb==1.1.1'), |
| 35 | + ('pip-pypi', 'adafruit_extended_bus', 'Adafruit-extended-bus==1.0.2'), |
| 36 | + ('pip-pypi', 'adafruit_veml7700', 'adafruit-circuitpython-veml7700==2.2.0') |
| 37 | + ], |
| 38 | + |
| 39 | + 'interfaces': ['I2C'], |
| 40 | + 'i2c_location': ['0x10'], |
| 41 | + 'i2c_address_editable': False |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +class InputModule(AbstractInput): |
| 47 | + """A sensor support class that monitors the DS18B20's lux.""" |
| 48 | + def __init__(self, input_dev, testing=False): |
| 49 | + super().__init__(input_dev, testing=testing, name=__name__) |
| 50 | + |
| 51 | + self.sensor = None |
| 52 | + |
| 53 | + if not testing: |
| 54 | + self.try_initialize() |
| 55 | + |
| 56 | + def initialize(self): |
| 57 | + import adafruit_veml7700 |
| 58 | + from adafruit_extended_bus import ExtendedI2C |
| 59 | + |
| 60 | + self.sensor = adafruit_veml7700.VEML7700( |
| 61 | + ExtendedI2C(self.input_dev.i2c_bus), |
| 62 | + address=int(str(self.input_dev.i2c_location), 16)) |
| 63 | + |
| 64 | + @property |
| 65 | + def lux(self): |
| 66 | + """VEML7700 luminosity in lux.""" |
| 67 | + if self._measurements is None: # update if needed |
| 68 | + self.read() |
| 69 | + return self._measurements |
| 70 | + |
| 71 | + def get_measurement(self): |
| 72 | + """Gets the VEML7700's lux.""" |
| 73 | + self.return_dict = copy.deepcopy(measurements_dict) |
| 74 | + |
| 75 | + lux = self.sensor.light |
| 76 | + |
| 77 | + self.value_set(0, lux) |
| 78 | + |
| 79 | + return self.return_dict |
0 commit comments