mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add strict typing for govee_ble (#128044)
This commit is contained in:
parent
23a1046a8f
commit
e6bba49bcd
@ -214,6 +214,7 @@ homeassistant.components.google_assistant_sdk.*
|
||||
homeassistant.components.google_cloud.*
|
||||
homeassistant.components.google_photos.*
|
||||
homeassistant.components.google_sheets.*
|
||||
homeassistant.components.govee_ble.*
|
||||
homeassistant.components.gpsd.*
|
||||
homeassistant.components.greeneye_monitor.*
|
||||
homeassistant.components.group.*
|
||||
|
@ -44,7 +44,7 @@ BINARY_SENSOR_DESCRIPTIONS = {
|
||||
|
||||
def sensor_update_to_bluetooth_data_update(
|
||||
sensor_update: SensorUpdate,
|
||||
) -> PassiveBluetoothDataUpdate:
|
||||
) -> PassiveBluetoothDataUpdate[bool | None]:
|
||||
"""Convert a sensor update to a bluetooth data update."""
|
||||
return PassiveBluetoothDataUpdate(
|
||||
devices={
|
||||
@ -95,13 +95,13 @@ class GoveeBluetoothBinarySensorEntity(
|
||||
):
|
||||
"""Representation of a govee-ble binary sensor."""
|
||||
|
||||
processor: GoveeBLEPassiveBluetoothDataProcessor
|
||||
processor: GoveeBLEPassiveBluetoothDataProcessor[bool | None]
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return False if sensor is in error."""
|
||||
coordinator = self.processor.coordinator
|
||||
return self.processor.entity_data.get(self.entity_key) != ERROR and (
|
||||
return self.processor.entity_data.get(self.entity_key) != ERROR and ( # type: ignore[comparison-overlap]
|
||||
((model_info := coordinator.model_info) and model_info.sleepy)
|
||||
or super().available
|
||||
)
|
||||
|
@ -1,5 +1,7 @@
|
||||
"""The govee Bluetooth integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from logging import Logger
|
||||
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from govee_ble import DeviceClass, SensorUpdate, Units
|
||||
from govee_ble.parser import ERROR
|
||||
|
||||
@ -29,6 +32,8 @@ from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
|
||||
from .coordinator import GoveeBLEConfigEntry, GoveeBLEPassiveBluetoothDataProcessor
|
||||
from .device import device_key_to_bluetooth_entity_key
|
||||
|
||||
type _SensorValueType = str | int | float | date | datetime | Decimal | None
|
||||
|
||||
SENSOR_DESCRIPTIONS = {
|
||||
(DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
|
||||
key=f"{DeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
|
||||
@ -72,7 +77,7 @@ SENSOR_DESCRIPTIONS = {
|
||||
|
||||
def sensor_update_to_bluetooth_data_update(
|
||||
sensor_update: SensorUpdate,
|
||||
) -> PassiveBluetoothDataUpdate:
|
||||
) -> PassiveBluetoothDataUpdate[_SensorValueType]:
|
||||
"""Convert a sensor update to a bluetooth data update."""
|
||||
return PassiveBluetoothDataUpdate(
|
||||
devices={
|
||||
@ -117,13 +122,13 @@ async def async_setup_entry(
|
||||
|
||||
class GoveeBluetoothSensorEntity(
|
||||
PassiveBluetoothProcessorEntity[
|
||||
PassiveBluetoothDataProcessor[float | int | str | None, SensorUpdate]
|
||||
PassiveBluetoothDataProcessor[_SensorValueType, SensorUpdate]
|
||||
],
|
||||
SensorEntity,
|
||||
):
|
||||
"""Representation of a govee ble sensor."""
|
||||
|
||||
processor: GoveeBLEPassiveBluetoothDataProcessor
|
||||
processor: GoveeBLEPassiveBluetoothDataProcessor[_SensorValueType]
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
@ -135,6 +140,6 @@ class GoveeBluetoothSensorEntity(
|
||||
)
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | int | str | None:
|
||||
def native_value(self) -> _SensorValueType: # pylint: disable=hass-return-type
|
||||
"""Return the native value."""
|
||||
return self.processor.entity_data.get(self.entity_key)
|
||||
|
10
mypy.ini
10
mypy.ini
@ -1895,6 +1895,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.govee_ble.*]
|
||||
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.gpsd.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user