mirror of
https://github.com/pimoroni/grow-python
synced 2025-10-25 15:19:23 +00:00
Merge pull request #3 from pimoroni/patch-context
Add context to settings edit screen
This commit is contained in:
@@ -7,8 +7,8 @@ git:
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- python: "2.7"
|
- python: "3.7"
|
||||||
env: TOXENV=py27
|
env: TOXENV=py37
|
||||||
- python: "3.5"
|
- python: "3.5"
|
||||||
env: TOXENV=py35
|
env: TOXENV=py35
|
||||||
|
|
||||||
|
|||||||
@@ -400,6 +400,18 @@ class ChannelView(View):
|
|||||||
fill=(255, 255, 255),
|
fill=(255, 255, 255),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def draw_context(self, position, metric="Hz"):
|
||||||
|
context = f"Now: {self.channel.sensor.moisture:.2f}Hz"
|
||||||
|
if metric.lower() == "sat":
|
||||||
|
context = f"Now: {self.channel.sensor.saturation * 100:.2f}%"
|
||||||
|
|
||||||
|
self._draw.text(
|
||||||
|
position,
|
||||||
|
context,
|
||||||
|
font=self.font,
|
||||||
|
fill=(255, 255, 255),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DetailView(ChannelView):
|
class DetailView(ChannelView):
|
||||||
"""Single channel details.
|
"""Single channel details.
|
||||||
@@ -507,6 +519,7 @@ class ChannelEditView(ChannelView, EditView):
|
|||||||
"round": 2,
|
"round": 2,
|
||||||
"format": lambda value: f"{value * 100:0.2f}%",
|
"format": lambda value: f"{value * 100:0.2f}%",
|
||||||
"help": "Saturation at which alarm is triggered",
|
"help": "Saturation at which alarm is triggered",
|
||||||
|
"context": "sat",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Enabled",
|
"title": "Enabled",
|
||||||
@@ -525,6 +538,7 @@ class ChannelEditView(ChannelView, EditView):
|
|||||||
"round": 2,
|
"round": 2,
|
||||||
"format": lambda value: f"{value:0.2f}Hz",
|
"format": lambda value: f"{value:0.2f}Hz",
|
||||||
"help": "Frequency for fully saturated soil",
|
"help": "Frequency for fully saturated soil",
|
||||||
|
"context": "hz",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Dry Point",
|
"title": "Dry Point",
|
||||||
@@ -536,6 +550,7 @@ class ChannelEditView(ChannelView, EditView):
|
|||||||
"round": 2,
|
"round": 2,
|
||||||
"format": lambda value: f"{value:0.2f}Hz",
|
"format": lambda value: f"{value:0.2f}Hz",
|
||||||
"help": "Frequency for fully dried soil",
|
"help": "Frequency for fully dried soil",
|
||||||
|
"context": "hz",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
EditView.__init__(self, image, options)
|
EditView.__init__(self, image, options)
|
||||||
@@ -546,6 +561,10 @@ class ChannelEditView(ChannelView, EditView):
|
|||||||
|
|
||||||
EditView.render(self)
|
EditView.render(self)
|
||||||
|
|
||||||
|
option = self._options[self._current_option]
|
||||||
|
if "context" in option:
|
||||||
|
self.draw_context((34, 6), option["context"])
|
||||||
|
|
||||||
|
|
||||||
class Channel:
|
class Channel:
|
||||||
colors = [
|
colors = [
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[run]
|
[run]
|
||||||
source = enviroplus
|
source = grow
|
||||||
omit =
|
omit =
|
||||||
.tox/*
|
.tox/*
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ You should read the following to get up and running with our monitoring script:
|
|||||||
* Discord - https://discord.gg/hr93ByC
|
* Discord - https://discord.gg/hr93ByC
|
||||||
|
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
0.0.1
|
0.0.1
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|||||||
@@ -80,4 +80,3 @@ class Pump(object):
|
|||||||
self.set_speed(speed)
|
self.set_speed(speed)
|
||||||
self._timeout.start()
|
self._timeout.start()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +1,47 @@
|
|||||||
|
import mock
|
||||||
|
|
||||||
|
|
||||||
def test_moisture_setup(GPIO, smbus):
|
def test_moisture_setup(GPIO, smbus):
|
||||||
from grow import moisture
|
from grow.moisture import Moisture
|
||||||
moisture._is_setup = False
|
|
||||||
|
|
||||||
moisture.setup()
|
ch1 = Moisture(channel=1)
|
||||||
moisture.setup()
|
ch2 = Moisture(channel=2)
|
||||||
|
ch3 = Moisture(channel=3)
|
||||||
|
|
||||||
|
assert GPIO.setup.has_calls([
|
||||||
|
mock.call(ch1._gpio_pin, GPIO.IN),
|
||||||
|
mock.call(ch2._gpio_pin, GPIO.IN),
|
||||||
|
mock.call(ch3._gpio_pin, GPIO.IN)
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_moisture_read_all(GPIO, smbus):
|
def test_moisture_read(GPIO, smbus):
|
||||||
from grow import moisture
|
from grow.moisture import Moisture
|
||||||
moisture._is_setup = False
|
|
||||||
|
|
||||||
result = moisture.read_all()
|
assert Moisture(channel=1).saturation == 1.0
|
||||||
|
assert Moisture(channel=2).saturation == 1.0
|
||||||
|
assert Moisture(channel=3).saturation == 1.0
|
||||||
|
|
||||||
assert type(result(1)) == float
|
assert Moisture(channel=1).moisture == 0
|
||||||
assert int(result(1)) == 100
|
assert Moisture(channel=2).moisture == 0
|
||||||
|
assert Moisture(channel=3).moisture == 0
|
||||||
|
|
||||||
assert type(result(2)) == float
|
|
||||||
assert int(result(2)) == 500
|
|
||||||
|
|
||||||
assert type(result.(3)) == float
|
|
||||||
assert int(result.(3)) == 5000
|
|
||||||
|
|
||||||
assert "Moisture" in str(result)
|
|
||||||
|
|
||||||
|
|
||||||
def test_moisture_read_each(GPIO, smbus):
|
|
||||||
from grow import moisture
|
|
||||||
moisture._is_setup = False
|
|
||||||
|
|
||||||
assert int(moisture.read(1)) == 100
|
|
||||||
assert int(moisture.read(2)) == 500
|
|
||||||
assert int(moisture.read(3)) == 5000
|
|
||||||
|
|
||||||
|
|
||||||
def test_moisture_cleanup(GPIO, smbus):
|
|
||||||
from grow import moisture
|
|
||||||
moisture.cleanup()
|
|
||||||
|
|
||||||
GPIO.input.assert_called_with(moisture.MOISTURE_1_PIN, 0)
|
|
||||||
GPIO.input.assert_called_with(moisture.MOISTURE_2_PIN, 0)
|
|
||||||
GPIO.input.assert_called_with(moisture.MOISTURE_3_PIN, 0)
|
|
||||||
|
|
||||||
def test_pump_setup(GPIO, smbus):
|
def test_pump_setup(GPIO, smbus):
|
||||||
from grow import pump
|
from grow.pump import Pump, PUMP_PWM_FREQ
|
||||||
moisture._is_setup = False
|
|
||||||
moisture.setup()
|
|
||||||
moisture.setup()
|
|
||||||
|
|
||||||
def test_pump_cleanup(GPIO, smbus):
|
ch1 = Pump(channel=1)
|
||||||
from grow import pump
|
ch2 = Pump(channel=2)
|
||||||
pump.cleanup()
|
ch3 = Pump(channel=3)
|
||||||
|
|
||||||
GPIO.input.assert_called_with(moisture.PUMP_1_PIN, 0)
|
assert GPIO.setup.has_calls([
|
||||||
GPIO.input.assert_called_with(moisture.PUMP_2_PIN, 0)
|
mock.call(ch1._gpio_pin, GPIO.OUT, initial=GPIO.LOW),
|
||||||
GPIO.input.assert_called_with(moisture.PUMP_3_PIN, 0)
|
mock.call(ch2._gpio_pin, GPIO.OUT, initial=GPIO.LOW),
|
||||||
|
mock.call(ch3._gpio_pin, GPIO.OUT, initial=GPIO.LOW)
|
||||||
|
])
|
||||||
|
|
||||||
|
assert GPIO.PWM.has_calls([
|
||||||
|
mock.call(ch1._gpio_pin, PUMP_PWM_FREQ),
|
||||||
|
mock.call(ch2._gpio_pin, PUMP_PWM_FREQ),
|
||||||
|
mock.call(ch3._gpio_pin, PUMP_PWM_FREQ)
|
||||||
|
])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = py{27,35},qa
|
envlist = py{35,37},qa
|
||||||
skip_missing_interpreters = True
|
skip_missing_interpreters = True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
@@ -14,11 +14,11 @@ deps =
|
|||||||
|
|
||||||
[testenv:qa]
|
[testenv:qa]
|
||||||
commands =
|
commands =
|
||||||
check-manifest --ignore tox.ini,tests*,.coveragerc
|
check-manifest --ignore tox.ini,tests/*,.coveragerc
|
||||||
python setup.py check -m -r -s
|
python setup.py sdist bdist_wheel
|
||||||
|
twine check dist/*
|
||||||
flake8 --ignore E501
|
flake8 --ignore E501
|
||||||
rstcheck README.rst
|
|
||||||
deps =
|
deps =
|
||||||
check-manifest
|
check-manifest
|
||||||
flake8
|
flake8
|
||||||
rstcheck
|
twine
|
||||||
|
|||||||
Reference in New Issue
Block a user