Add device class to withings (#84103)

This commit is contained in:
epenet 2022-12-16 20:04:07 +01:00 committed by GitHub
parent b41d0be952
commit 1af72e3671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 399 additions and 365 deletions

View file

@ -1,11 +1,14 @@
"""Sensors flow for Withings."""
from __future__ import annotations
from dataclasses import dataclass
from withings_api.common import NotifyAppli
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -14,21 +17,29 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .common import (
BaseWithingsSensor,
UpdateType,
WithingsAttribute,
WithingsEntityDescription,
async_get_data_manager,
)
from .const import Measurement
@dataclass
class WithingsBinarySensorEntityDescription(
BinarySensorEntityDescription, WithingsEntityDescription
):
"""Immutable class for describing withings binary sensor data."""
BINARY_SENSORS = [
# Webhook measurements.
WithingsAttribute(
Measurement.IN_BED,
NotifyAppli.BED_IN,
"In bed",
"",
"mdi:bed",
True,
UpdateType.WEBHOOK,
WithingsBinarySensorEntityDescription(
key=Measurement.IN_BED.value,
measurement=Measurement.IN_BED,
measure_type=NotifyAppli.BED_IN,
name="In bed",
icon="mdi:bed",
update_type=UpdateType.WEBHOOK,
device_class=BinarySensorDeviceClass.OCCUPANCY,
),
]
@ -52,7 +63,7 @@ async def async_setup_entry(
class WithingsHealthBinarySensor(BaseWithingsSensor, BinarySensorEntity):
"""Implementation of a Withings sensor."""
_attr_device_class = BinarySensorDeviceClass.OCCUPANCY
entity_description: WithingsBinarySensorEntityDescription
@property
def is_on(self) -> bool | None: