Skip to content

Commit 4c22264

Browse files
ekobresemontnemery
andauthored
Add support for inH₂O pressure unit (home-assistant#148289)
Co-authored-by: Erik Montnemery <[email protected]>
1 parent baf4382 commit 4c22264

File tree

7 files changed

+23
-4
lines changed

7 files changed

+23
-4
lines changed

homeassistant/components/number/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class NumberDeviceClass(StrEnum):
328328
- `Pa`, `hPa`, `kPa`
329329
- `inHg`
330330
- `psi`
331+
- `inH₂O`
331332
"""
332333

333334
REACTIVE_ENERGY = "reactive_energy"

homeassistant/components/sensor/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ class SensorDeviceClass(StrEnum):
361361
- `Pa`, `hPa`, `kPa`
362362
- `inHg`
363363
- `psi`
364+
- `inH₂O`
364365
"""
365366

366367
REACTIVE_ENERGY = "reactive_energy"

homeassistant/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ class UnitOfPressure(StrEnum):
749749
MBAR = "mbar"
750750
MMHG = "mmHg"
751751
INHG = "inHg"
752+
INH2O = "inH₂O"
752753
PSI = "psi"
753754

754755

homeassistant/util/unit_conversion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
# Pressure conversion constants
8383
_STANDARD_GRAVITY = 9.80665
8484
_MERCURY_DENSITY = 13.5951
85+
_INH2O_TO_PA = 249.0889083333348 # 1 inH₂O = 249.0889083333348 Pa at 4°C
8586

8687
# Volume conversion constants
8788
_L_TO_CUBIC_METER = 0.001 # 1 L = 0.001 m³
@@ -435,6 +436,7 @@ class PressureConverter(BaseUnitConverter):
435436
UnitOfPressure.MBAR: 1 / 100,
436437
UnitOfPressure.INHG: 1
437438
/ (_IN_TO_M * 1000 * _STANDARD_GRAVITY * _MERCURY_DENSITY),
439+
UnitOfPressure.INH2O: 1 / _INH2O_TO_PA,
438440
UnitOfPressure.PSI: 1 / 6894.757,
439441
UnitOfPressure.MMHG: 1
440442
/ (_MM_TO_M * 1000 * _STANDARD_GRAVITY * _MERCURY_DENSITY),
@@ -447,6 +449,7 @@ class PressureConverter(BaseUnitConverter):
447449
UnitOfPressure.CBAR,
448450
UnitOfPressure.MBAR,
449451
UnitOfPressure.INHG,
452+
UnitOfPressure.INH2O,
450453
UnitOfPressure.PSI,
451454
UnitOfPressure.MMHG,
452455
}

homeassistant/util/unit_system.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def _deprecated_unit_system(value: str) -> str:
296296
# Convert non-metric pressure
297297
("pressure", UnitOfPressure.PSI): UnitOfPressure.KPA,
298298
("pressure", UnitOfPressure.INHG): UnitOfPressure.HPA,
299+
("pressure", UnitOfPressure.INH2O): UnitOfPressure.KPA,
299300
# Convert non-metric speeds except knots to km/h
300301
("speed", UnitOfSpeed.FEET_PER_SECOND): UnitOfSpeed.KILOMETERS_PER_HOUR,
301302
("speed", UnitOfSpeed.INCHES_PER_SECOND): UnitOfSpeed.MILLIMETERS_PER_SECOND,
@@ -379,6 +380,7 @@ def _deprecated_unit_system(value: str) -> str:
379380
("pressure", UnitOfPressure.HPA): UnitOfPressure.PSI,
380381
("pressure", UnitOfPressure.KPA): UnitOfPressure.PSI,
381382
("pressure", UnitOfPressure.MMHG): UnitOfPressure.INHG,
383+
("pressure", UnitOfPressure.INH2O): UnitOfPressure.PSI,
382384
# Convert non-USCS speeds, except knots, to mph
383385
("speed", UnitOfSpeed.METERS_PER_SECOND): UnitOfSpeed.MILES_PER_HOUR,
384386
("speed", UnitOfSpeed.MILLIMETERS_PER_SECOND): UnitOfSpeed.INCHES_PER_SECOND,

tests/components/sensor/test_recorder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4957,14 +4957,14 @@ def set_state(entity_id, state, **kwargs):
49574957
PRESSURE_SENSOR_ATTRIBUTES,
49584958
"psi",
49594959
"bar",
4960-
"Pa, bar, cbar, hPa, inHg, kPa, mbar, mmHg, psi",
4960+
"Pa, bar, cbar, hPa, inHg, inH₂O, kPa, mbar, mmHg, psi",
49614961
),
49624962
(
49634963
METRIC_SYSTEM,
49644964
PRESSURE_SENSOR_ATTRIBUTES,
49654965
"Pa",
49664966
"bar",
4967-
"Pa, bar, cbar, hPa, inHg, kPa, mbar, mmHg, psi",
4967+
"Pa, bar, cbar, hPa, inHg, inH₂O, kPa, mbar, mmHg, psi",
49684968
),
49694969
],
49704970
)
@@ -5175,14 +5175,14 @@ async def test_validate_statistics_unit_ignore_device_class(
51755175
PRESSURE_SENSOR_ATTRIBUTES,
51765176
"psi",
51775177
"bar",
5178-
"Pa, bar, cbar, hPa, inHg, kPa, mbar, mmHg, psi",
5178+
"Pa, bar, cbar, hPa, inHg, inH₂O, kPa, mbar, mmHg, psi",
51795179
),
51805180
(
51815181
METRIC_SYSTEM,
51825182
PRESSURE_SENSOR_ATTRIBUTES,
51835183
"Pa",
51845184
"bar",
5185-
"Pa, bar, cbar, hPa, inHg, kPa, mbar, mmHg, psi",
5185+
"Pa, bar, cbar, hPa, inHg, inH₂O, kPa, mbar, mmHg, psi",
51865186
),
51875187
(
51885188
METRIC_SYSTEM,

tests/util/test_unit_conversion.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,26 +672,37 @@
672672
(1000, UnitOfPressure.HPA, 100, UnitOfPressure.KPA),
673673
(1000, UnitOfPressure.HPA, 1000, UnitOfPressure.MBAR),
674674
(1000, UnitOfPressure.HPA, 100, UnitOfPressure.CBAR),
675+
(1000, UnitOfPressure.HPA, 401.46307866177, UnitOfPressure.INH2O),
675676
(100, UnitOfPressure.KPA, 14.5037743897, UnitOfPressure.PSI),
676677
(100, UnitOfPressure.KPA, 29.5299801647, UnitOfPressure.INHG),
677678
(100, UnitOfPressure.KPA, 100000, UnitOfPressure.PA),
678679
(100, UnitOfPressure.KPA, 1000, UnitOfPressure.HPA),
679680
(100, UnitOfPressure.KPA, 1000, UnitOfPressure.MBAR),
680681
(100, UnitOfPressure.KPA, 100, UnitOfPressure.CBAR),
682+
(100, UnitOfPressure.INH2O, 3.6127291827353996, UnitOfPressure.PSI),
683+
(100, UnitOfPressure.INH2O, 186.83201548767, UnitOfPressure.MMHG),
684+
(100, UnitOfPressure.INH2O, 7.3555912463681, UnitOfPressure.INHG),
685+
(100, UnitOfPressure.INH2O, 24908.890833333, UnitOfPressure.PA),
686+
(100, UnitOfPressure.INH2O, 249.08890833333, UnitOfPressure.HPA),
687+
(100, UnitOfPressure.INH2O, 249.08890833333, UnitOfPressure.MBAR),
688+
(100, UnitOfPressure.INH2O, 24.908890833333, UnitOfPressure.KPA),
689+
(100, UnitOfPressure.INH2O, 24.908890833333, UnitOfPressure.CBAR),
681690
(30, UnitOfPressure.INHG, 14.7346266155, UnitOfPressure.PSI),
682691
(30, UnitOfPressure.INHG, 101.59167, UnitOfPressure.KPA),
683692
(30, UnitOfPressure.INHG, 1015.9167, UnitOfPressure.HPA),
684693
(30, UnitOfPressure.INHG, 101591.67, UnitOfPressure.PA),
685694
(30, UnitOfPressure.INHG, 1015.9167, UnitOfPressure.MBAR),
686695
(30, UnitOfPressure.INHG, 101.59167, UnitOfPressure.CBAR),
687696
(30, UnitOfPressure.INHG, 762, UnitOfPressure.MMHG),
697+
(30, UnitOfPressure.INHG, 407.85300589959, UnitOfPressure.INH2O),
688698
(30, UnitOfPressure.MMHG, 0.580103, UnitOfPressure.PSI),
689699
(30, UnitOfPressure.MMHG, 3.99967, UnitOfPressure.KPA),
690700
(30, UnitOfPressure.MMHG, 39.9967, UnitOfPressure.HPA),
691701
(30, UnitOfPressure.MMHG, 3999.67, UnitOfPressure.PA),
692702
(30, UnitOfPressure.MMHG, 39.9967, UnitOfPressure.MBAR),
693703
(30, UnitOfPressure.MMHG, 3.99967, UnitOfPressure.CBAR),
694704
(30, UnitOfPressure.MMHG, 1.181102, UnitOfPressure.INHG),
705+
(30, UnitOfPressure.MMHG, 16.0572051431838, UnitOfPressure.INH2O),
695706
(5, UnitOfPressure.BAR, 72.51887, UnitOfPressure.PSI),
696707
],
697708
ReactiveEnergyConverter: [

0 commit comments

Comments
 (0)