mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Remove entity description in Point (#112921)
This commit is contained in:
parent
d29418ebf5
commit
d0a1781187
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
@ -24,36 +23,22 @@ from .const import DOMAIN as POINT_DOMAIN, POINT_DISCOVERY_NEW
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
class MinutPointRequiredKeysMixin:
|
SensorEntityDescription(
|
||||||
"""Mixin for required keys."""
|
|
||||||
|
|
||||||
precision: int
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class MinutPointSensorEntityDescription(
|
|
||||||
SensorEntityDescription, MinutPointRequiredKeysMixin
|
|
||||||
):
|
|
||||||
"""Describes MinutPoint sensor entity."""
|
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[MinutPointSensorEntityDescription, ...] = (
|
|
||||||
MinutPointSensorEntityDescription(
|
|
||||||
key="temperature",
|
key="temperature",
|
||||||
precision=1,
|
suggested_display_precision=1,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
),
|
),
|
||||||
MinutPointSensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="humidity",
|
key="humidity",
|
||||||
precision=1,
|
suggested_display_precision=1,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
),
|
),
|
||||||
MinutPointSensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="sound",
|
key="sound",
|
||||||
precision=1,
|
suggested_display_precision=1,
|
||||||
device_class=SensorDeviceClass.SOUND_PRESSURE,
|
device_class=SensorDeviceClass.SOUND_PRESSURE,
|
||||||
native_unit_of_measurement=UnitOfSoundPressure.WEIGHTED_DECIBEL_A,
|
native_unit_of_measurement=UnitOfSoundPressure.WEIGHTED_DECIBEL_A,
|
||||||
),
|
),
|
||||||
@ -86,10 +71,8 @@ async def async_setup_entry(
|
|||||||
class MinutPointSensor(MinutPointEntity, SensorEntity):
|
class MinutPointSensor(MinutPointEntity, SensorEntity):
|
||||||
"""The platform class required by Home Assistant."""
|
"""The platform class required by Home Assistant."""
|
||||||
|
|
||||||
entity_description: MinutPointSensorEntityDescription
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, point_client, device_id, description: MinutPointSensorEntityDescription
|
self, point_client, device_id, description: SensorEntityDescription
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(point_client, device_id, description.device_class)
|
super().__init__(point_client, device_id, description.device_class)
|
||||||
@ -100,9 +83,5 @@ class MinutPointSensor(MinutPointEntity, SensorEntity):
|
|||||||
_LOGGER.debug("Update sensor value for %s", self)
|
_LOGGER.debug("Update sensor value for %s", self)
|
||||||
if self.is_updated:
|
if self.is_updated:
|
||||||
self._attr_native_value = await self.device.sensor(self.device_class)
|
self._attr_native_value = await self.device.sensor(self.device_class)
|
||||||
if self.native_value is not None:
|
|
||||||
self._attr_native_value = round(
|
|
||||||
self.native_value, self.entity_description.precision
|
|
||||||
)
|
|
||||||
self._updated = parse_datetime(self.device.last_update)
|
self._updated = parse_datetime(self.device.last_update)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user