mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Fix husqvarna_automower typing (#116060)
This commit is contained in:
parent
f828eb2301
commit
0f60b404df
@ -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)
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user