def new_profile_config( profile: str, user_id: int, api_response_user_get_device: UserGetDeviceResponse | Exception | None = None, api_response_measure_get_meas: MeasureGetMeasResponse | Exception | None = None, api_response_sleep_get_summary: SleepGetSummaryResponse | Exception | None = None, api_response_notify_list: NotifyListResponse | Exception | None = None, api_response_notify_revoke: Exception | None = None, ) -> ProfileConfig: """Create a new profile config immutable object.""" return ProfileConfig( profile=profile, user_id=user_id, api_response_user_get_device=api_response_user_get_device or UserGetDeviceResponse(devices=[]), api_response_measure_get_meas=api_response_measure_get_meas or MeasureGetMeasResponse( measuregrps=[], more=False, offset=0, timezone=dt_util.UTC, updatetime=arrow.get(12345), ), api_response_sleep_get_summary=api_response_sleep_get_summary or SleepGetSummaryResponse(more=False, offset=0, series=[]), api_response_notify_list=api_response_notify_list or NotifyListResponse(profiles=[]), api_response_notify_revoke=api_response_notify_revoke, )
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), ), ), ), )
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
api_response_measure_get_meas=MeasureGetMeasResponse( measuregrps=( 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), ), ), MeasureGetMeasGroup( attrib=MeasureGetMeasGroupAttrib. DEVICE_ENTRY_FOR_USER_AMBIGUOUS, category=MeasureGetMeasGroupCategory.REAL, created=time.time(), date=time.time(), deviceid="DEV_ID", grpid=1, measures=( MeasureGetMeasMeasure(type=MeasureType.WEIGHT, unit=0, value=71), MeasureGetMeasMeasure(type=MeasureType.FAT_MASS_WEIGHT, unit=0, value=4), MeasureGetMeasMeasure(type=MeasureType.FAT_FREE_MASS, unit=0, value=40), MeasureGetMeasMeasure(type=MeasureType.MUSCLE_MASS, unit=0, value=51), MeasureGetMeasMeasure(type=MeasureType.BONE_MASS, unit=0, value=11), MeasureGetMeasMeasure(type=MeasureType.HEIGHT, unit=0, value=201), MeasureGetMeasMeasure(type=MeasureType.TEMPERATURE, unit=0, value=41), MeasureGetMeasMeasure(type=MeasureType.BODY_TEMPERATURE, unit=0, value=34), MeasureGetMeasMeasure(type=MeasureType.SKIN_TEMPERATURE, unit=0, value=21), MeasureGetMeasMeasure(type=MeasureType.FAT_RATIO, unit=-3, value=71), MeasureGetMeasMeasure( type=MeasureType.DIASTOLIC_BLOOD_PRESSURE, unit=0, value=71), MeasureGetMeasMeasure( type=MeasureType.SYSTOLIC_BLOOD_PRESSURE, unit=0, value=101), MeasureGetMeasMeasure(type=MeasureType.HEART_RATE, unit=0, value=61), MeasureGetMeasMeasure(type=MeasureType.SP02, unit=-2, value=98), MeasureGetMeasMeasure(type=MeasureType.HYDRATION, unit=-2, value=96), MeasureGetMeasMeasure(type=MeasureType.PULSE_WAVE_VELOCITY, unit=0, value=102), ), ), ), more=False, timezone=pytz.UTC, updatetime=arrow.get("2019-08-01"), offset=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],)