mirror of
https://github.com/home-assistant/core.git
synced 2026-08-29 01:26:17 +01:00
* initial oauth2 implementation * fix unload_entry * read old yaml/entry config * update tests * fix: pylint on tests * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix constants, formatting * use runtime_data * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * fix missing import * adopt to PointData dataclass * fix typing * add more strings (copied from weheat) * move the PointData dataclass to avoid circular imports * use configflow inspired by withings * raise ConfigEntryAuthFailed * it is called entry_lock * fix webhook issue * fix oauth_create_entry * stop using async_forward_entry_setup * Fixup * fix strings * fix issue that old config might be without unique_id * parametrize tests * Update homeassistant/components/point/config_flow.py * Update tests/components/point/test_config_flow.py * Fix --------- Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
90 lines
2.8 KiB
Python
90 lines
2.8 KiB
Python
"""Support for Minut Point sensors."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from homeassistant.components.sensor import (
|
|
DOMAIN as SENSOR_DOMAIN,
|
|
SensorDeviceClass,
|
|
SensorEntity,
|
|
SensorEntityDescription,
|
|
)
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import PERCENTAGE, UnitOfSoundPressure, UnitOfTemperature
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
from homeassistant.util.dt import parse_datetime
|
|
|
|
from . import MinutPointEntity
|
|
from .const import DOMAIN as POINT_DOMAIN, POINT_DISCOVERY_NEW
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|
SensorEntityDescription(
|
|
key="temperature",
|
|
suggested_display_precision=1,
|
|
device_class=SensorDeviceClass.TEMPERATURE,
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
|
),
|
|
SensorEntityDescription(
|
|
key="humidity",
|
|
suggested_display_precision=1,
|
|
device_class=SensorDeviceClass.HUMIDITY,
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
),
|
|
SensorEntityDescription(
|
|
key="sound",
|
|
suggested_display_precision=1,
|
|
device_class=SensorDeviceClass.SOUND_PRESSURE,
|
|
native_unit_of_measurement=UnitOfSoundPressure.WEIGHTED_DECIBEL_A,
|
|
),
|
|
)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
config_entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up a Point's sensors based on a config entry."""
|
|
|
|
async def async_discover_sensor(device_id):
|
|
"""Discover and add a discovered sensor."""
|
|
client = config_entry.runtime_data.client
|
|
async_add_entities(
|
|
[
|
|
MinutPointSensor(client, device_id, description)
|
|
for description in SENSOR_TYPES
|
|
],
|
|
True,
|
|
)
|
|
|
|
async_dispatcher_connect(
|
|
hass,
|
|
POINT_DISCOVERY_NEW.format(SENSOR_DOMAIN, POINT_DOMAIN),
|
|
async_discover_sensor,
|
|
)
|
|
|
|
|
|
class MinutPointSensor(MinutPointEntity, SensorEntity):
|
|
"""The platform class required by Home Assistant."""
|
|
|
|
def __init__(
|
|
self, point_client, device_id, description: SensorEntityDescription
|
|
) -> None:
|
|
"""Initialize the sensor."""
|
|
super().__init__(point_client, device_id, description.device_class)
|
|
self.entity_description = description
|
|
|
|
async def _update_callback(self):
|
|
"""Update the value of the sensor."""
|
|
_LOGGER.debug("Update sensor value for %s", self)
|
|
if self.is_updated:
|
|
self._attr_native_value = await self.device.sensor(self.device_class)
|
|
self._updated = parse_datetime(self.device.last_update)
|
|
self.async_write_ha_state()
|