Skip to content

Commit 9717599

Browse files
TheDKjoostlek
andauthored
Use SensorDeviceClass.PRESSURE in Withings (home-assistant#156648)
Co-authored-by: Joostlek <[email protected]>
1 parent 4d7de2f commit 9717599

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

homeassistant/components/withings/const.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@
1212
UOM_BEATS_PER_MINUTE = "bpm"
1313
UOM_BREATHS_PER_MINUTE = "br/min"
1414
UOM_FREQUENCY = "times"
15-
UOM_MMHG = "mmhg"

homeassistant/components/withings/sensor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Platform,
3131
UnitOfLength,
3232
UnitOfMass,
33+
UnitOfPressure,
3334
UnitOfSpeed,
3435
UnitOfTemperature,
3536
UnitOfTime,
@@ -48,7 +49,6 @@
4849
UOM_BEATS_PER_MINUTE,
4950
UOM_BREATHS_PER_MINUTE,
5051
UOM_FREQUENCY,
51-
UOM_MMHG,
5252
)
5353
from .coordinator import (
5454
WithingsActivityDataUpdateCoordinator,
@@ -162,14 +162,16 @@ class WithingsMeasurementSensorEntityDescription(SensorEntityDescription):
162162
key="diastolic_blood_pressure_mmhg",
163163
measurement_type=MeasurementType.DIASTOLIC_BLOOD_PRESSURE,
164164
translation_key="diastolic_blood_pressure",
165-
native_unit_of_measurement=UOM_MMHG,
165+
native_unit_of_measurement=UnitOfPressure.MMHG,
166+
device_class=SensorDeviceClass.PRESSURE,
166167
state_class=SensorStateClass.MEASUREMENT,
167168
),
168169
MeasurementType.SYSTOLIC_BLOOD_PRESSURE: WithingsMeasurementSensorEntityDescription(
169170
key="systolic_blood_pressure_mmhg",
170171
measurement_type=MeasurementType.SYSTOLIC_BLOOD_PRESSURE,
171172
translation_key="systolic_blood_pressure",
172-
native_unit_of_measurement=UOM_MMHG,
173+
native_unit_of_measurement=UnitOfPressure.MMHG,
174+
device_class=SensorDeviceClass.PRESSURE,
173175
state_class=SensorStateClass.MEASUREMENT,
174176
),
175177
MeasurementType.HEART_RATE: WithingsMeasurementSensorEntityDescription(

tests/components/withings/snapshots/test_sensor.ambr

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,11 @@
577577
}),
578578
'name': None,
579579
'options': dict({
580+
'sensor': dict({
581+
'suggested_display_precision': 2,
582+
}),
580583
}),
581-
'original_device_class': None,
584+
'original_device_class': <SensorDeviceClass.PRESSURE: 'pressure'>,
582585
'original_icon': None,
583586
'original_name': 'Diastolic blood pressure',
584587
'platform': 'withings',
@@ -587,15 +590,16 @@
587590
'supported_features': 0,
588591
'translation_key': 'diastolic_blood_pressure',
589592
'unique_id': 'withings_12345_diastolic_blood_pressure_mmhg',
590-
'unit_of_measurement': 'mmhg',
593+
'unit_of_measurement': <UnitOfPressure.MMHG: 'mmHg'>,
591594
})
592595
# ---
593596
# name: test_all_entities[sensor.henk_diastolic_blood_pressure-state]
594597
StateSnapshot({
595598
'attributes': ReadOnlyDict({
599+
'device_class': 'pressure',
596600
'friendly_name': 'henk Diastolic blood pressure',
597601
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
598-
'unit_of_measurement': 'mmhg',
602+
'unit_of_measurement': <UnitOfPressure.MMHG: 'mmHg'>,
599603
}),
600604
'context': <ANY>,
601605
'entity_id': 'sensor.henk_diastolic_blood_pressure',
@@ -3643,8 +3647,11 @@
36433647
}),
36443648
'name': None,
36453649
'options': dict({
3650+
'sensor': dict({
3651+
'suggested_display_precision': 2,
3652+
}),
36463653
}),
3647-
'original_device_class': None,
3654+
'original_device_class': <SensorDeviceClass.PRESSURE: 'pressure'>,
36483655
'original_icon': None,
36493656
'original_name': 'Systolic blood pressure',
36503657
'platform': 'withings',
@@ -3653,15 +3660,16 @@
36533660
'supported_features': 0,
36543661
'translation_key': 'systolic_blood_pressure',
36553662
'unique_id': 'withings_12345_systolic_blood_pressure_mmhg',
3656-
'unit_of_measurement': 'mmhg',
3663+
'unit_of_measurement': <UnitOfPressure.MMHG: 'mmHg'>,
36573664
})
36583665
# ---
36593666
# name: test_all_entities[sensor.henk_systolic_blood_pressure-state]
36603667
StateSnapshot({
36613668
'attributes': ReadOnlyDict({
3669+
'device_class': 'pressure',
36623670
'friendly_name': 'henk Systolic blood pressure',
36633671
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
3664-
'unit_of_measurement': 'mmhg',
3672+
'unit_of_measurement': <UnitOfPressure.MMHG: 'mmHg'>,
36653673
}),
36663674
'context': <ANY>,
36673675
'entity_id': 'sensor.henk_systolic_blood_pressure',

0 commit comments

Comments
 (0)