mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Improve type annotation in the Shelly text and number platform (#143568)
* Define _id with type * Define attribute_value with type
This commit is contained in:
parent
061a1be2bc
commit
290bbcfa3e
@ -66,6 +66,8 @@ class RpcNumber(ShellyRpcAttributeEntity, NumberEntity):
|
|||||||
"""Represent a RPC number entity."""
|
"""Represent a RPC number entity."""
|
||||||
|
|
||||||
entity_description: RpcNumberDescription
|
entity_description: RpcNumberDescription
|
||||||
|
attribute_value: float | None
|
||||||
|
_id: int | None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -93,9 +95,6 @@ class RpcNumber(ShellyRpcAttributeEntity, NumberEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self) -> float | None:
|
def native_value(self) -> float | None:
|
||||||
"""Return value of number."""
|
"""Return value of number."""
|
||||||
if TYPE_CHECKING:
|
|
||||||
assert isinstance(self.attribute_value, float | None)
|
|
||||||
|
|
||||||
return self.attribute_value
|
return self.attribute_value
|
||||||
|
|
||||||
@rpc_call
|
@rpc_call
|
||||||
@ -104,7 +103,6 @@ class RpcNumber(ShellyRpcAttributeEntity, NumberEntity):
|
|||||||
method = getattr(self.coordinator.device, self.entity_description.method)
|
method = getattr(self.coordinator.device, self.entity_description.method)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert isinstance(self._id, int)
|
|
||||||
assert method is not None
|
assert method is not None
|
||||||
|
|
||||||
await method(self._id, value)
|
await method(self._id, value)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Final
|
from typing import Final
|
||||||
|
|
||||||
from aioshelly.const import RPC_GENERATIONS
|
from aioshelly.const import RPC_GENERATIONS
|
||||||
|
|
||||||
@ -76,14 +76,12 @@ class RpcText(ShellyRpcAttributeEntity, TextEntity):
|
|||||||
"""Represent a RPC text entity."""
|
"""Represent a RPC text entity."""
|
||||||
|
|
||||||
entity_description: RpcTextDescription
|
entity_description: RpcTextDescription
|
||||||
|
attribute_value: str | None
|
||||||
_id: int
|
_id: int
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> str | None:
|
def native_value(self) -> str | None:
|
||||||
"""Return value of sensor."""
|
"""Return value of sensor."""
|
||||||
if TYPE_CHECKING:
|
|
||||||
assert isinstance(self.attribute_value, str | None)
|
|
||||||
|
|
||||||
return self.attribute_value
|
return self.attribute_value
|
||||||
|
|
||||||
@rpc_call
|
@rpc_call
|
||||||
|
Loading…
x
Reference in New Issue
Block a user