Пример #1
0
def test_measure_get_meas(withings_api: WithingsApi) -> None:
    """Test function."""
    responses_add_measure_get_meas()
    assert withings_api.measure_get_meas() == MeasureGetMeasResponse(
        more=False,
        offset=0,
        timezone=TIMEZONE0,
        updatetime=arrow.get(1409596058).to(TIMEZONE0),
        measuregrps=(
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.
                MANUAL_USER_DURING_ACCOUNT_CREATION,
                category=MeasureGetMeasGroupCategory.REAL,
                created=arrow.get(1111111111).to(TIMEZONE0),
                date=arrow.get("2019-01-01").to(TIMEZONE0),
                deviceid="dev1",
                grpid=1,
                measures=(
                    MeasureGetMeasMeasure(type=MeasureType.HEIGHT,
                                          unit=110,
                                          value=110),
                    MeasureGetMeasMeasure(type=MeasureType.WEIGHT,
                                          unit=120,
                                          value=120),
                ),
            ),
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.
                DEVICE_ENTRY_FOR_USER_AMBIGUOUS,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(2222222222).to(TIMEZONE0),
                date=arrow.get("2019-01-02").to(TIMEZONE0),
                deviceid="dev2",
                grpid=2,
                measures=(
                    MeasureGetMeasMeasure(type=MeasureType.BODY_TEMPERATURE,
                                          unit=210,
                                          value=210),
                    MeasureGetMeasMeasure(type=MeasureType.BONE_MASS,
                                          unit=220,
                                          value=220),
                ),
            ),
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.UNKNOWN,
                category=MeasureGetMeasGroupCategory.UNKNOWN,
                created=arrow.get(2222222222).to(TIMEZONE0),
                date=arrow.get("2019-01-02").to(TIMEZONE0),
                deviceid="dev2",
                grpid=2,
                measures=(MeasureGetMeasMeasure(type=MeasureType.UNKNOWN,
                                                unit=230,
                                                value=230), ),
            ),
        ),
    )
Пример #2
0
def test_get_measure_value() -> None:
    """Test function."""
    response: Final = MeasureGetMeasResponse(
        offset=0,
        more=False,
        timezone=TIMEZONE0,
        updatetime=arrow.get(100000),
        measuregrps=(MeasureGetMeasGroup(
            attrib=MeasureGetMeasGroupAttrib.
            MANUAL_USER_DURING_ACCOUNT_CREATION,
            category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
            created=arrow.utcnow(),
            date=arrow.utcnow(),
            deviceid="dev1",
            grpid=1,
            measures=(
                MeasureGetMeasMeasure(type=MeasureType.WEIGHT,
                                      unit=1,
                                      value=10),
                MeasureGetMeasMeasure(type=MeasureType.BONE_MASS,
                                      unit=-2,
                                      value=20),
            ),
        ), ),
    )

    assert get_measure_value(response, MeasureType.BODY_TEMPERATURE) is None

    assert get_measure_value(response.measuregrps,
                             MeasureType.BODY_TEMPERATURE) is None

    assert (get_measure_value(response.measuregrps[0],
                              MeasureType.BODY_TEMPERATURE) is None)

    assert get_measure_value(response, MeasureType.WEIGHT) == 100
    assert get_measure_value(response.measuregrps, MeasureType.WEIGHT) == 100
    assert get_measure_value(response.measuregrps[0],
                             MeasureType.WEIGHT) == 100

    assert get_measure_value(response, MeasureType.BONE_MASS) == 0.2
    assert get_measure_value(response.measuregrps,
                             MeasureType.BONE_MASS) == 0.2
    assert get_measure_value(response.measuregrps[0],
                             MeasureType.BONE_MASS) == 0.2
Пример #3
0
 MeasureGetMeasGroup(
     attrib=MeasureGetMeasGroupAttrib.DEVICE_ENTRY_FOR_USER,
     category=MeasureGetMeasGroupCategory.REAL,
     created=time.time(),
     date=time.time(),
     deviceid="DEV_ID",
     grpid=1,
     measures=(
         MeasureGetMeasMeasure(type=MeasureType.WEIGHT,
                               unit=0,
                               value=70),
         MeasureGetMeasMeasure(type=MeasureType.FAT_MASS_WEIGHT,
                               unit=0,
                               value=5),
         MeasureGetMeasMeasure(type=MeasureType.FAT_FREE_MASS,
                               unit=0,
                               value=60),
         MeasureGetMeasMeasure(type=MeasureType.MUSCLE_MASS,
                               unit=0,
                               value=50),
         MeasureGetMeasMeasure(type=MeasureType.BONE_MASS,
                               unit=0,
                               value=10),
         MeasureGetMeasMeasure(type=MeasureType.HEIGHT,
                               unit=0,
                               value=2),
         MeasureGetMeasMeasure(type=MeasureType.TEMPERATURE,
                               unit=0,
                               value=40),
         MeasureGetMeasMeasure(type=MeasureType.BODY_TEMPERATURE,
                               unit=0,
                               value=40),
         MeasureGetMeasMeasure(type=MeasureType.SKIN_TEMPERATURE,
                               unit=0,
                               value=20),
         MeasureGetMeasMeasure(type=MeasureType.FAT_RATIO,
                               unit=-3,
                               value=70),
         MeasureGetMeasMeasure(
             type=MeasureType.DIASTOLIC_BLOOD_PRESSURE,
             unit=0,
             value=70),
         MeasureGetMeasMeasure(
             type=MeasureType.SYSTOLIC_BLOOD_PRESSURE,
             unit=0,
             value=100),
         MeasureGetMeasMeasure(type=MeasureType.HEART_RATE,
                               unit=0,
                               value=60),
         MeasureGetMeasMeasure(type=MeasureType.SP02,
                               unit=-2,
                               value=95),
         MeasureGetMeasMeasure(type=MeasureType.HYDRATION,
                               unit=-2,
                               value=95),
         MeasureGetMeasMeasure(type=MeasureType.PULSE_WAVE_VELOCITY,
                               unit=0,
                               value=100),
     ),
 ),
Пример #4
0
def test_query_measure_groups() -> None:
    """Test function."""
    response: Final = MeasureGetMeasResponse(
        offset=0,
        more=False,
        timezone=TIMEZONE0,
        updatetime=arrow.get(100000),
        measuregrps=(
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.MANUAL_USER_DURING_ACCOUNT_CREATION,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(10000200),
                date=arrow.get(10000300),
                deviceid="dev1",
                grpid=1,
                measures=(
                    MeasureGetMeasMeasure(type=MeasureType.WEIGHT, unit=1, value=10),
                    MeasureGetMeasMeasure(
                        type=MeasureType.BONE_MASS, unit=-2, value=20
                    ),
                ),
            ),
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.MEASURE_USER_CONFIRMED,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(10000400),
                date=arrow.get(10000500),
                deviceid="dev2",
                grpid=2,
                measures=(
                    MeasureGetMeasMeasure(
                        type=MeasureType.BONE_MASS, unit=21, value=210
                    ),
                    MeasureGetMeasMeasure(
                        type=MeasureType.FAT_FREE_MASS, unit=-22, value=220
                    ),
                ),
            ),
        ),
    )

    # Measure type filter.
    expected1: Final = tuple(
        [
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.MANUAL_USER_DURING_ACCOUNT_CREATION,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(10000200),
                date=arrow.get(10000300),
                deviceid="dev1",
                grpid=1,
                measures=(),
            ),
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.MEASURE_USER_CONFIRMED,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(10000400),
                date=arrow.get(10000500),
                deviceid="dev2",
                grpid=2,
                measures=(
                    MeasureGetMeasMeasure(
                        type=MeasureType.FAT_FREE_MASS, unit=-22, value=220
                    ),
                ),
            ),
        ]
    )
    assert query_measure_groups(response, MeasureType.FAT_FREE_MASS) == expected1

    expected2: Final = tuple(
        [
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.MEASURE_USER_CONFIRMED,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(10000400),
                date=arrow.get(10000500),
                deviceid="dev2",
                grpid=2,
                measures=(
                    MeasureGetMeasMeasure(
                        type=MeasureType.FAT_FREE_MASS, unit=-22, value=220
                    ),
                ),
            )
        ]
    )
    assert (
        query_measure_groups(
            response,
            MeasureType.FAT_FREE_MASS,
            MeasureGetMeasGroupAttrib.MEASURE_USER_CONFIRMED,
        )
        == expected2
    )

    expected3: Final = tuple(
        [
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.MANUAL_USER_DURING_ACCOUNT_CREATION,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(10000200),
                date=arrow.get(10000300),
                deviceid="dev1",
                grpid=1,
                measures=(
                    MeasureGetMeasMeasure(
                        type=MeasureType.BONE_MASS, unit=-2, value=20
                    ),
                ),
            ),
            MeasureGetMeasGroup(
                attrib=MeasureGetMeasGroupAttrib.MEASURE_USER_CONFIRMED,
                category=MeasureGetMeasGroupCategory.USER_OBJECTIVES,
                created=arrow.get(10000400),
                date=arrow.get(10000500),
                deviceid="dev2",
                grpid=2,
                measures=(
                    MeasureGetMeasMeasure(
                        type=MeasureType.BONE_MASS, unit=21, value=210
                    ),
                ),
            ),
        ]
    )
    assert query_measure_groups(response, MeasureType.BONE_MASS) == expected3

    # Group attrib filter.
    assert query_measure_groups(response) == response.measuregrps

    assert (
        query_measure_groups(response, MeasureTypes.ANY, MeasureGroupAttribs.ANY)
        == response.measuregrps
    )

    assert query_measure_groups(
        response, MeasureTypes.ANY, MeasureGroupAttribs.AMBIGUOUS
    ) == (response.measuregrps[0],)

    assert query_measure_groups(
        response, MeasureTypes.ANY, MeasureGroupAttribs.UNAMBIGUOUS
    ) == (response.measuregrps[1],)

    assert query_measure_groups(
        response, MeasureTypes.ANY, response.measuregrps[0].attrib
    ) == (response.measuregrps[0],)