diff --git a/homeassistant/components/withings/diagnostics.py b/homeassistant/components/withings/diagnostics.py index 1f74f2be444..d8b59075368 100644 --- a/homeassistant/components/withings/diagnostics.py +++ b/homeassistant/components/withings/diagnostics.py @@ -26,11 +26,30 @@ async def async_get_config_entry_diagnostics( withings_data = entry.runtime_data + positional_measurements: dict[str, list[str]] = {} + measurements: list[str] = [] + + for measurement in withings_data.measurement_coordinator.data: + measurement_type, measurement_position = measurement + measurement_type_name = measurement_type.name.lower() + if measurement_position is not None: + measurement_position_name = measurement_position.name.lower() + if measurement_type_name not in positional_measurements: + positional_measurements[measurement_type_name] = [] + positional_measurements[measurement_type_name].append( + measurement_position_name + ) + else: + measurements.append(measurement_type_name) + return { "has_valid_external_webhook_url": has_valid_external_webhook_url, "has_cloudhooks": has_cloudhooks, "webhooks_connected": withings_data.measurement_coordinator.webhooks_connected, - "received_measurements": list(withings_data.measurement_coordinator.data), + "received_measurements": { + "positional": positional_measurements, + "non_positional": measurements, + }, "received_sleep_data": withings_data.sleep_coordinator.data is not None, "received_workout_data": withings_data.workout_coordinator.data is not None, "received_activity_data": withings_data.activity_coordinator.data is not None, diff --git a/tests/components/withings/fixtures/measurements.json b/tests/components/withings/fixtures/measurements.json index 9c68d2e3e47..5ce14b6c774 100644 --- a/tests/components/withings/fixtures/measurements.json +++ b/tests/components/withings/fixtures/measurements.json @@ -779,11 +779,11 @@ }, { "value": 489, - "type": 1, + "type": 175, "unit": -2, "algo": 218235904, "fm": 3, - "position": 2 + "position": 1 }, { "value": 2308, diff --git a/tests/components/withings/snapshots/test_diagnostics.ambr b/tests/components/withings/snapshots/test_diagnostics.ambr index ca3cd2147d3..df2a3b95388 100644 --- a/tests/components/withings/snapshots/test_diagnostics.ambr +++ b/tests/components/withings/snapshots/test_diagnostics.ambr @@ -4,172 +4,59 @@ 'has_cloudhooks': True, 'has_valid_external_webhook_url': True, 'received_activity_data': False, - 'received_measurements': list([ - list([ - 1, - None, + 'received_measurements': dict({ + 'non_positional': list([ + 'weight', + 'fat_free_mass', + 'fat_mass_weight', + 'muscle_mass', + 'hydration', + 'bone_mass', + 'extracellular_water', + 'intracellular_water', + 'visceral_fat', + 'unknown', + 'fat_ratio', + 'height', + 'temperature', + 'body_temperature', + 'skin_temperature', + 'diastolic_blood_pressure', + 'systolic_blood_pressure', + 'heart_rate', + 'sp02', + 'pulse_wave_velocity', + 'vo2', + 'vascular_age', + 'electrodermal_activity_right_foot', + 'electrodermal_activity_left_foot', + 'electrodermal_activity_feet', ]), - list([ - 5, - None, - ]), - list([ - 8, - None, - ]), - list([ - 76, - None, - ]), - list([ - 77, - None, - ]), - list([ - 88, - None, - ]), - list([ - 168, - None, - ]), - list([ - 169, - None, - ]), - list([ - 170, - None, - ]), - list([ - 173, - 12, - ]), - list([ - 173, - 10, - ]), - list([ - 173, - 3, - ]), - list([ - 173, - 11, - ]), - list([ - 173, - 2, - ]), - list([ - 174, - 12, - ]), - list([ - 174, - 10, - ]), - list([ - 174, - 3, - ]), - list([ - 174, - 11, - ]), - list([ - 174, - 2, - ]), - list([ - 175, - 12, - ]), - list([ - 175, - 10, - ]), - list([ - 175, - 3, - ]), - list([ - 175, - 11, - ]), - list([ - 175, - 2, - ]), - list([ - 0, - None, - ]), - list([ - 6, - None, - ]), - list([ - 1, - 2, - ]), - list([ - 4, - None, - ]), - list([ - 12, - None, - ]), - list([ - 71, - None, - ]), - list([ - 73, - None, - ]), - list([ - 9, - None, - ]), - list([ - 10, - None, - ]), - list([ - 11, - None, - ]), - list([ - 54, - None, - ]), - list([ - 91, - None, - ]), - list([ - 123, - None, - ]), - list([ - 155, - None, - ]), - list([ - 198, - None, - ]), - list([ - 197, - None, - ]), - list([ - 196, - None, - ]), - ]), + 'positional': dict({ + 'fat_free_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + ]), + 'fat_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + ]), + 'muscle_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + 'left_wrist', + ]), + }), + }), 'received_sleep_data': True, 'received_workout_data': True, 'webhooks_connected': True, @@ -180,172 +67,59 @@ 'has_cloudhooks': False, 'has_valid_external_webhook_url': False, 'received_activity_data': False, - 'received_measurements': list([ - list([ - 1, - None, + 'received_measurements': dict({ + 'non_positional': list([ + 'weight', + 'fat_free_mass', + 'fat_mass_weight', + 'muscle_mass', + 'hydration', + 'bone_mass', + 'extracellular_water', + 'intracellular_water', + 'visceral_fat', + 'unknown', + 'fat_ratio', + 'height', + 'temperature', + 'body_temperature', + 'skin_temperature', + 'diastolic_blood_pressure', + 'systolic_blood_pressure', + 'heart_rate', + 'sp02', + 'pulse_wave_velocity', + 'vo2', + 'vascular_age', + 'electrodermal_activity_right_foot', + 'electrodermal_activity_left_foot', + 'electrodermal_activity_feet', ]), - list([ - 5, - None, - ]), - list([ - 8, - None, - ]), - list([ - 76, - None, - ]), - list([ - 77, - None, - ]), - list([ - 88, - None, - ]), - list([ - 168, - None, - ]), - list([ - 169, - None, - ]), - list([ - 170, - None, - ]), - list([ - 173, - 12, - ]), - list([ - 173, - 10, - ]), - list([ - 173, - 3, - ]), - list([ - 173, - 11, - ]), - list([ - 173, - 2, - ]), - list([ - 174, - 12, - ]), - list([ - 174, - 10, - ]), - list([ - 174, - 3, - ]), - list([ - 174, - 11, - ]), - list([ - 174, - 2, - ]), - list([ - 175, - 12, - ]), - list([ - 175, - 10, - ]), - list([ - 175, - 3, - ]), - list([ - 175, - 11, - ]), - list([ - 175, - 2, - ]), - list([ - 0, - None, - ]), - list([ - 6, - None, - ]), - list([ - 1, - 2, - ]), - list([ - 4, - None, - ]), - list([ - 12, - None, - ]), - list([ - 71, - None, - ]), - list([ - 73, - None, - ]), - list([ - 9, - None, - ]), - list([ - 10, - None, - ]), - list([ - 11, - None, - ]), - list([ - 54, - None, - ]), - list([ - 91, - None, - ]), - list([ - 123, - None, - ]), - list([ - 155, - None, - ]), - list([ - 198, - None, - ]), - list([ - 197, - None, - ]), - list([ - 196, - None, - ]), - ]), + 'positional': dict({ + 'fat_free_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + ]), + 'fat_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + ]), + 'muscle_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + 'left_wrist', + ]), + }), + }), 'received_sleep_data': True, 'received_workout_data': True, 'webhooks_connected': False, @@ -356,172 +130,59 @@ 'has_cloudhooks': False, 'has_valid_external_webhook_url': True, 'received_activity_data': False, - 'received_measurements': list([ - list([ - 1, - None, + 'received_measurements': dict({ + 'non_positional': list([ + 'weight', + 'fat_free_mass', + 'fat_mass_weight', + 'muscle_mass', + 'hydration', + 'bone_mass', + 'extracellular_water', + 'intracellular_water', + 'visceral_fat', + 'unknown', + 'fat_ratio', + 'height', + 'temperature', + 'body_temperature', + 'skin_temperature', + 'diastolic_blood_pressure', + 'systolic_blood_pressure', + 'heart_rate', + 'sp02', + 'pulse_wave_velocity', + 'vo2', + 'vascular_age', + 'electrodermal_activity_right_foot', + 'electrodermal_activity_left_foot', + 'electrodermal_activity_feet', ]), - list([ - 5, - None, - ]), - list([ - 8, - None, - ]), - list([ - 76, - None, - ]), - list([ - 77, - None, - ]), - list([ - 88, - None, - ]), - list([ - 168, - None, - ]), - list([ - 169, - None, - ]), - list([ - 170, - None, - ]), - list([ - 173, - 12, - ]), - list([ - 173, - 10, - ]), - list([ - 173, - 3, - ]), - list([ - 173, - 11, - ]), - list([ - 173, - 2, - ]), - list([ - 174, - 12, - ]), - list([ - 174, - 10, - ]), - list([ - 174, - 3, - ]), - list([ - 174, - 11, - ]), - list([ - 174, - 2, - ]), - list([ - 175, - 12, - ]), - list([ - 175, - 10, - ]), - list([ - 175, - 3, - ]), - list([ - 175, - 11, - ]), - list([ - 175, - 2, - ]), - list([ - 0, - None, - ]), - list([ - 6, - None, - ]), - list([ - 1, - 2, - ]), - list([ - 4, - None, - ]), - list([ - 12, - None, - ]), - list([ - 71, - None, - ]), - list([ - 73, - None, - ]), - list([ - 9, - None, - ]), - list([ - 10, - None, - ]), - list([ - 11, - None, - ]), - list([ - 54, - None, - ]), - list([ - 91, - None, - ]), - list([ - 123, - None, - ]), - list([ - 155, - None, - ]), - list([ - 198, - None, - ]), - list([ - 197, - None, - ]), - list([ - 196, - None, - ]), - ]), + 'positional': dict({ + 'fat_free_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + ]), + 'fat_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + ]), + 'muscle_mass_for_segments': list([ + 'torso', + 'left_leg', + 'left_arm', + 'right_leg', + 'right_arm', + 'left_wrist', + ]), + }), + }), 'received_sleep_data': True, 'received_workout_data': True, 'webhooks_connected': True,