Add coordinator to Withings (#100378)
* Add coordinator to Withings * Add coordinator to Withings * Fix tests * Remove common files * Fix tests * Fix tests * Rename to Entity * Fix * Rename webhook handler * Fix * Fix external url * Update homeassistant/components/withings/entity.py Co-authored-by: Luke Lashley <conway220@gmail.com> * Update homeassistant/components/withings/entity.py Co-authored-by: Luke Lashley <conway220@gmail.com> * Update homeassistant/components/withings/entity.py Co-authored-by: Luke Lashley <conway220@gmail.com> * Update homeassistant/components/withings/entity.py Co-authored-by: Luke Lashley <conway220@gmail.com> * fix imports * Simplify * Simplify * Fix feedback * Test if this makes changes clearer * Test if this makes changes clearer * Fix tests * Remove name * Fix feedback --------- Co-authored-by: Luke Lashley <conway220@gmail.com>
This commit is contained in:
parent
8ba6fd7935
commit
4f63c7934b
12 changed files with 393 additions and 875 deletions
|
@ -14,9 +14,9 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .common import UpdateType, async_get_data_manager
|
||||
from .const import Measurement
|
||||
from .entity import BaseWithingsSensor, WithingsEntityDescription
|
||||
from .common import WithingsDataUpdateCoordinator
|
||||
from .const import DOMAIN, Measurement
|
||||
from .entity import WithingsEntity, WithingsEntityDescription
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -34,7 +34,6 @@ BINARY_SENSORS = [
|
|||
measure_type=NotifyAppli.BED_IN,
|
||||
translation_key="in_bed",
|
||||
icon="mdi:bed",
|
||||
update_type=UpdateType.WEBHOOK,
|
||||
device_class=BinarySensorDeviceClass.OCCUPANCY,
|
||||
),
|
||||
]
|
||||
|
@ -46,17 +45,17 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the sensor config entry."""
|
||||
data_manager = await async_get_data_manager(hass, entry)
|
||||
coordinator: WithingsDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
entities = [
|
||||
WithingsHealthBinarySensor(data_manager, attribute)
|
||||
for attribute in BINARY_SENSORS
|
||||
]
|
||||
if coordinator.use_webhooks:
|
||||
entities = [
|
||||
WithingsBinarySensor(coordinator, attribute) for attribute in BINARY_SENSORS
|
||||
]
|
||||
|
||||
async_add_entities(entities, True)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class WithingsHealthBinarySensor(BaseWithingsSensor, BinarySensorEntity):
|
||||
class WithingsBinarySensor(WithingsEntity, BinarySensorEntity):
|
||||
"""Implementation of a Withings sensor."""
|
||||
|
||||
entity_description: WithingsBinarySensorEntityDescription
|
||||
|
@ -64,4 +63,4 @@ class WithingsHealthBinarySensor(BaseWithingsSensor, BinarySensorEntity):
|
|||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return self._state_data
|
||||
return self.coordinator.in_bed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue