Make Withings sleep sensor only show last night (#101993)
parent
30ba78cf82
commit
a6ade59133
|
@ -15,7 +15,6 @@ from aiowithings import (
|
||||||
WithingsUnauthorizedError,
|
WithingsUnauthorizedError,
|
||||||
aggregate_measurements,
|
aggregate_measurements,
|
||||||
)
|
)
|
||||||
from aiowithings.helpers import aggregate_sleep_summary
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -145,7 +144,9 @@ class WithingsSleepDataUpdateCoordinator(
|
||||||
SleepSummaryDataFields.TOTAL_TIME_AWAKE,
|
SleepSummaryDataFields.TOTAL_TIME_AWAKE,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
return aggregate_sleep_summary(response)
|
if not response:
|
||||||
|
return None
|
||||||
|
return response[0]
|
||||||
|
|
||||||
|
|
||||||
class WithingsBedPresenceDataUpdateCoordinator(WithingsDataUpdateCoordinator[None]):
|
class WithingsBedPresenceDataUpdateCoordinator(WithingsDataUpdateCoordinator[None]):
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
'entity_id': 'sensor.henk_average_heart_rate',
|
'entity_id': 'sensor.henk_average_heart_rate',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '83',
|
'state': '103',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_average_respiratory_rate]
|
# name: test_all_entities[sensor.henk_average_respiratory_rate]
|
||||||
|
@ -100,7 +100,7 @@
|
||||||
'entity_id': 'sensor.henk_breathing_disturbances_intensity',
|
'entity_id': 'sensor.henk_breathing_disturbances_intensity',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '10',
|
'state': '9',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_deep_sleep]
|
# name: test_all_entities[sensor.henk_deep_sleep]
|
||||||
|
@ -116,7 +116,7 @@
|
||||||
'entity_id': 'sensor.henk_deep_sleep',
|
'entity_id': 'sensor.henk_deep_sleep',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '26220',
|
'state': '5820',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_diastolic_blood_pressure]
|
# name: test_all_entities[sensor.henk_diastolic_blood_pressure]
|
||||||
|
@ -315,7 +315,7 @@
|
||||||
'entity_id': 'sensor.henk_light_sleep',
|
'entity_id': 'sensor.henk_light_sleep',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '58440',
|
'state': '10440',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_maximum_heart_rate]
|
# name: test_all_entities[sensor.henk_maximum_heart_rate]
|
||||||
|
@ -330,7 +330,7 @@
|
||||||
'entity_id': 'sensor.henk_maximum_heart_rate',
|
'entity_id': 'sensor.henk_maximum_heart_rate',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '108',
|
'state': '120',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_maximum_respiratory_rate]
|
# name: test_all_entities[sensor.henk_maximum_respiratory_rate]
|
||||||
|
@ -359,7 +359,7 @@
|
||||||
'entity_id': 'sensor.henk_minimum_heart_rate',
|
'entity_id': 'sensor.henk_minimum_heart_rate',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '58',
|
'state': '70',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_minimum_respiratory_rate]
|
# name: test_all_entities[sensor.henk_minimum_respiratory_rate]
|
||||||
|
@ -435,7 +435,7 @@
|
||||||
'entity_id': 'sensor.henk_rem_sleep',
|
'entity_id': 'sensor.henk_rem_sleep',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '17280',
|
'state': '2400',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_skin_temperature]
|
# name: test_all_entities[sensor.henk_skin_temperature]
|
||||||
|
@ -481,7 +481,7 @@
|
||||||
'entity_id': 'sensor.henk_sleep_score',
|
'entity_id': 'sensor.henk_sleep_score',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '90',
|
'state': '37',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_snoring]
|
# name: test_all_entities[sensor.henk_snoring]
|
||||||
|
@ -494,7 +494,7 @@
|
||||||
'entity_id': 'sensor.henk_snoring',
|
'entity_id': 'sensor.henk_snoring',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '1044',
|
'state': '1080',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_snoring_episode_count]
|
# name: test_all_entities[sensor.henk_snoring_episode_count]
|
||||||
|
@ -507,7 +507,7 @@
|
||||||
'entity_id': 'sensor.henk_snoring_episode_count',
|
'entity_id': 'sensor.henk_snoring_episode_count',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '87',
|
'state': '18',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_soft_activity_today]
|
# name: test_all_entities[sensor.henk_soft_activity_today]
|
||||||
|
@ -613,7 +613,7 @@
|
||||||
'entity_id': 'sensor.henk_time_to_sleep',
|
'entity_id': 'sensor.henk_time_to_sleep',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '780',
|
'state': '540',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_time_to_wakeup]
|
# name: test_all_entities[sensor.henk_time_to_wakeup]
|
||||||
|
@ -629,7 +629,7 @@
|
||||||
'entity_id': 'sensor.henk_time_to_wakeup',
|
'entity_id': 'sensor.henk_time_to_wakeup',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '996',
|
'state': '1140',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_total_calories_burnt_today]
|
# name: test_all_entities[sensor.henk_total_calories_burnt_today]
|
||||||
|
@ -685,7 +685,7 @@
|
||||||
'entity_id': 'sensor.henk_wakeup_count',
|
'entity_id': 'sensor.henk_wakeup_count',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '8',
|
'state': '1',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_wakeup_time]
|
# name: test_all_entities[sensor.henk_wakeup_time]
|
||||||
|
@ -701,7 +701,7 @@
|
||||||
'entity_id': 'sensor.henk_wakeup_time',
|
'entity_id': 'sensor.henk_wakeup_time',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': '3468',
|
'state': '3060',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_all_entities[sensor.henk_weight]
|
# name: test_all_entities[sensor.henk_weight]
|
||||||
|
|
|
@ -243,3 +243,24 @@ async def test_activity_sensors_created_when_receive_activity_data(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("sensor.henk_steps_today") is not None
|
assert hass.states.get("sensor.henk_steps_today") is not None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
|
async def test_no_sleep(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
withings: AsyncMock,
|
||||||
|
polling_config_entry: MockConfigEntry,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
) -> None:
|
||||||
|
"""Test no sleep found."""
|
||||||
|
await setup_integration(hass, polling_config_entry, False)
|
||||||
|
|
||||||
|
withings.get_sleep_summary_since.return_value = []
|
||||||
|
freezer.tick(timedelta(minutes=10))
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.henk_average_respiratory_rate")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
Loading…
Reference in New Issue