mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-11-13 15:43:52 -05:00
Code cleanup
This commit is contained in:
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Any, Callable
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
@@ -18,27 +15,19 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import OasisMiniCoordinator
|
from .coordinator import OasisMiniCoordinator
|
||||||
from .entity import OasisMiniEntity
|
from .entity import OasisMiniEntity
|
||||||
from .pyoasismini import OasisMini
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
async def async_setup_entry(
|
||||||
class OasisMiniSensorEntityDescription(SensorEntityDescription):
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
"""Oasis Mini sensor entity description."""
|
) -> None:
|
||||||
|
"""Set up Oasis Mini sensors using config entry."""
|
||||||
lookup_fn: Callable[[OasisMini], Any] | None = None
|
coordinator: OasisMiniCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
async_add_entities(
|
||||||
|
[
|
||||||
class OasisMiniSensorEntity(OasisMiniEntity, SensorEntity):
|
OasisMiniSensorEntity(coordinator, entry, descriptor)
|
||||||
"""Oasis Mini sensor entity."""
|
for descriptor in DESCRIPTORS
|
||||||
|
]
|
||||||
entity_description: OasisMiniSensorEntityDescription | SensorEntityDescription
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self) -> str | None:
|
|
||||||
"""Return the value reported by the sensor."""
|
|
||||||
if lookup_fn := getattr(self.entity_description, "lookup_fn", None):
|
|
||||||
return lookup_fn(self.device)
|
|
||||||
return getattr(self.device, self.entity_description.key)
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTORS = {
|
DESCRIPTORS = {
|
||||||
@@ -49,9 +38,7 @@ DESCRIPTORS = {
|
|||||||
name="Download progress",
|
name="Download progress",
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
}
|
} | {
|
||||||
|
|
||||||
OTHERS = {
|
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key=key,
|
key=key,
|
||||||
name=key.replace("_", " ").capitalize(),
|
name=key.replace("_", " ").capitalize(),
|
||||||
@@ -68,14 +55,10 @@ OTHERS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
class OasisMiniSensorEntity(OasisMiniEntity, SensorEntity):
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
"""Oasis Mini sensor entity."""
|
||||||
) -> None:
|
|
||||||
"""Set up Oasis Mini sensors using config entry."""
|
@property
|
||||||
coordinator: OasisMiniCoordinator = hass.data[DOMAIN][entry.entry_id]
|
def native_value(self) -> str | None:
|
||||||
async_add_entities(
|
"""Return the value reported by the sensor."""
|
||||||
[
|
return getattr(self.device, self.entity_description.key)
|
||||||
OasisMiniSensorEntity(coordinator, entry, descriptor)
|
|
||||||
for descriptor in DESCRIPTORS | OTHERS
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user