2019-08-31 12:30:59 +00:00
|
|
|
"""Sensors flow for Withings."""
|
2021-03-18 14:08:35 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-09-28 12:33:38 +00:00
|
|
|
from homeassistant.components.sensor import (
|
|
|
|
DOMAIN as SENSOR_DOMAIN,
|
|
|
|
SensorEntity,
|
|
|
|
SensorStateClass,
|
|
|
|
)
|
2019-08-31 12:30:59 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2019-10-24 16:41:04 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-04-30 18:38:59 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-08-31 12:30:59 +00:00
|
|
|
|
2020-06-16 18:16:18 +00:00
|
|
|
from .common import BaseWithingsSensor, async_create_entities
|
2019-08-31 12:30:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
2019-10-24 16:41:04 +00:00
|
|
|
hass: HomeAssistant,
|
2019-08-31 12:30:59 +00:00
|
|
|
entry: ConfigEntry,
|
2021-04-30 18:38:59 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2019-10-24 16:41:04 +00:00
|
|
|
) -> None:
|
2019-08-31 12:30:59 +00:00
|
|
|
"""Set up the sensor config entry."""
|
2020-06-16 18:16:18 +00:00
|
|
|
entities = await async_create_entities(
|
2020-08-27 11:56:20 +00:00
|
|
|
hass,
|
|
|
|
entry,
|
|
|
|
WithingsHealthSensor,
|
|
|
|
SENSOR_DOMAIN,
|
2020-06-16 18:16:18 +00:00
|
|
|
)
|
2019-08-31 12:30:59 +00:00
|
|
|
|
2019-10-24 16:41:04 +00:00
|
|
|
async_add_entities(entities, True)
|
2019-08-31 12:30:59 +00:00
|
|
|
|
|
|
|
|
2021-03-22 18:50:29 +00:00
|
|
|
class WithingsHealthSensor(BaseWithingsSensor, SensorEntity):
|
2019-08-31 12:30:59 +00:00
|
|
|
"""Implementation of a Withings sensor."""
|
|
|
|
|
|
|
|
@property
|
2021-08-11 19:17:16 +00:00
|
|
|
def native_value(self) -> None | str | int | float:
|
2020-06-16 18:16:18 +00:00
|
|
|
"""Return the state of the entity."""
|
|
|
|
return self._state_data
|
2021-03-23 14:56:33 +00:00
|
|
|
|
|
|
|
@property
|
2021-08-11 19:17:16 +00:00
|
|
|
def native_unit_of_measurement(self) -> str:
|
2021-03-23 14:56:33 +00:00
|
|
|
"""Return the unit of measurement of this entity, if any."""
|
|
|
|
return self._attribute.unit_of_measurement
|
2022-09-28 12:33:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state_class(self) -> str:
|
|
|
|
"""Return the state_class of this entity, if any."""
|
|
|
|
return SensorStateClass.MEASUREMENT
|