Skip to content

Commit

Permalink
Simplify Idasen Desk entity properties (#133536)
Browse files Browse the repository at this point in the history
  • Loading branch information
abmantis authored Dec 18, 2024
1 parent 9f3c549 commit 0076bd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
12 changes: 5 additions & 7 deletions homeassistant/components/idasen_desk/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -83,8 +82,7 @@ async def async_set_cover_position(self, **kwargs: Any) -> None:
"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
21 changes: 5 additions & 16 deletions homeassistant/components/idasen_desk/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from collections.abc import Callable
from dataclasses import dataclass
from typing import Any

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand All @@ -13,7 +12,7 @@
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
Expand Down Expand Up @@ -68,17 +67,7 @@ def __init__(
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)

0 comments on commit 0076bd8

Please sign in to comment.