From ea709d06303ec98ccd68d324ed8ecf75aa634bac Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Wed, 8 Apr 2020 11:57:42 -0700 Subject: [PATCH] Remove withings sleep state (#33817) --- homeassistant/components/withings/const.py | 1 - homeassistant/components/withings/sensor.py | 41 --------------------- tests/components/withings/test_init.py | 5 --- 3 files changed, 47 deletions(-) diff --git a/homeassistant/components/withings/const.py b/homeassistant/components/withings/const.py index 781420b347a..172a17d2914 100644 --- a/homeassistant/components/withings/const.py +++ b/homeassistant/components/withings/const.py @@ -48,7 +48,6 @@ MEAS_SLEEP_REM_DURATION_SECONDS = "sleep_rem_duration_seconds" MEAS_SLEEP_RESPIRATORY_RATE_AVERAGE = "sleep_respiratory_average_bpm" MEAS_SLEEP_RESPIRATORY_RATE_MAX = "sleep_respiratory_max_bpm" MEAS_SLEEP_RESPIRATORY_RATE_MIN = "sleep_respiratory_min_bpm" -MEAS_SLEEP_STATE = "sleep_state" MEAS_SLEEP_TOSLEEP_DURATION_SECONDS = "sleep_tosleep_duration_seconds" MEAS_SLEEP_TOWAKEUP_DURATION_SECONDS = "sleep_towakeup_duration_seconds" MEAS_SLEEP_WAKEUP_COUNT = "sleep_wakeup_count" diff --git a/homeassistant/components/withings/sensor.py b/homeassistant/components/withings/sensor.py index 61e4dab8510..4061e3207cc 100644 --- a/homeassistant/components/withings/sensor.py +++ b/homeassistant/components/withings/sensor.py @@ -6,9 +6,7 @@ from withings_api.common import ( MeasureGetMeasResponse, MeasureGroupAttribs, MeasureType, - SleepGetResponse, SleepGetSummaryResponse, - SleepState, get_measure_value, ) @@ -73,16 +71,6 @@ class WithingsMeasureAttribute(WithingsAttribute): """Model measure attributes.""" -class WithingsSleepStateAttribute(WithingsAttribute): - """Model sleep data attributes.""" - - def __init__( - self, measurement: str, friendly_name: str, unit_of_measurement: str, icon: str - ) -> None: - """Initialize sleep state attribute.""" - super().__init__(measurement, None, friendly_name, unit_of_measurement, icon) - - class WithingsSleepSummaryAttribute(WithingsAttribute): """Models sleep summary attributes.""" @@ -196,9 +184,6 @@ WITHINGS_ATTRIBUTES = [ SPEED_METERS_PER_SECOND, None, ), - WithingsSleepStateAttribute( - const.MEAS_SLEEP_STATE, "Sleep state", None, "mdi:sleep" - ), WithingsSleepSummaryAttribute( const.MEAS_SLEEP_WAKEUP_DURATION_SECONDS, GetSleepSummaryField.WAKEUP_DURATION.value, @@ -359,11 +344,6 @@ class WithingsHealthSensor(Entity): await self._data_manager.update_measures() await self.async_update_measure(self._data_manager.measures) - elif isinstance(self._attribute, WithingsSleepStateAttribute): - _LOGGER.debug("Updating sleep state") - await self._data_manager.update_sleep() - await self.async_update_sleep_state(self._data_manager.sleep) - elif isinstance(self._attribute, WithingsSleepSummaryAttribute): _LOGGER.debug("Updating sleep summary state") await self._data_manager.update_sleep_summary() @@ -386,27 +366,6 @@ class WithingsHealthSensor(Entity): self._state = round(value, 2) - async def async_update_sleep_state(self, data: SleepGetResponse) -> None: - """Update the sleep state data.""" - if not data.series: - _LOGGER.debug("No sleep data, setting state to %s", None) - self._state = None - return - - sorted_series = sorted(data.series, key=lambda serie: serie.startdate) - serie = sorted_series[len(sorted_series) - 1] - state = None - if serie.state == SleepState.AWAKE: - state = const.STATE_AWAKE - elif serie.state == SleepState.LIGHT: - state = const.STATE_LIGHT - elif serie.state == SleepState.DEEP: - state = const.STATE_DEEP - elif serie.state == SleepState.REM: - state = const.STATE_REM - - self._state = state - async def async_update_sleep_summary(self, data: SleepGetSummaryResponse) -> None: """Update the sleep summary data.""" if not data.series: diff --git a/tests/components/withings/test_init.py b/tests/components/withings/test_init.py index ae717bc1839..f6f36ba8eff 100644 --- a/tests/components/withings/test_init.py +++ b/tests/components/withings/test_init.py @@ -412,13 +412,8 @@ async def test_full_setup(hass: HomeAssistant, aiohttp_client, aioclient_mock) - (profiles[0], const.MEAS_SLEEP_RESPIRATORY_RATE_AVERAGE, 2320), (profiles[0], const.MEAS_SLEEP_RESPIRATORY_RATE_MIN, 2520), (profiles[0], const.MEAS_SLEEP_RESPIRATORY_RATE_MAX, 2720), - (profiles[0], const.MEAS_SLEEP_STATE, const.STATE_DEEP), - (profiles[1], const.MEAS_SLEEP_STATE, STATE_UNKNOWN), (profiles[1], const.MEAS_HYDRATION, STATE_UNKNOWN), - (profiles[2], const.MEAS_SLEEP_STATE, const.STATE_AWAKE), - (profiles[3], const.MEAS_SLEEP_STATE, const.STATE_LIGHT), (profiles[3], const.MEAS_FAT_FREE_MASS_KG, STATE_UNKNOWN), - (profiles[4], const.MEAS_SLEEP_STATE, const.STATE_REM), ) for (profile, meas, value) in expected_states: assert_state_equals(hass, profile, meas, value)