Skip to content

Commit 91e93b0

Browse files
committed
Ensure JamHat's on/off methods control the buzzer too
1 parent 023bce4 commit 91e93b0

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

gpiozero/boards.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,10 @@ class JamHat(CompositeOutputDevice):
18191819
18201820
hat = JamHat()
18211821
1822+
hat.button_1.wait_for_press()
18221823
hat.lights_1.on()
1823-
hat.buzzer.play(60)
1824-
1824+
hat.buzzer.play('C4')
1825+
hat.button_2.wait_for_press()
18251826
hat.off()
18261827
18271828
:param bool pwm:
@@ -1849,3 +1850,17 @@ def __init__(self, pwm=False, pin_factory=None):
18491850
_order=('lights_1', 'lights_2', 'button_1', 'button_2', 'buzzer'),
18501851
pin_factory=pin_factory
18511852
)
1853+
1854+
def on(self):
1855+
"""
1856+
Turns all the LEDs on and makes the buzzer play its mid tone.
1857+
"""
1858+
self.buzzer.value = 0
1859+
super(JamHat, self).on()
1860+
1861+
def off(self):
1862+
"""
1863+
Turns all the LEDs off and stops the buzzer.
1864+
"""
1865+
self.buzzer.value = None
1866+
super(JamHat, self).off()

tests/test_boards.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,17 +1379,33 @@ def test_jamhat(mock_factory, pwm):
13791379
assert isinstance(jh.buzzer, TonalBuzzer)
13801380
assert isinstance(jh.lights_1.red, LED)
13811381
assert jh.value == (
1382-
(False, False, False),
1383-
(False, False, False),
1384-
False, False,
1385-
None
1382+
(False, False, False), # lights_1
1383+
(False, False, False), # lights_2
1384+
False, False, # buttons
1385+
None # buzzer
13861386
)
13871387
jh.on()
13881388
assert jh.value == (
1389-
(True, True, True),
1390-
(True, True, True),
1391-
False, False,
1392-
None
1389+
(True, True, True), # lights_1
1390+
(True, True, True), # lights_2
1391+
False, False, # buttons
1392+
0 # buzzer
1393+
)
1394+
jh.buzzer.play('A5')
1395+
jh.button_1.pin.drive_high()
1396+
jh.button_2.pin.drive_high()
1397+
assert jh.value == (
1398+
(True, True, True), # lights_1
1399+
(True, True, True), # lights_2
1400+
True, True, # buttons
1401+
1 # buzzer
1402+
)
1403+
jh.off()
1404+
assert jh.value == (
1405+
(False, False, False), # lights_1
1406+
(False, False, False), # lights_2
1407+
True, True, # buttons
1408+
None # buzzer
13931409
)
13941410

13951411
def test_jamhat_pwm(mock_factory, pwm):
@@ -1400,3 +1416,23 @@ def test_jamhat_pwm(mock_factory, pwm):
14001416
assert isinstance(jh.button_1, Button)
14011417
assert isinstance(jh.button_2, Button)
14021418
assert isinstance(jh.buzzer, TonalBuzzer)
1419+
assert jh.value == (
1420+
(0, 0, 0), # lights_1
1421+
(0, 0, 0), # lights_2
1422+
False, False, # buttons
1423+
None # buzzer
1424+
)
1425+
jh.on()
1426+
assert jh.value == (
1427+
(1, 1, 1), # lights_1
1428+
(1, 1, 1), # lights_2
1429+
False, False, # buttons
1430+
0 # buzzer
1431+
)
1432+
jh.off()
1433+
assert jh.value == (
1434+
(0, 0, 0), # lights_1
1435+
(0, 0, 0), # lights_2
1436+
False, False, # buttons
1437+
None # buzzer
1438+
)

0 commit comments

Comments
 (0)