mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +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."""
|
||||
|
||||
entity_description: RpcNumberDescription
|
||||
attribute_value: float | None
|
||||
_id: int | None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -93,9 +95,6 @@ class RpcNumber(ShellyRpcAttributeEntity, NumberEntity):
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
"""Return value of number."""
|
||||
if TYPE_CHECKING:
|
||||
assert isinstance(self.attribute_value, float | None)
|
||||
|
||||
return self.attribute_value
|
||||
|
||||
@rpc_call
|
||||
@ -104,7 +103,6 @@ class RpcNumber(ShellyRpcAttributeEntity, NumberEntity):
|
||||
method = getattr(self.coordinator.device, self.entity_description.method)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
assert isinstance(self._id, int)
|
||||
assert method is not None
|
||||
|
||||
await method(self._id, value)
|
||||
|
@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Final
|
||||
from typing import Final
|
||||
|
||||
from aioshelly.const import RPC_GENERATIONS
|
||||
|
||||
@ -76,14 +76,12 @@ class RpcText(ShellyRpcAttributeEntity, TextEntity):
|
||||
"""Represent a RPC text entity."""
|
||||
|
||||
entity_description: RpcTextDescription
|
||||
attribute_value: str | None
|
||||
_id: int
|
||||
|
||||
@property
|
||||
def native_value(self) -> str | None:
|
||||
"""Return value of sensor."""
|
||||
if TYPE_CHECKING:
|
||||
assert isinstance(self.attribute_value, str | None)
|
||||
|
||||
return self.attribute_value
|
||||
|
||||
@rpc_call
|
||||
|
Loading…
x
Reference in New Issue
Block a user