Make use of generic EntityComponent (part 2) (#78494)

pull/78397/head
epenet 2022-09-17 18:18:53 +02:00 committed by GitHub
parent bbf54e6f44
commit 64988521bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 108 additions and 63 deletions

View File

@ -50,10 +50,12 @@ PROP_TO_ATTR: Final[dict[str, str]] = {
"sulphur_dioxide": ATTR_SO2,
}
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the air quality component."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[AirQualityEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -62,13 +64,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[AirQualityEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[AirQualityEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -55,10 +55,12 @@ ALARM_SERVICE_SCHEMA: Final = make_entity_service_schema(
PLATFORM_SCHEMA: Final = cv.PLATFORM_SCHEMA
PLATFORM_SCHEMA_BASE: Final = cv.PLATFORM_SCHEMA_BASE
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Track states and offer events for sensors."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[AlarmControlPanelEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
@ -109,13 +111,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[AlarmControlPanelEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[AlarmControlPanelEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -150,10 +150,12 @@ DEVICE_CLASS_UPDATE = BinarySensorDeviceClass.UPDATE.value
DEVICE_CLASS_VIBRATION = BinarySensorDeviceClass.VIBRATION.value
DEVICE_CLASS_WINDOW = BinarySensorDeviceClass.WINDOW.value
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Track states and offer events for binary sensors."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[BinarySensorEntity](
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL
)
@ -163,13 +165,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[BinarySensorEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[BinarySensorEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -41,10 +41,12 @@ class ButtonDeviceClass(StrEnum):
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(ButtonDeviceClass))
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Button entities."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[ButtonEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -60,13 +62,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[ButtonEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[ButtonEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -32,10 +32,12 @@ DOMAIN = "calendar"
ENTITY_ID_FORMAT = DOMAIN + ".{}"
SCAN_INTERVAL = datetime.timedelta(seconds=60)
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Track states and offer events for calendars."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[CalendarEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
@ -52,13 +54,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[CalendarEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[CalendarEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)
@ -243,7 +245,7 @@ class CalendarEventView(http.HomeAssistantView):
url = "/api/calendars/{entity_id}"
name = "api:calendars:calendar"
def __init__(self, component: EntityComponent) -> None:
def __init__(self, component: EntityComponent[CalendarEntity]) -> None:
"""Initialize calendar view."""
self.component = component
@ -294,7 +296,7 @@ class CalendarListView(http.HomeAssistantView):
url = "/api/calendars"
name = "api:calendars"
def __init__(self, component: EntityComponent) -> None:
def __init__(self, component: EntityComponent[CalendarEntity]) -> None:
"""Initialize calendar view."""
self.component = component

View File

@ -38,6 +38,8 @@ TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
}
)
# mypy: disallow-any-generics
class CalendarEventListener:
"""Helper class to listen to calendar events."""
@ -172,7 +174,7 @@ async def async_attach_trigger(
event_type = config[CONF_EVENT]
offset = config[CONF_OFFSET]
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[CalendarEntity] = hass.data[DOMAIN]
if not (entity := component.get_entity(entity_id)) or not isinstance(
entity, CalendarEntity
):

View File

@ -129,10 +129,12 @@ SET_TEMPERATURE_SCHEMA = vol.All(
),
)
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up climate entities."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[ClimateEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -189,13 +191,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[ClimateEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[ClimateEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -83,6 +83,8 @@ DEVICE_CLASS_SHADE = CoverDeviceClass.SHADE.value
DEVICE_CLASS_SHUTTER = CoverDeviceClass.SHUTTER.value
DEVICE_CLASS_WINDOW = CoverDeviceClass.WINDOW.value
# mypy: disallow-any-generics
class CoverEntityFeature(IntEnum):
"""Supported features of the cover entity."""
@ -122,7 +124,7 @@ def is_closed(hass: HomeAssistant, entity_id: str) -> bool:
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Track states and offer events for covers."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[CoverEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
@ -202,13 +204,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[CoverEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[CoverEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -33,15 +33,19 @@ from .const import (
SourceType,
)
# mypy: disallow-any-generics
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up an entry."""
component: EntityComponent | None = hass.data.get(DOMAIN)
component: EntityComponent[BaseTrackerEntity] | None = hass.data.get(DOMAIN)
if component is not None:
return await component.async_setup_entry(entry)
component = hass.data[DOMAIN] = EntityComponent(LOGGER, DOMAIN, hass)
component = hass.data[DOMAIN] = EntityComponent[BaseTrackerEntity](
LOGGER, DOMAIN, hass
)
# Clean up old devices created by device tracker entities in the past.
# Can be removed after 2022.6
@ -70,7 +74,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload an entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[BaseTrackerEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -74,6 +74,8 @@ ATTR_DIRECTION = "direction"
ATTR_PRESET_MODE = "preset_mode"
ATTR_PRESET_MODES = "preset_modes"
# mypy: disallow-any-generics
class NotValidPresetModeError(ValueError):
"""Exception class when the preset_mode in not in the preset_modes list."""
@ -89,7 +91,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Expose fan control via statemachine and services."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[FanEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
@ -163,13 +165,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[FanEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[FanEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -27,10 +27,12 @@ ENTITY_ID_FORMAT = DOMAIN + ".{}"
SCAN_INTERVAL = timedelta(seconds=60)
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Geolocation component."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[GeolocationEvent](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -39,13 +41,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[GeolocationEvent] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[GeolocationEvent] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -68,6 +68,8 @@ DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(HumidifierDeviceClass))
# use the HumidifierDeviceClass enum instead.
DEVICE_CLASSES = [cls.value for cls in HumidifierDeviceClass]
# mypy: disallow-any-generics
@bind_hass
def is_on(hass, entity_id):
@ -80,7 +82,7 @@ def is_on(hass, entity_id):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up humidifier devices."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[HumidifierEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -109,13 +111,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[HumidifierEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[HumidifierEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -60,10 +60,12 @@ SUPPORT_OPEN = 1
PROP_TO_ATTR = {"changed_by": ATTR_CHANGED_BY, "code_format": ATTR_CODE_FORMAT}
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Track states and offer events for locks."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[LockEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
@ -84,13 +86,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[LockEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[LockEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -56,10 +56,12 @@ PLATFORM_SCHEMA = vol.Schema(
extra=vol.ALLOW_EXTRA,
)
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the scenes."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[Scene](
logging.getLogger(__name__), DOMAIN, hass
)
@ -77,13 +79,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[Scene] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[Scene] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -29,10 +29,12 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
_LOGGER = logging.getLogger(__name__)
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Select entities."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[SelectEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -56,13 +58,13 @@ async def async_select_option(entity: SelectEntity, service_call: ServiceCall) -
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[SelectEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[SelectEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -226,10 +226,12 @@ VALID_UNITS: dict[str, tuple[str, ...]] = {
SensorDeviceClass.TEMPERATURE: temperature_util.VALID_UNITS,
}
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Track states and offer events for sensors."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[SensorEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
@ -239,13 +241,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component = cast(EntityComponent, hass.data[DOMAIN])
component: EntityComponent[SensorEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component = cast(EntityComponent, hass.data[DOMAIN])
component: EntityComponent[SensorEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -53,6 +53,9 @@ class SirenTurnOnServiceParameters(TypedDict, total=False):
volume_level: float
# mypy: disallow-any-generics
def process_turn_on_params(
siren: SirenEntity, params: SirenTurnOnServiceParameters
) -> SirenTurnOnServiceParameters:
@ -99,7 +102,7 @@ def process_turn_on_params(
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up siren devices."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[SirenEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -138,13 +141,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[SirenEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[SirenEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -51,6 +51,8 @@ DEVICE_CLASSES = [cls.value for cls in SwitchDeviceClass]
DEVICE_CLASS_OUTLET = SwitchDeviceClass.OUTLET.value
DEVICE_CLASS_SWITCH = SwitchDeviceClass.SWITCH.value
# mypy: disallow-any-generics
@bind_hass
def is_on(hass: HomeAssistant, entity_id: str) -> bool:
@ -63,7 +65,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Track states and offer events for switches."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[SwitchEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -77,13 +79,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[SwitchEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[SwitchEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -110,6 +110,8 @@ SUPPORT_MAP = 2048
SUPPORT_STATE = 4096
SUPPORT_START = 8192
# mypy: disallow-any-generics
@bind_hass
def is_on(hass: HomeAssistant, entity_id: str) -> bool:
@ -119,7 +121,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the vacuum component."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[_BaseVacuum](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
@ -158,13 +160,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[_BaseVacuum] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[_BaseVacuum] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -107,10 +107,12 @@ SET_OPERATION_MODE_SCHEMA = vol.Schema(
}
)
# mypy: disallow-any-generics
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up water_heater devices."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[WaterHeaterEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -138,13 +140,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[WaterHeaterEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[WaterHeaterEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)

View File

@ -141,6 +141,8 @@ VALID_UNITS: dict[str, tuple[str, ...]] = {
ATTR_WEATHER_WIND_SPEED_UNIT: VALID_UNITS_WIND_SPEED,
}
# mypy: disallow-any-generics
def round_temperature(temperature: float | None, precision: float) -> float | None:
"""Convert temperature into preferred precision for display."""
@ -183,7 +185,7 @@ class Forecast(TypedDict, total=False):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the weather component."""
component = hass.data[DOMAIN] = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent[WeatherEntity](
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
@ -192,13 +194,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[WeatherEntity] = hass.data[DOMAIN]
return await component.async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
component: EntityComponent = hass.data[DOMAIN]
component: EntityComponent[WeatherEntity] = hass.data[DOMAIN]
return await component.async_unload_entry(entry)