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