Improve picnic typing (#104587)

pull/104592/head
Marc Mueller 2023-11-27 13:13:02 +01:00 committed by GitHub
parent a5fd479608
commit ba8e2ed7d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 14 deletions

View File

@ -17,10 +17,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt as dt_util
from .const import (
@ -44,6 +41,7 @@ from .const import (
SENSOR_SELECTED_SLOT_MIN_ORDER_VALUE,
SENSOR_SELECTED_SLOT_START,
)
from .coordinator import PicnicUpdateCoordinator
@dataclass
@ -237,7 +235,7 @@ async def async_setup_entry(
)
class PicnicSensor(SensorEntity, CoordinatorEntity):
class PicnicSensor(SensorEntity, CoordinatorEntity[PicnicUpdateCoordinator]):
"""The CoordinatorEntity subclass representing Picnic sensors."""
_attr_has_entity_name = True
@ -246,7 +244,7 @@ class PicnicSensor(SensorEntity, CoordinatorEntity):
def __init__(
self,
coordinator: DataUpdateCoordinator[Any],
coordinator: PicnicUpdateCoordinator,
config_entry: ConfigEntry,
description: PicnicSensorEntityDescription,
) -> None:

View File

@ -77,8 +77,11 @@ async def handle_add_product(
)
def product_search(api_client: PicnicAPI, product_name: str) -> None | str:
def product_search(api_client: PicnicAPI, product_name: str | None) -> None | str:
"""Query the api client for the product name."""
if product_name is None:
return None
search_result = api_client.search(product_name)
if not search_result or "items" not in search_result[0]:

View File

@ -2,7 +2,7 @@
from __future__ import annotations
import logging
from typing import Any, cast
from typing import cast
from homeassistant.components.todo import (
TodoItem,
@ -14,12 +14,10 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import CONF_COORDINATOR, DOMAIN
from .coordinator import PicnicUpdateCoordinator
from .services import product_search
_LOGGER = logging.getLogger(__name__)
@ -36,7 +34,7 @@ async def async_setup_entry(
async_add_entities([PicnicCart(hass, picnic_coordinator, config_entry)])
class PicnicCart(TodoListEntity, CoordinatorEntity):
class PicnicCart(TodoListEntity, CoordinatorEntity[PicnicUpdateCoordinator]):
"""A Picnic Shopping Cart TodoListEntity."""
_attr_has_entity_name = True
@ -47,7 +45,7 @@ class PicnicCart(TodoListEntity, CoordinatorEntity):
def __init__(
self,
hass: HomeAssistant,
coordinator: DataUpdateCoordinator[Any],
coordinator: PicnicUpdateCoordinator,
config_entry: ConfigEntry,
) -> None:
"""Initialize PicnicCart."""