mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Simplify Idasen Desk entity properties (#133536)
This commit is contained in:
parent
9f3c549f8d
commit
0076bd8389
@ -12,7 +12,7 @@ from homeassistant.components.cover import (
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
@ -46,7 +46,6 @@ class IdasenDeskCover(IdasenDeskEntity, CoverEntity):
|
||||
def __init__(self, coordinator: IdasenDeskCoordinator) -> None:
|
||||
"""Initialize an Idasen Desk cover."""
|
||||
super().__init__(coordinator.address, coordinator)
|
||||
self._attr_current_cover_position = self._desk.height_percent
|
||||
|
||||
@property
|
||||
def is_closed(self) -> bool:
|
||||
@ -83,8 +82,7 @@ class IdasenDeskCover(IdasenDeskEntity, CoverEntity):
|
||||
"Failed to move to specified position: Bluetooth error"
|
||||
) from err
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self, *args: Any) -> None:
|
||||
"""Handle data update."""
|
||||
self._attr_current_cover_position = self._desk.height_percent
|
||||
self.async_write_ha_state()
|
||||
@property
|
||||
def current_cover_position(self) -> int | None:
|
||||
"""Return the current cover position."""
|
||||
return self._desk.height_percent
|
||||
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
@ -13,7 +12,7 @@ from homeassistant.components.sensor import (
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import UnitOfLength
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import IdasenDeskConfigEntry, IdasenDeskCoordinator
|
||||
@ -68,17 +67,7 @@ class IdasenDeskSensor(IdasenDeskEntity, SensorEntity):
|
||||
super().__init__(f"{description.key}-{coordinator.address}", coordinator)
|
||||
self.entity_description = description
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""When entity is added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
self._update_native_value()
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self, *args: Any) -> None:
|
||||
"""Handle data update."""
|
||||
self._update_native_value()
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
def _update_native_value(self) -> None:
|
||||
"""Update the native value attribute."""
|
||||
self._attr_native_value = self.entity_description.value_fn(self.coordinator)
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the value reported by the sensor."""
|
||||
return self.entity_description.value_fn(self.coordinator)
|
||||
|
Loading…
x
Reference in New Issue
Block a user