From c913d1791302f26b0cd74f4a4abc2a9f29b7673f Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Sun, 2 Aug 2020 07:36:14 -0700 Subject: [PATCH] Add bed sensor availability for withings (#37906) --- homeassistant/components/withings/common.py | 6 ++++++ tests/components/withings/test_binary_sensor.py | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/withings/common.py b/homeassistant/components/withings/common.py index 89bc56dc77c..2f3f4bf849a 100644 --- a/homeassistant/components/withings/common.py +++ b/homeassistant/components/withings/common.py @@ -926,6 +926,12 @@ class BaseWithingsSensor(Entity): if self._attribute.update_type == UpdateType.POLL: return self._data_manager.poll_data_update_coordinator.last_update_success + if self._attribute.update_type == UpdateType.WEBHOOK: + return self._data_manager.webhook_config.enabled and ( + self._attribute.measurement + in self._data_manager.webhook_update_coordinator.data + ) + return True @property diff --git a/tests/components/withings/test_binary_sensor.py b/tests/components/withings/test_binary_sensor.py index b646c667472..8f3347c8867 100644 --- a/tests/components/withings/test_binary_sensor.py +++ b/tests/components/withings/test_binary_sensor.py @@ -6,7 +6,7 @@ from homeassistant.components.withings.common import ( async_get_entity_id, ) from homeassistant.components.withings.const import Measurement -from homeassistant.const import STATE_OFF, STATE_ON +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_registry import EntityRegistry @@ -37,7 +37,7 @@ async def test_binary_sensor( assert entity_id1 assert entity_registry.async_is_registered(entity_id0) - assert hass.states.get(entity_id0).state == STATE_OFF + assert hass.states.get(entity_id0).state == STATE_UNAVAILABLE resp = await component_factory.call_webhook(person0.user_id, NotifyAppli.BED_IN) assert resp.message_code == 0 @@ -50,7 +50,7 @@ async def test_binary_sensor( assert hass.states.get(entity_id0).state == STATE_OFF # person 1 - assert hass.states.get(entity_id1).state == STATE_OFF + assert hass.states.get(entity_id1).state == STATE_UNAVAILABLE resp = await component_factory.call_webhook(person1.user_id, NotifyAppli.BED_IN) assert resp.message_code == 0