Skip to content

Commit

Permalink
Make sure internal devices' values are numeric not boolean, close #755
Browse files Browse the repository at this point in the history
  • Loading branch information
bennuttall committed Sep 20, 2019
1 parent 5a1f42f commit 4fbb040
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions gpiozero/internal_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def host(self):
@property
def value(self):
"""
Returns :data:`True` if the host returned a single ping, and
:data:`False` otherwise.
Returns :data:`1` if the host returned a single ping, and :data:`0`
otherwise.
"""
# XXX This is doing a DNS lookup every time it's queried; should we
# call gethostbyname in the constructor and ping that instead (good
Expand All @@ -124,9 +124,9 @@ def value(self):
['ping', '-c1', self.host],
stdout=devnull, stderr=devnull)
except subprocess.CalledProcessError:
return False
return 0
else:
return True
return 1


class CPUTemperature(InternalDevice):
Expand Down Expand Up @@ -414,18 +414,17 @@ def utc(self):
@property
def value(self):
"""
Returns :data:`True` when the system clock reads between
:attr:`start_time` and :attr:`end_time`, and :data:`False` otherwise.
If :attr:`start_time` is greater than :attr:`end_time` (indicating a
period that crosses midnight), then this returns :data:`True` when the
current time is greater than :attr:`start_time` or less than
:attr:`end_time`.
Returns :data:`1` when the system clock reads between :attr:`start_time`
and :attr:`end_time`, and :data:`0` otherwise. If :attr:`start_time` is
greater than :attr:`end_time` (indicating a period that crosses
midnight), then this returns :data:`True` when the current time is

This comment has been minimized.

Copy link
@lurch

lurch Sep 20, 2019

Contributor

Still says True here instead of 1

This comment has been minimized.

Copy link
@bennuttall

bennuttall Sep 20, 2019

Author Member

Good spot - fixed

greater than :attr:`start_time` or less than :attr:`end_time`.
"""
now = datetime.utcnow().time() if self.utc else datetime.now().time()
if self.start_time < self.end_time:
return self.start_time <= now <= self.end_time
return int(self.start_time <= now <= self.end_time)
else:
return not self.end_time < now < self.start_time
return int(not self.end_time < now < self.start_time)


class DiskUsage(InternalDevice):
Expand Down

0 comments on commit 4fbb040

Please sign in to comment.