Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions homeassistant/components/meater/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@


@dataclass
class MeaterSensorEntityDescription(SensorEntityDescription):
"""Describes meater sensor entity."""
class MeaterSensorEntityDescriptionMixin:
"""Mixin for MeaterSensorEntityDescription."""

available: Callable[[MeaterProbe | None], bool]
value: Callable[[MeaterProbe], datetime | float | str | None]

available: Callable[
[MeaterProbe | None], bool | type[NotImplementedError]
] = lambda x: NotImplementedError
value: Callable[
[MeaterProbe], datetime | float | str | None | type[NotImplementedError]
] = lambda x: NotImplementedError

@dataclass
class MeaterSensorEntityDescription(
SensorEntityDescription, MeaterSensorEntityDescriptionMixin
):
"""Describes meater sensor entity."""


def _elapsed_time_to_timestamp(probe: MeaterProbe) -> datetime | None:
Expand Down Expand Up @@ -108,15 +111,17 @@ def _remaining_time_to_timestamp(probe: MeaterProbe) -> datetime | None:
available=lambda probe: probe is not None and probe.cook is not None,
value=lambda probe: probe.cook.peak_temperature if probe.cook else None,
),
# Time since the start of cook in seconds. Default: 0.
# Remaining time in seconds. When unknown/calculating default is used. Default: -1
# Exposed as a TIMESTAMP sensor where the timestamp is current time + remaining time.
MeaterSensorEntityDescription(
key="cook_time_remaining",
device_class=SensorDeviceClass.TIMESTAMP,
name="Remaining time",
available=lambda probe: probe is not None and probe.cook is not None,
value=_remaining_time_to_timestamp,
),
# Remaining time in seconds. When unknown/calculating default is used. Default: -1
# Time since the start of cook in seconds. Default: 0. Exposed as a TIMESTAMP sensor
# where the timestamp is current time - elapsed time.
MeaterSensorEntityDescription(
key="cook_time_elapsed",
device_class=SensorDeviceClass.TIMESTAMP,
Expand Down Expand Up @@ -147,7 +152,7 @@ def async_update_data():

# Add entities for temperature probes which we've not yet seen
for dev in devices:
if dev in known_probes:
if dev.id in known_probes:
continue

entities.extend(
Expand All @@ -156,7 +161,7 @@ def async_update_data():
for sensor_description in SENSOR_TYPES
]
)
known_probes.add(dev)
known_probes.add(dev.id)

async_add_entities(entities)

Expand Down