Use class attrs and shorthand attrs for Shelly (#101249)

pull/101262/head
Maciej Bieniek 2023-10-02 11:40:06 +00:00 committed by GitHub
parent 85e782055b
commit 0fdf04391b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 25 deletions

View File

@ -148,6 +148,7 @@ class BlockSleepingClimate(
self.last_state_attributes: Mapping[str, Any]
self._preset_modes: list[str] = []
self._last_target_temp = SHTRV_01_TEMPERATURE_SETTINGS["default"]
self._attr_name = coordinator.name
if self.block is not None and self.device_block is not None:
self._unique_id = f"{self.coordinator.mac}-{self.block.description}"
@ -160,6 +161,9 @@ class BlockSleepingClimate(
]
elif entry is not None:
self._unique_id = entry.unique_id
self._attr_device_info = DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, coordinator.mac)},
)
self._channel = cast(int, self._unique_id.split("_")[1])
@ -173,11 +177,6 @@ class BlockSleepingClimate(
"""Set unique id of entity."""
return self._unique_id
@property
def name(self) -> str:
"""Name of entity."""
return self.coordinator.name
@property
def target_temperature(self) -> float | None:
"""Set target temperature."""
@ -256,13 +255,6 @@ class BlockSleepingClimate(
"""Preset available modes."""
return self._preset_modes
@property
def device_info(self) -> DeviceInfo:
"""Device info."""
return DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, self.coordinator.mac)},
)
def _check_is_off(self) -> bool:
"""Return if valve is off or on."""
return bool(
@ -354,7 +346,7 @@ class BlockSleepingClimate(
severity=ir.IssueSeverity.ERROR,
translation_key="device_not_calibrated",
translation_placeholders={
"device_name": self.name,
"device_name": self.coordinator.name,
"ip_address": self.coordinator.device.ip_address,
},
)

View File

@ -70,14 +70,14 @@ class BlockShellyCover(ShellyBlockEntity, CoverEntity):
"""Entity that controls a cover on block based Shelly devices."""
_attr_device_class = CoverDeviceClass.SHUTTER
_attr_supported_features = (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
)
def __init__(self, coordinator: ShellyBlockCoordinator, block: Block) -> None:
"""Initialize block cover."""
super().__init__(coordinator, block)
self.control_result: dict[str, Any] | None = None
self._attr_supported_features = (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
)
if self.coordinator.device.settings["rollers"][0]["positioning"]:
self._attr_supported_features |= CoverEntityFeature.SET_POSITION
@ -146,14 +146,14 @@ class RpcShellyCover(ShellyRpcEntity, CoverEntity):
"""Entity that controls a cover on RPC based Shelly devices."""
_attr_device_class = CoverDeviceClass.SHUTTER
_attr_supported_features = (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
)
def __init__(self, coordinator: ShellyRpcCoordinator, id_: int) -> None:
"""Initialize rpc cover."""
super().__init__(coordinator, f"cover:{id_}")
self._id = id_
self._attr_supported_features = (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
)
if self.status["pos_control"]:
self._attr_supported_features |= CoverEntityFeature.SET_POSITION

View File

@ -326,7 +326,6 @@ class ShellyBlockEntity(CoordinatorEntity[ShellyBlockCoordinator]):
super().__init__(coordinator)
self.block = block
self._attr_name = get_block_entity_name(coordinator.device, block)
self._attr_should_poll = False
self._attr_device_info = DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, coordinator.mac)}
)
@ -364,7 +363,6 @@ class ShellyRpcEntity(CoordinatorEntity[ShellyRpcCoordinator]):
"""Initialize Shelly entity."""
super().__init__(coordinator)
self.key = key
self._attr_should_poll = False
self._attr_device_info = {
"connections": {(CONNECTION_NETWORK_MAC, coordinator.mac)}
}
@ -571,7 +569,6 @@ class ShellySleepingBlockAttributeEntity(ShellyBlockAttributeEntity):
self.block: Block | None = block # type: ignore[assignment]
self.entity_description = description
self._attr_should_poll = False
self._attr_device_info = DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, coordinator.mac)}
)
@ -643,7 +640,6 @@ class ShellySleepingRpcAttributeEntity(ShellyRpcAttributeEntity):
self.attribute = attribute
self.entity_description = description
self._attr_should_poll = False
self._attr_device_info = DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, coordinator.mac)}
)

View File

@ -122,7 +122,6 @@ async def async_setup_entry(
class ShellyBlockEvent(ShellyBlockEntity, EventEntity):
"""Represent Block event entity."""
_attr_should_poll = False
entity_description: ShellyBlockEventDescription
def __init__(
@ -160,7 +159,6 @@ class ShellyBlockEvent(ShellyBlockEntity, EventEntity):
class ShellyRpcEvent(CoordinatorEntity[ShellyRpcCoordinator], EventEntity):
"""Represent RPC event entity."""
_attr_should_poll = False
entity_description: ShellyRpcEventDescription
def __init__(