Remove withings sleep state (#33817)

This commit is contained in:
Robert Van Gorkom 2020-04-08 11:57:42 -07:00 committed by GitHub
parent cec3b57390
commit ea709d0630
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 47 deletions

View File

@ -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_AVERAGE = "sleep_respiratory_average_bpm"
MEAS_SLEEP_RESPIRATORY_RATE_MAX = "sleep_respiratory_max_bpm" MEAS_SLEEP_RESPIRATORY_RATE_MAX = "sleep_respiratory_max_bpm"
MEAS_SLEEP_RESPIRATORY_RATE_MIN = "sleep_respiratory_min_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_TOSLEEP_DURATION_SECONDS = "sleep_tosleep_duration_seconds"
MEAS_SLEEP_TOWAKEUP_DURATION_SECONDS = "sleep_towakeup_duration_seconds" MEAS_SLEEP_TOWAKEUP_DURATION_SECONDS = "sleep_towakeup_duration_seconds"
MEAS_SLEEP_WAKEUP_COUNT = "sleep_wakeup_count" MEAS_SLEEP_WAKEUP_COUNT = "sleep_wakeup_count"

View File

@ -6,9 +6,7 @@ from withings_api.common import (
MeasureGetMeasResponse, MeasureGetMeasResponse,
MeasureGroupAttribs, MeasureGroupAttribs,
MeasureType, MeasureType,
SleepGetResponse,
SleepGetSummaryResponse, SleepGetSummaryResponse,
SleepState,
get_measure_value, get_measure_value,
) )
@ -73,16 +71,6 @@ class WithingsMeasureAttribute(WithingsAttribute):
"""Model measure attributes.""" """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): class WithingsSleepSummaryAttribute(WithingsAttribute):
"""Models sleep summary attributes.""" """Models sleep summary attributes."""
@ -196,9 +184,6 @@ WITHINGS_ATTRIBUTES = [
SPEED_METERS_PER_SECOND, SPEED_METERS_PER_SECOND,
None, None,
), ),
WithingsSleepStateAttribute(
const.MEAS_SLEEP_STATE, "Sleep state", None, "mdi:sleep"
),
WithingsSleepSummaryAttribute( WithingsSleepSummaryAttribute(
const.MEAS_SLEEP_WAKEUP_DURATION_SECONDS, const.MEAS_SLEEP_WAKEUP_DURATION_SECONDS,
GetSleepSummaryField.WAKEUP_DURATION.value, GetSleepSummaryField.WAKEUP_DURATION.value,
@ -359,11 +344,6 @@ class WithingsHealthSensor(Entity):
await self._data_manager.update_measures() await self._data_manager.update_measures()
await self.async_update_measure(self._data_manager.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): elif isinstance(self._attribute, WithingsSleepSummaryAttribute):
_LOGGER.debug("Updating sleep summary state") _LOGGER.debug("Updating sleep summary state")
await self._data_manager.update_sleep_summary() await self._data_manager.update_sleep_summary()
@ -386,27 +366,6 @@ class WithingsHealthSensor(Entity):
self._state = round(value, 2) 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: async def async_update_sleep_summary(self, data: SleepGetSummaryResponse) -> None:
"""Update the sleep summary data.""" """Update the sleep summary data."""
if not data.series: if not data.series:

View File

@ -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_AVERAGE, 2320),
(profiles[0], const.MEAS_SLEEP_RESPIRATORY_RATE_MIN, 2520), (profiles[0], const.MEAS_SLEEP_RESPIRATORY_RATE_MIN, 2520),
(profiles[0], const.MEAS_SLEEP_RESPIRATORY_RATE_MAX, 2720), (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[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[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: for (profile, meas, value) in expected_states:
assert_state_equals(hass, profile, meas, value) assert_state_equals(hass, profile, meas, value)