Fix husqvarna_automower typing (#116060)

This commit is contained in:
J. Nick Koston 2024-04-23 22:50:31 +02:00 committed by GitHub
parent f828eb2301
commit 0f60b404df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,7 @@
from collections.abc import Awaitable, Callable from collections.abc import Awaitable, Callable
from dataclasses import dataclass from dataclasses import dataclass
import logging import logging
from typing import Any from typing import TYPE_CHECKING, Any
from aioautomower.exceptions import ApiException from aioautomower.exceptions import ApiException
from aioautomower.model import MowerAttributes from aioautomower.model import MowerAttributes
@ -12,7 +12,7 @@ from aioautomower.session import AutomowerSession
from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -32,6 +32,15 @@ class AutomowerNumberEntityDescription(NumberEntityDescription):
set_value_fn: Callable[[AutomowerSession, str, float], Awaitable[Any]] set_value_fn: Callable[[AutomowerSession, str, float], Awaitable[Any]]
@callback
def _async_get_cutting_height(data: MowerAttributes) -> int:
"""Return the cutting height."""
if TYPE_CHECKING:
# Sensor does not get created if it is None
assert data.cutting_height is not None
return data.cutting_height
NUMBER_TYPES: tuple[AutomowerNumberEntityDescription, ...] = ( NUMBER_TYPES: tuple[AutomowerNumberEntityDescription, ...] = (
AutomowerNumberEntityDescription( AutomowerNumberEntityDescription(
key="cutting_height", key="cutting_height",
@ -41,7 +50,7 @@ NUMBER_TYPES: tuple[AutomowerNumberEntityDescription, ...] = (
native_min_value=1, native_min_value=1,
native_max_value=9, native_max_value=9,
exists_fn=lambda data: data.cutting_height is not None, exists_fn=lambda data: data.cutting_height is not None,
value_fn=lambda data: data.cutting_height, value_fn=_async_get_cutting_height,
set_value_fn=lambda session, mower_id, cheight: session.set_cutting_height( set_value_fn=lambda session, mower_id, cheight: session.set_cutting_height(
mower_id, int(cheight) mower_id, int(cheight)
), ),