mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Enable strict type checks for PEGELONLINE (#143563)
enable strict type checks for pegel_online
This commit is contained in:
parent
9e0a7122f5
commit
49522d93df
@ -386,6 +386,7 @@ homeassistant.components.pandora.*
|
|||||||
homeassistant.components.panel_custom.*
|
homeassistant.components.panel_custom.*
|
||||||
homeassistant.components.peblar.*
|
homeassistant.components.peblar.*
|
||||||
homeassistant.components.peco.*
|
homeassistant.components.peco.*
|
||||||
|
homeassistant.components.pegel_online.*
|
||||||
homeassistant.components.persistent_notification.*
|
homeassistant.components.persistent_notification.*
|
||||||
homeassistant.components.person.*
|
homeassistant.components.person.*
|
||||||
homeassistant.components.pi_hole.*
|
homeassistant.components.pi_hole.*
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from aiopegelonline.models import CurrentMeasurement
|
from aiopegelonline.models import CurrentMeasurement, StationMeasurements
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
@ -24,67 +25,67 @@ from .entity import PegelOnlineEntity
|
|||||||
class PegelOnlineSensorEntityDescription(SensorEntityDescription):
|
class PegelOnlineSensorEntityDescription(SensorEntityDescription):
|
||||||
"""PEGELONLINE sensor entity description."""
|
"""PEGELONLINE sensor entity description."""
|
||||||
|
|
||||||
measurement_key: str
|
measurement_fn: Callable[[StationMeasurements], CurrentMeasurement | None]
|
||||||
|
|
||||||
|
|
||||||
SENSORS: tuple[PegelOnlineSensorEntityDescription, ...] = (
|
SENSORS: tuple[PegelOnlineSensorEntityDescription, ...] = (
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="air_temperature",
|
key="air_temperature",
|
||||||
translation_key="air_temperature",
|
translation_key="air_temperature",
|
||||||
measurement_key="air_temperature",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
|
measurement_fn=lambda data: data.air_temperature,
|
||||||
),
|
),
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="clearance_height",
|
key="clearance_height",
|
||||||
translation_key="clearance_height",
|
translation_key="clearance_height",
|
||||||
measurement_key="clearance_height",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.DISTANCE,
|
device_class=SensorDeviceClass.DISTANCE,
|
||||||
|
measurement_fn=lambda data: data.clearance_height,
|
||||||
),
|
),
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="oxygen_level",
|
key="oxygen_level",
|
||||||
translation_key="oxygen_level",
|
translation_key="oxygen_level",
|
||||||
measurement_key="oxygen_level",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
|
measurement_fn=lambda data: data.oxygen_level,
|
||||||
),
|
),
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="ph_value",
|
key="ph_value",
|
||||||
measurement_key="ph_value",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.PH,
|
device_class=SensorDeviceClass.PH,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
|
measurement_fn=lambda data: data.ph_value,
|
||||||
),
|
),
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="water_speed",
|
key="water_speed",
|
||||||
translation_key="water_speed",
|
translation_key="water_speed",
|
||||||
measurement_key="water_speed",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.SPEED,
|
device_class=SensorDeviceClass.SPEED,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
|
measurement_fn=lambda data: data.water_speed,
|
||||||
),
|
),
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="water_flow",
|
key="water_flow",
|
||||||
translation_key="water_flow",
|
translation_key="water_flow",
|
||||||
measurement_key="water_flow",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
|
measurement_fn=lambda data: data.water_flow,
|
||||||
),
|
),
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="water_level",
|
key="water_level",
|
||||||
translation_key="water_level",
|
translation_key="water_level",
|
||||||
measurement_key="water_level",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
measurement_fn=lambda data: data.water_level,
|
||||||
),
|
),
|
||||||
PegelOnlineSensorEntityDescription(
|
PegelOnlineSensorEntityDescription(
|
||||||
key="water_temperature",
|
key="water_temperature",
|
||||||
translation_key="water_temperature",
|
translation_key="water_temperature",
|
||||||
measurement_key="water_temperature",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
|
measurement_fn=lambda data: data.water_temperature,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ async def async_setup_entry(
|
|||||||
[
|
[
|
||||||
PegelOnlineSensor(coordinator, description)
|
PegelOnlineSensor(coordinator, description)
|
||||||
for description in SENSORS
|
for description in SENSORS
|
||||||
if getattr(coordinator.data, description.measurement_key) is not None
|
if description.measurement_fn(coordinator.data) is not None
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -135,7 +136,9 @@ class PegelOnlineSensor(PegelOnlineEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def measurement(self) -> CurrentMeasurement:
|
def measurement(self) -> CurrentMeasurement:
|
||||||
"""Return the measurement data of the entity."""
|
"""Return the measurement data of the entity."""
|
||||||
return getattr(self.coordinator.data, self.entity_description.measurement_key)
|
measurement = self.entity_description.measurement_fn(self.coordinator.data)
|
||||||
|
assert measurement is not None # we ensure existence in async_setup_entry
|
||||||
|
return measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> float:
|
def native_value(self) -> float:
|
||||||
|
10
mypy.ini
generated
10
mypy.ini
generated
@ -3616,6 +3616,16 @@ disallow_untyped_defs = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.pegel_online.*]
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_incomplete_defs = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
disallow_untyped_calls = true
|
||||||
|
disallow_untyped_decorators = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.persistent_notification.*]
|
[mypy-homeassistant.components.persistent_notification.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user