Skip to content

Commit f77bc64

Browse files
authored
Merge pull request #5 from sommersoft/prop_set
Update Functions To Use @Property & setter Structure
2 parents 13f6407 + e38ca19 commit f77bc64

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

adafruit_veml6070.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def __init__(self, i2c_bus, _veml6070_it="VEML6070_1_T", ack=False):
144144
i2c_cmd.write(self.buf)
145145

146146

147-
148147
@property
149148
def read(self):
150149
"""
@@ -161,27 +160,36 @@ def read(self):
161160

162161
return uvi
163162

164-
def set_ack(self, new_ack=False):
163+
@property
164+
def ack(self):
165165
"""
166166
Turns on or off the ACKnowledge function of the sensor. The ACK function will send
167167
a signal to the host when the value of the sensed UV light changes beyond the
168-
programmed threshold. Use ``[veml6070].set_ack_threshold`` to change between the two
169-
available threshold settings.
168+
programmed threshold.
170169
"""
171-
if new_ack not in (True, False):
170+
return self._ack
171+
172+
@ack.setter
173+
def ack(self, new_ack):
174+
if new_ack != bool(new_ack):
172175
raise ValueError("ACK must be 'True' or 'False'.")
173176
self._ack = int(new_ack)
174177
self.buf[0] = (self._ack << 5 | self._ack_thd << 4 |
175178
_VEML6070_INTEGRATION_TIME[self._it][0] << 2 | 0x02)
176179
with self.i2c_cmd as i2c_cmd:
177180
i2c_cmd.write(self.buf)
178181

179-
def set_ack_threshold(self, new_ack_thd=0):
182+
@property
183+
def ack_threshold(self):
180184
"""
181-
Sets the ACKnowledge Threshold, which alerts the host controller to value changes
185+
The ACKnowledge Threshold, which alerts the host controller to value changes
182186
greater than the threshold. Available settings are: ``0`` = 102 steps; ``1`` = 145 steps.
183187
``0`` is the default setting.
184188
"""
189+
return self._ack_thd
190+
191+
@ack_threshold.setter
192+
def ack_threshold(self, new_ack_thd):
185193
if new_ack_thd not in (0, 1):
186194
raise ValueError("ACK Threshold must be '0' or '1'.")
187195
self._ack_thd = int(new_ack_thd)
@@ -190,14 +198,18 @@ def set_ack_threshold(self, new_ack_thd=0):
190198
with self.i2c_cmd as i2c_cmd:
191199
i2c_cmd.write(self.buf)
192200

193-
194-
def set_integration_time(self, new_it):
201+
@property
202+
def integration_time(self):
195203
"""
196-
Sets the Integration Time of the sensor. This is the refresh interval of the
204+
The Integration Time of the sensor, which is the refresh interval of the
197205
sensor. The higher the refresh interval, the more accurate the reading is (at
198206
the cost of less sampling). The available settings are: ``VEML6070_HALF_T``,
199207
``VEML6070_1_T``, ``VEML6070_2_T``, ``VEML6070_4_T``.
200208
"""
209+
return self._it
210+
211+
@integration_time.setter
212+
def integration_time(self, new_it):
201213
if new_it not in _VEML6070_INTEGRATION_TIME:
202214
raise ValueError("Integration Time invalid. Valid values are: ",
203215
_VEML6070_INTEGRATION_TIME.keys())

0 commit comments

Comments
 (0)