Beispiel #1
0
def test_get_devices():
    devices = [
        b'(2345678',
        b'(2345679',
        b'12345678',
        b'12345678'
    ]
    owi = Owi(board.PIN_LED)
    assert owi.get_devices() == devices
Beispiel #2
0
def test_get_temperature():
    ds18b20 = Ds18b20(Owi(board.PIN_LED))
    assert ds18b20.get_temperature(b'\x282345678') == 22.0
Beispiel #3
0
def test_get_devices():
    ds18b20 = Ds18b20(Owi(board.PIN_LED))
    assert ds18b20.get_devices() == [b'\x282345678', b'\x282345679']
Beispiel #4
0
def test_convert():
    ds18b20 = Ds18b20(Owi(board.PIN_LED))
    assert ds18b20.convert() == None
Beispiel #5
0
def test_print():
    print(Ds18b20)
    help(Ds18b20)
    ds18b20 = Ds18b20(Owi(board.PIN_LED))
    print(ds18b20)
Beispiel #6
0
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# This file is part of the Pumbaa project.
#

import binascii
import board
from drivers import Ds18b20, Owi

OWI = Owi(board.PIN_GPIO17)
DS18B20 = Ds18b20(OWI)

# Search for devices on the OWI bus.
print('Number of sensors:', OWI.search())

while True:
    # Taking a new temperature sample.
    DS18B20.convert()

    for device_id in DS18B20.get_devices():
        print('Device id: {}, Temperature: {}'.format(
            binascii.hexlify(device_id), DS18B20.get_temperature(device_id)))
Beispiel #7
0
def test_bad_arguments():
    # Bad pin device.
    with assert_raises(ValueError, "bad pin device"):
        Owi(-1)
Beispiel #8
0
def test_write():
    owi = Owi(board.PIN_LED)
    assert owi.write(b'23') == 2
    assert owi.write(b'23', 1) == 1
Beispiel #9
0
def test_read():
    owi = Owi(board.PIN_LED)
    assert owi.read(2) == b'12'
Beispiel #10
0
def test_get_devices():
    owi = Owi(board.PIN_LED)
    assert owi.get_devices() == [b'12345678']
Beispiel #11
0
def test_search():
    owi = Owi(board.PIN_LED)
    assert owi.search() == 1
Beispiel #12
0
def test_reset():
    owi = Owi(board.PIN_LED)
    assert owi.reset() is None
Beispiel #13
0
def test_print():
    print(Owi)
    help(Owi)
    owi = Owi(board.PIN_LED)
    print(owi)
Beispiel #14
0
def test_write():
    owi_stub.set_write([b'23', b'2'])

    owi = Owi(board.PIN_LED)
    assert owi.write(b'23') == 2
    assert owi.write(b'23', 1) == 1
Beispiel #15
0
def test_read():
    owi_stub.set_read(b'12')

    owi = Owi(board.PIN_LED)
    assert owi.read(2) == b'12'