From b7ad53e134b33b484dd24da8798fbecb3181c4da Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 31 Aug 2026 09:31:34 -0700 Subject: [PATCH] Suggest hours as unit of measurement for Google Health sleep duration sensors (#180929) Co-authored-by: Home Assistant Developer --- .../components/google_health/sensor.py | 6 +++++ .../google_health/snapshots/test_sensor.ambr | 27 ++++++++++++------- tests/components/google_health/test_sensor.py | 6 ++--- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/google_health/sensor.py b/homeassistant/components/google_health/sensor.py index e9c23357bfb1..e0a7c37ebced 100644 --- a/homeassistant/components/google_health/sensor.py +++ b/homeassistant/components/google_health/sensor.py @@ -158,6 +158,8 @@ SLEEP_SENSORS: list[ key="sleep_asleep", translation_key="sleep_asleep", native_unit_of_measurement=UnitOfTime.MINUTES, + suggested_unit_of_measurement=UnitOfTime.HOURS, + suggested_display_precision=2, device_class=SensorDeviceClass.DURATION, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: ( @@ -170,6 +172,8 @@ SLEEP_SENSORS: list[ key="sleep_awake", translation_key="sleep_awake", native_unit_of_measurement=UnitOfTime.MINUTES, + suggested_unit_of_measurement=UnitOfTime.HOURS, + suggested_display_precision=2, device_class=SensorDeviceClass.DURATION, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: ( @@ -182,6 +186,8 @@ SLEEP_SENSORS: list[ key="sleep_in_bed", translation_key="sleep_in_bed", native_unit_of_measurement=UnitOfTime.MINUTES, + suggested_unit_of_measurement=UnitOfTime.HOURS, + suggested_display_precision=2, device_class=SensorDeviceClass.DURATION, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: ( diff --git a/tests/components/google_health/snapshots/test_sensor.ambr b/tests/components/google_health/snapshots/test_sensor.ambr index 5f084d060e53..2785c01fa2de 100644 --- a/tests/components/google_health/snapshots/test_sensor.ambr +++ b/tests/components/google_health/snapshots/test_sensor.ambr @@ -690,6 +690,9 @@ 'sensor': dict({ 'suggested_display_precision': 2, }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), 'original_device_class': , 'original_icon': None, @@ -700,7 +703,7 @@ 'supported_features': 0, 'translation_key': 'sleep_asleep', 'unique_id': '01J0BC4QM2YBRP6H5G933CETT7_sleep_asleep', - 'unit_of_measurement': , + 'unit_of_measurement': , }) # --- # name: test_all_entities[sensor.google_health_time_asleep-state] @@ -709,14 +712,14 @@ : 'duration', : 'Google Health Time asleep', : , - : , + : , }), 'context': , 'entity_id': 'sensor.google_health_time_asleep', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '420', + 'state': '7.0', }) # --- # name: test_all_entities[sensor.google_health_time_awake-entry] @@ -748,6 +751,9 @@ 'sensor': dict({ 'suggested_display_precision': 2, }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), 'original_device_class': , 'original_icon': None, @@ -758,7 +764,7 @@ 'supported_features': 0, 'translation_key': 'sleep_awake', 'unique_id': '01J0BC4QM2YBRP6H5G933CETT7_sleep_awake', - 'unit_of_measurement': , + 'unit_of_measurement': , }) # --- # name: test_all_entities[sensor.google_health_time_awake-state] @@ -767,14 +773,14 @@ : 'duration', : 'Google Health Time awake', : , - : , + : , }), 'context': , 'entity_id': 'sensor.google_health_time_awake', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '60', + 'state': '1.0', }) # --- # name: test_all_entities[sensor.google_health_time_in_bed-entry] @@ -806,6 +812,9 @@ 'sensor': dict({ 'suggested_display_precision': 2, }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), 'original_device_class': , 'original_icon': None, @@ -816,7 +825,7 @@ 'supported_features': 0, 'translation_key': 'sleep_in_bed', 'unique_id': '01J0BC4QM2YBRP6H5G933CETT7_sleep_in_bed', - 'unit_of_measurement': , + 'unit_of_measurement': , }) # --- # name: test_all_entities[sensor.google_health_time_in_bed-state] @@ -825,14 +834,14 @@ : 'duration', : 'Google Health Time in bed', : , - : , + : , }), 'context': , 'entity_id': 'sensor.google_health_time_in_bed', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '480', + 'state': '8.0', }) # --- # name: test_all_entities[sensor.google_health_time_to_fall_asleep-entry] diff --git a/tests/components/google_health/test_sensor.py b/tests/components/google_health/test_sensor.py index 91a0b652f7e0..9b1b890146df 100644 --- a/tests/components/google_health/test_sensor.py +++ b/tests/components/google_health/test_sensor.py @@ -119,15 +119,15 @@ async def test_sensor_in_progress_sleep( time_asleep_state = hass.states.get("sensor.google_health_time_asleep") assert time_asleep_state is not None - assert time_asleep_state.state == "420" + assert time_asleep_state.state == "7.0" time_awake_state = hass.states.get("sensor.google_health_time_awake") assert time_awake_state is not None - assert time_awake_state.state == "60" + assert time_awake_state.state == "1.0" time_in_bed_state = hass.states.get("sensor.google_health_time_in_bed") assert time_in_bed_state is not None - assert time_in_bed_state.state == "480" + assert time_in_bed_state.state == "8.0" time_to_fall_asleep_state = hass.states.get( "sensor.google_health_time_to_fall_asleep"