Пример #1
0
async def test_heater_command():
    async def _req_cb(path, timeout):
        assert False

    async def _pub_cb(path, timeout):
        assert False

    async def _reg_rep_cb(path, callback):
        assert False

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    pwm = MockPWM()
    pwm.duty_cycle = 50
    pwm.frequency = 51

    pid = MockPID()
    heater = Heater(pwm, pid, 1000, bus)

    response = await heater.command_callback({'command': 'get'})
    assert response['status'] == 'ok'
    assert response['duty_cycle'] == 50
    assert response['frequency'] == 51

    response = await heater.command_callback({'command': 'put'})
    assert response['status'] == 'error'
Пример #2
0
async def test_refiller_command():
    async def _req_cb(path, data, timeout):
        assert False

    async def _pub_cb(path, data):
        assert False

    async def _reg_rep_cb(path, callback):
        assert False

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    pwm = MockPWM()
    pwm.duty_cycle = 50
    pwm.frequency = 51

    service = RefillService(pwm, 1000, bus)

    response = await service.command_callback({'command': 'get'})
    assert response['status'] == 'ok'
    assert response['stop'] is True

    response = await service.command_callback({'command': 'put'})
    assert response['status'] == 'error'

    response = await service.command_callback({'command': 'start'})
    assert response['status'] == 'ok'
    assert pwm._open is True
Пример #3
0
async def test_heater_start():
    async def _req_cb(path, timeout):
        assert False

    async def _pub_cb(path, timeout):
        assert False

    async def _reg_rep_cb(path, callback):
        assert path == 'tank.heater'

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    pwm = MockPWM()
    pid = MockPID()
    heater = Heater(pwm, pid, 1000, bus)

    loop = asyncio.get_event_loop()
    task = loop.create_task(heater.start())

    await asyncio.sleep(0.5)
    assert pwm._open is True
    assert pwm._start is True
    task.cancel()
Пример #4
0
async def test_refiller_start():
    async def _req_cb(path, data, timeout):
        assert path == 'tank.water'
        assert data['command'] == 'get'
        return {'status': 'ok', 'water': True}

    async def _pub_cb(path, timeout):
        assert False

    async def _reg_rep_cb(path, callback):
        assert path == 'tank.refill'

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    pwm = MockPWM()
    refiller = RefillService(pwm, 1000, bus)

    loop = asyncio.get_event_loop()
    task = loop.create_task(refiller.start())

    await asyncio.sleep(0.5)
    task.cancel()
async def test_tank_temp_service_pub():
    async def _req_cb(path, timeout):
        assert False

    async def _pub_cb(path, data):
        assert path == 'tank.temperature'
        assert data['status'] == 'ok'
        assert data['temperature'] == 100

    async def _reg_rep_cb(path, callback):
        assert False

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    sensor = MockTemperatureSensor()
    sensor.temp = 100
    service = TankTempService(sensor, 1000, bus)
    await service.pub_tank_temperature()
    assert sensor.is_connected() is True
Пример #6
0
async def test_tank_water_service_command():
    async def _req_cb(path, timeout):
        assert False

    async def _pub_cb(path, data):
        assert path == 'tank.water'
        assert data['status'] == 'ok'
        assert data['water'] is True

    async def _reg_rep_cb(path, callback):
        assert False

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    sensor = MockWaterDetector()
    sensor._is_water_full = True

    service = TankWaterService(sensor, 1000, bus)
    await service.pub_water_status()
    response = await service.rep_water_command({'command': 'get'})
    assert sensor.is_connected() is True
    assert response['status'] == 'ok'
    assert response['water'] is True
Пример #7
0
async def test_barista_start():
    async def _req_cb(path, timeout):
        assert False

    async def _pub_cb(path, timeout):
        assert False

    async def _reg_rep_cb(path, callback):
        assert path == 'barista'

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    pid = MockPID()
    pos = barista.WasteWaterPosition(x=0, y=0, z=0)
    b = barista.Barista(MovingDev(), ExtruderDev(), pid, pos, 5000, bus)

    loop = asyncio.get_event_loop()
    task = loop.create_task(b.start())
    response = await b.command_callback({'command': 'get'})
    assert response['status'] == 'ok'

    task.cancel()
Пример #8
0
async def test_barista_brew():
    async def _req_cb(path, data, timeout):
        if path == 'tank.refill':
            return {'status': 'ok'}
        if path == 'output.temperature':
            return {'status': 'ok', 'temperature': 50}

    async def _pub_cb(path, timeout):
        assert False

    async def _reg_rep_cb(path, callback):
        assert path == 'barista'

    async def _reg_sub_cb(path, callback):
        assert False

    bus = MockBus()
    bus.req_cb = _req_cb
    bus.pub_cb = _pub_cb
    bus.reg_rep_cb = _reg_rep_cb
    bus.reg_sub_cb = _reg_sub_cb

    pid = MockPID()
    moving = MovingDev()
    extruder = ExtruderDev()
    pos = barista.WasteWaterPosition(x=70, y=50, z=180)
    b = barista.Barista(moving, extruder, pid, pos, 5000, bus)

    await b.brew([{'type': 'command', 'name': 'home'}])
    assert len(moving.sent_commands) == 1
    assert moving.sent_commands[0] == 'G28'

    await b.brew([{'type': 'command', 'name': 'calibration'}])
    assert moving.sent_commands[0] == 'G28'
    assert moving.sent_commands[
        1] == 'G1 X70.00000 Y50.00000 Z180.00000 F5000.00000'