Fix meater sensor (#71283)
* Fix meater sensor * Cleanup MeaterEntityDescription * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com>pull/71297/head
parent
bf17bd55fd
commit
44d17a80c3
|
@ -27,15 +27,18 @@ from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MeaterSensorEntityDescription(SensorEntityDescription):
|
class MeaterSensorEntityDescriptionMixin:
|
||||||
"""Describes meater sensor entity."""
|
"""Mixin for MeaterSensorEntityDescription."""
|
||||||
|
|
||||||
available: Callable[
|
available: Callable[[MeaterProbe | None], bool]
|
||||||
[MeaterProbe | None], bool | type[NotImplementedError]
|
value: Callable[[MeaterProbe], datetime | float | str | None]
|
||||||
] = lambda x: NotImplementedError
|
|
||||||
value: Callable[
|
|
||||||
[MeaterProbe], datetime | float | str | None | type[NotImplementedError]
|
@dataclass
|
||||||
] = lambda x: NotImplementedError
|
class MeaterSensorEntityDescription(
|
||||||
|
SensorEntityDescription, MeaterSensorEntityDescriptionMixin
|
||||||
|
):
|
||||||
|
"""Describes meater sensor entity."""
|
||||||
|
|
||||||
|
|
||||||
def _elapsed_time_to_timestamp(probe: MeaterProbe) -> datetime | None:
|
def _elapsed_time_to_timestamp(probe: MeaterProbe) -> datetime | None:
|
||||||
|
@ -108,7 +111,8 @@ SENSOR_TYPES = (
|
||||||
available=lambda probe: probe is not None and probe.cook is not 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,
|
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(
|
MeaterSensorEntityDescription(
|
||||||
key="cook_time_remaining",
|
key="cook_time_remaining",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
|
@ -116,7 +120,8 @@ SENSOR_TYPES = (
|
||||||
available=lambda probe: probe is not None and probe.cook is not None,
|
available=lambda probe: probe is not None and probe.cook is not None,
|
||||||
value=_remaining_time_to_timestamp,
|
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(
|
MeaterSensorEntityDescription(
|
||||||
key="cook_time_elapsed",
|
key="cook_time_elapsed",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
|
@ -147,7 +152,7 @@ async def async_setup_entry(
|
||||||
|
|
||||||
# Add entities for temperature probes which we've not yet seen
|
# Add entities for temperature probes which we've not yet seen
|
||||||
for dev in devices:
|
for dev in devices:
|
||||||
if dev in known_probes:
|
if dev.id in known_probes:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entities.extend(
|
entities.extend(
|
||||||
|
@ -156,7 +161,7 @@ async def async_setup_entry(
|
||||||
for sensor_description in SENSOR_TYPES
|
for sensor_description in SENSOR_TYPES
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
known_probes.add(dev)
|
known_probes.add(dev.id)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue