Exemplo n.º 1
0
def test_check_feeder_broker_connection(mocker):
    from feeder.util.feeder import check_connection

    class MockDevice(dict):
        gatewayHid = "gateway_hid"

    device = MockDevice()
    session = mocker.Mock()
    broker = mocker.Mock()
    broker._sessions = {"gateway_hid": (session, None)}
    session.return_value.transitions.is_connected.return_value = True
    results = check_connection(device=device, broker=broker)
    assert results["connected"]
Exemplo n.º 2
0
async def update_single_device(device_id: str, updated: DeviceUpdate):
    await KronosDevices.update(
        device_hid=device_id,
        name=updated.name,
        timezone=updated.timezone,
        front_button=updated.frontButton,
        recipe_id=updated.currentRecipe,
        black=updated.black,
    )
    devices = await KronosDevices.get(device_hid=device_id)
    device = devices[0]

    if updated.timezone is not None:
        try:
            timezone = pytz.timezone(updated.timezone)
            offset = int(
                datetime.datetime.now(timezone).utcoffset().total_seconds())
            await router.client.send_cmd_utc_offset(
                gateway_id=device.gatewayHid,
                device_id=device_id,
                utc_offset=offset)
        except pytz.exceptions.UnknownTimeZoneError:
            logger.exception("Unable to set timezone!")
            raise HTTPException(500, detail="Unknown timezone!")

    if updated.frontButton is not None:
        await router.client.send_cmd_button(
            gateway_id=device.gatewayHid,
            device_id=device_id,
            enable=updated.frontButton,
        )

    if updated.currentRecipe is not None:
        recipe_results = await StoredRecipe.get(recipe_id=updated.currentRecipe
                                                )
        if len(recipe_results) > 0:
            recipe = recipe_results[0]
            await router.client.send_cmd_budget(
                gateway_id=device.gatewayHid,
                device_id=device_id,
                recipe_id=recipe.id,
                tbsp_per_feeding=recipe.tbsp_per_feeding,
                g_per_tbsp=recipe.g_per_tbsp,
                budget_tbsp=recipe.budget_tbsp,
            )

    return check_connection(device, router.broker)
Exemplo n.º 3
0
async def get_single_device(device_id: str):
    device = [
        check_connection(device, router.broker)
        for device in await KronosDevices.get(device_hid=device_id)
    ]
    return device[0]
Exemplo n.º 4
0
async def get_devices():
    return [
        check_connection(device, router.broker) for device in await KronosDevices.get()
    ]