Improve `sleepiq` generic typing (#85330)
parent
e99840f82c
commit
a2ef0caa07
|
@ -8,10 +8,9 @@ from homeassistant.components.binary_sensor import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN, ICON_EMPTY, ICON_OCCUPIED, IS_IN_BED
|
||||
from .coordinator import SleepIQData
|
||||
from .coordinator import SleepIQData, SleepIQDataUpdateCoordinator
|
||||
from .entity import SleepIQSleeperEntity
|
||||
|
||||
|
||||
|
@ -29,14 +28,16 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class IsInBedBinarySensor(SleepIQSleeperEntity, BinarySensorEntity):
|
||||
class IsInBedBinarySensor(
|
||||
SleepIQSleeperEntity[SleepIQDataUpdateCoordinator], BinarySensorEntity
|
||||
):
|
||||
"""Implementation of a SleepIQ presence sensor."""
|
||||
|
||||
_attr_device_class = BinarySensorDeviceClass.OCCUPANCY
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
coordinator: SleepIQDataUpdateCoordinator,
|
||||
bed: SleepIQBed,
|
||||
sleeper: SleepIQSleeper,
|
||||
) -> None:
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
"""Entity for the SleepIQ integration."""
|
||||
from abc import abstractmethod
|
||||
from typing import TypeVar, Union
|
||||
|
||||
from asyncsleepiq import SleepIQBed, SleepIQSleeper
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import ENTITY_TYPES, ICON_OCCUPIED
|
||||
from .coordinator import SleepIQDataUpdateCoordinator, SleepIQPauseUpdateCoordinator
|
||||
|
||||
_SleepIQCoordinatorT = TypeVar(
|
||||
"_SleepIQCoordinatorT",
|
||||
bound=Union[SleepIQDataUpdateCoordinator, SleepIQPauseUpdateCoordinator],
|
||||
)
|
||||
|
||||
|
||||
def device_from_bed(bed: SleepIQBed) -> DeviceInfo:
|
||||
|
@ -33,14 +37,14 @@ class SleepIQEntity(Entity):
|
|||
self._attr_device_info = device_from_bed(bed)
|
||||
|
||||
|
||||
class SleepIQBedEntity(CoordinatorEntity):
|
||||
class SleepIQBedEntity(CoordinatorEntity[_SleepIQCoordinatorT]):
|
||||
"""Implementation of a SleepIQ sensor."""
|
||||
|
||||
_attr_icon = ICON_OCCUPIED
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
coordinator: _SleepIQCoordinatorT,
|
||||
bed: SleepIQBed,
|
||||
) -> None:
|
||||
"""Initialize the SleepIQ sensor entity."""
|
||||
|
@ -61,14 +65,14 @@ class SleepIQBedEntity(CoordinatorEntity):
|
|||
"""Update sensor attributes."""
|
||||
|
||||
|
||||
class SleepIQSleeperEntity(SleepIQBedEntity):
|
||||
class SleepIQSleeperEntity(SleepIQBedEntity[_SleepIQCoordinatorT]):
|
||||
"""Implementation of a SleepIQ sensor."""
|
||||
|
||||
_attr_icon = ICON_OCCUPIED
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
coordinator: _SleepIQCoordinatorT,
|
||||
bed: SleepIQBed,
|
||||
sleeper: SleepIQSleeper,
|
||||
name: str,
|
||||
|
|
|
@ -8,10 +8,9 @@ from homeassistant.components.light import ColorMode, LightEntity
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import SleepIQData
|
||||
from .coordinator import SleepIQData, SleepIQDataUpdateCoordinator
|
||||
from .entity import SleepIQBedEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -31,14 +30,17 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class SleepIQLightEntity(SleepIQBedEntity, LightEntity):
|
||||
class SleepIQLightEntity(SleepIQBedEntity[SleepIQDataUpdateCoordinator], LightEntity):
|
||||
"""Representation of a light."""
|
||||
|
||||
_attr_color_mode = ColorMode.ONOFF
|
||||
_attr_supported_color_modes = {ColorMode.ONOFF}
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, bed: SleepIQBed, light: SleepIQLight
|
||||
self,
|
||||
coordinator: SleepIQDataUpdateCoordinator,
|
||||
bed: SleepIQBed,
|
||||
light: SleepIQLight,
|
||||
) -> None:
|
||||
"""Initialize the light."""
|
||||
self.light = light
|
||||
|
|
|
@ -11,10 +11,9 @@ from homeassistant.components.number import NumberEntity, NumberEntityDescriptio
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import ACTUATOR, DOMAIN, ENTITY_TYPES, FIRMNESS, ICON_OCCUPIED
|
||||
from .coordinator import SleepIQData
|
||||
from .coordinator import SleepIQData, SleepIQDataUpdateCoordinator
|
||||
from .entity import SleepIQBedEntity
|
||||
|
||||
|
||||
|
@ -130,7 +129,7 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class SleepIQNumberEntity(SleepIQBedEntity, NumberEntity):
|
||||
class SleepIQNumberEntity(SleepIQBedEntity[SleepIQDataUpdateCoordinator], NumberEntity):
|
||||
"""Representation of a SleepIQ number entity."""
|
||||
|
||||
entity_description: SleepIQNumberEntityDescription
|
||||
|
@ -138,7 +137,7 @@ class SleepIQNumberEntity(SleepIQBedEntity, NumberEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
coordinator: SleepIQDataUpdateCoordinator,
|
||||
bed: SleepIQBed,
|
||||
device: Any,
|
||||
description: SleepIQNumberEntityDescription,
|
||||
|
|
|
@ -7,10 +7,9 @@ from homeassistant.components.select import SelectEntity
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import SleepIQData
|
||||
from .coordinator import SleepIQData, SleepIQDataUpdateCoordinator
|
||||
from .entity import SleepIQBedEntity
|
||||
|
||||
|
||||
|
@ -28,13 +27,16 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class SleepIQSelectEntity(SleepIQBedEntity, SelectEntity):
|
||||
class SleepIQSelectEntity(SleepIQBedEntity[SleepIQDataUpdateCoordinator], SelectEntity):
|
||||
"""Representation of a SleepIQ select entity."""
|
||||
|
||||
_attr_options = list(BED_PRESETS)
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, bed: SleepIQBed, preset: SleepIQPreset
|
||||
self,
|
||||
coordinator: SleepIQDataUpdateCoordinator,
|
||||
bed: SleepIQBed,
|
||||
preset: SleepIQPreset,
|
||||
) -> None:
|
||||
"""Initialize the select entity."""
|
||||
self.preset = preset
|
||||
|
|
|
@ -7,10 +7,9 @@ from homeassistant.components.sensor import SensorEntity, SensorStateClass
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN, PRESSURE, SLEEP_NUMBER
|
||||
from .coordinator import SleepIQData
|
||||
from .coordinator import SleepIQData, SleepIQDataUpdateCoordinator
|
||||
from .entity import SleepIQSleeperEntity
|
||||
|
||||
SENSORS = [PRESSURE, SLEEP_NUMBER]
|
||||
|
@ -31,14 +30,16 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class SleepIQSensorEntity(SleepIQSleeperEntity, SensorEntity):
|
||||
class SleepIQSensorEntity(
|
||||
SleepIQSleeperEntity[SleepIQDataUpdateCoordinator], SensorEntity
|
||||
):
|
||||
"""Representation of an SleepIQ Entity with CoordinatorEntity."""
|
||||
|
||||
_attr_icon = "mdi:bed"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
coordinator: SleepIQDataUpdateCoordinator,
|
||||
bed: SleepIQBed,
|
||||
sleeper: SleepIQSleeper,
|
||||
sensor_type: str,
|
||||
|
|
|
@ -28,7 +28,9 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class SleepNumberPrivateSwitch(SleepIQBedEntity, SwitchEntity):
|
||||
class SleepNumberPrivateSwitch(
|
||||
SleepIQBedEntity[SleepIQPauseUpdateCoordinator], SwitchEntity
|
||||
):
|
||||
"""Representation of SleepIQ privacy mode."""
|
||||
|
||||
def __init__(
|
||||
|
|
Loading…
Reference in New Issue