Skip to content

Update Functions To Use @property & setter Structure #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions adafruit_veml6070.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@ def read(self):

return uvi

def set_ack(self, new_ack=False):
@property
def ack(self):
"""
Turns on or off the ACKnowledge function of the sensor. The ACK function will send
a signal to the host when the value of the sensed UV light changes beyond the
programmed threshold. Use ``[veml6070].set_ack_threshold`` to change between the two
available threshold settings.
programmed threshold.
"""
return self._ack

@ack.setter
def ack(self, new_ack=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the default value since its a setter.

if new_ack not in (True, False):
raise ValueError("ACK must be 'True' or 'False'.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced with a new_ack = bool(new_ack) because python's truthiness is broader than the bool type. For example, empty list is False. https://docs.python.org/3/library/stdtypes.html#truth-value-testing

self._ack = int(new_ack)
Expand All @@ -176,12 +180,17 @@ def set_ack(self, new_ack=False):
with self.i2c_cmd as i2c_cmd:
i2c_cmd.write(self.buf)

def set_ack_threshold(self, new_ack_thd=0):
@property
def ack_threshold(self):
"""
Sets the ACKnowledge Threshold, which alerts the host controller to value changes
The ACKnowledge Threshold, which alerts the host controller to value changes
greater than the threshold. Available settings are: ``0`` = 102 steps; ``1`` = 145 steps.
``0`` is the default setting.
"""
return self._ack_thd

@ack_threshold.setter
def ack_threshold(self, new_ack_thd=0):
if new_ack_thd not in (0, 1):
raise ValueError("ACK Threshold must be '0' or '1'.")
self._ack_thd = int(new_ack_thd)
Expand All @@ -190,14 +199,18 @@ def set_ack_threshold(self, new_ack_thd=0):
with self.i2c_cmd as i2c_cmd:
i2c_cmd.write(self.buf)


def set_integration_time(self, new_it):
@property
def integration_time(self):
"""
Sets the Integration Time of the sensor. This is the refresh interval of the
The Integration Time of the sensor, which is the refresh interval of the
sensor. The higher the refresh interval, the more accurate the reading is (at
the cost of less sampling). The available settings are: ``VEML6070_HALF_T``,
``VEML6070_1_T``, ``VEML6070_2_T``, ``VEML6070_4_T``.
"""
return self._it

@integration_time.setter
def integration_time(self, new_it):
if new_it not in _VEML6070_INTEGRATION_TIME:
raise ValueError("Integration Time invalid. Valid values are: ",
_VEML6070_INTEGRATION_TIME.keys())
Expand Down