mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Code quality for Shelly integration (#109061)
This commit is contained in:
parent
b3c1e165db
commit
7359449636
@ -55,7 +55,7 @@ class RestBinarySensorDescription(RestEntityDescription, BinarySensorEntityDescr
|
|||||||
"""Class to describe a REST binary sensor."""
|
"""Class to describe a REST binary sensor."""
|
||||||
|
|
||||||
|
|
||||||
SENSORS: Final = {
|
SENSORS: dict[tuple[str, str], BlockBinarySensorDescription] = {
|
||||||
("device", "overtemp"): BlockBinarySensorDescription(
|
("device", "overtemp"): BlockBinarySensorDescription(
|
||||||
key="device|overtemp",
|
key="device|overtemp",
|
||||||
name="Overheating",
|
name="Overheating",
|
||||||
|
@ -201,12 +201,18 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
if get_info_gen(self.info) in RPC_GENERATIONS:
|
if get_info_gen(self.info) in RPC_GENERATIONS:
|
||||||
schema = {
|
schema = {
|
||||||
vol.Required(CONF_PASSWORD, default=user_input.get(CONF_PASSWORD)): str,
|
vol.Required(
|
||||||
|
CONF_PASSWORD, default=user_input.get(CONF_PASSWORD, "")
|
||||||
|
): str,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
schema = {
|
schema = {
|
||||||
vol.Required(CONF_USERNAME, default=user_input.get(CONF_USERNAME)): str,
|
vol.Required(
|
||||||
vol.Required(CONF_PASSWORD, default=user_input.get(CONF_PASSWORD)): str,
|
CONF_USERNAME, default=user_input.get(CONF_USERNAME, "")
|
||||||
|
): str,
|
||||||
|
vol.Required(
|
||||||
|
CONF_PASSWORD, default=user_input.get(CONF_PASSWORD, "")
|
||||||
|
): str,
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
|
@ -7,10 +7,9 @@ from dataclasses import dataclass
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, Generic, TypeVar, cast
|
from typing import Any, Generic, TypeVar, cast
|
||||||
|
|
||||||
import aioshelly
|
|
||||||
from aioshelly.ble import async_ensure_ble_enabled, async_stop_scanner
|
from aioshelly.ble import async_ensure_ble_enabled, async_stop_scanner
|
||||||
from aioshelly.block_device import BlockDevice, BlockUpdateType
|
from aioshelly.block_device import BlockDevice, BlockUpdateType
|
||||||
from aioshelly.const import MODEL_VALVE
|
from aioshelly.const import MODEL_NAMES, MODEL_VALVE
|
||||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError
|
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError
|
||||||
from aioshelly.rpc_device import RpcDevice, RpcUpdateType
|
from aioshelly.rpc_device import RpcDevice, RpcUpdateType
|
||||||
|
|
||||||
@ -137,7 +136,7 @@ class ShellyCoordinatorBase(DataUpdateCoordinator[None], Generic[_DeviceT]):
|
|||||||
name=self.name,
|
name=self.name,
|
||||||
connections={(CONNECTION_NETWORK_MAC, self.mac)},
|
connections={(CONNECTION_NETWORK_MAC, self.mac)},
|
||||||
manufacturer="Shelly",
|
manufacturer="Shelly",
|
||||||
model=aioshelly.const.MODEL_NAMES.get(self.model, self.model),
|
model=MODEL_NAMES.get(self.model, self.model),
|
||||||
sw_version=self.sw_version,
|
sw_version=self.sw_version,
|
||||||
hw_version=f"gen{get_device_entry_gen(self.entry)} ({self.model})",
|
hw_version=f"gen{get_device_entry_gen(self.entry)} ({self.model})",
|
||||||
configuration_url=f"http://{self.entry.data[CONF_HOST]}",
|
configuration_url=f"http://{self.entry.data[CONF_HOST]}",
|
||||||
|
@ -71,7 +71,7 @@ class BlockShellyCover(ShellyBlockEntity, CoverEntity):
|
|||||||
"""Entity that controls a cover on block based Shelly devices."""
|
"""Entity that controls a cover on block based Shelly devices."""
|
||||||
|
|
||||||
_attr_device_class = CoverDeviceClass.SHUTTER
|
_attr_device_class = CoverDeviceClass.SHUTTER
|
||||||
_attr_supported_features = (
|
_attr_supported_features: CoverEntityFeature = (
|
||||||
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class RpcShellyCover(ShellyRpcEntity, CoverEntity):
|
|||||||
"""Entity that controls a cover on RPC based Shelly devices."""
|
"""Entity that controls a cover on RPC based Shelly devices."""
|
||||||
|
|
||||||
_attr_device_class = CoverDeviceClass.SHUTTER
|
_attr_device_class = CoverDeviceClass.SHUTTER
|
||||||
_attr_supported_features = (
|
_attr_supported_features: CoverEntityFeature = (
|
||||||
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -172,6 +172,7 @@ def async_setup_rpc_attribute_entities(
|
|||||||
coordinator = get_entry_data(hass)[config_entry.entry_id].rpc
|
coordinator = get_entry_data(hass)[config_entry.entry_id].rpc
|
||||||
assert coordinator
|
assert coordinator
|
||||||
|
|
||||||
|
polling_coordinator = None
|
||||||
if not (sleep_period := config_entry.data[CONF_SLEEP_PERIOD]):
|
if not (sleep_period := config_entry.data[CONF_SLEEP_PERIOD]):
|
||||||
polling_coordinator = get_entry_data(hass)[config_entry.entry_id].rpc_poll
|
polling_coordinator = get_entry_data(hass)[config_entry.entry_id].rpc_poll
|
||||||
assert polling_coordinator
|
assert polling_coordinator
|
||||||
|
@ -221,7 +221,7 @@ class BlockShellyLight(ShellyBlockEntity, LightEntity):
|
|||||||
red = self.block.red
|
red = self.block.red
|
||||||
green = self.block.green
|
green = self.block.green
|
||||||
blue = self.block.blue
|
blue = self.block.blue
|
||||||
return (red, green, blue)
|
return (cast(int, red), cast(int, green), cast(int, blue))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rgbw_color(self) -> tuple[int, int, int, int]:
|
def rgbw_color(self) -> tuple[int, int, int, int]:
|
||||||
@ -231,7 +231,7 @@ class BlockShellyLight(ShellyBlockEntity, LightEntity):
|
|||||||
else:
|
else:
|
||||||
white = self.block.white
|
white = self.block.white
|
||||||
|
|
||||||
return (*self.rgb_color, white)
|
return (*self.rgb_color, cast(int, white))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp_kelvin(self) -> int:
|
def color_temp_kelvin(self) -> int:
|
||||||
@ -262,9 +262,9 @@ class BlockShellyLight(ShellyBlockEntity, LightEntity):
|
|||||||
effect_index = self.block.effect
|
effect_index = self.block.effect
|
||||||
|
|
||||||
if self.coordinator.model == MODEL_BULB:
|
if self.coordinator.model == MODEL_BULB:
|
||||||
return SHBLB_1_RGB_EFFECTS[effect_index]
|
return SHBLB_1_RGB_EFFECTS[cast(int, effect_index)]
|
||||||
|
|
||||||
return STANDARD_RGB_EFFECTS[effect_index]
|
return STANDARD_RGB_EFFECTS[cast(int, effect_index)]
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn on light."""
|
"""Turn on light."""
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Final, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from aioshelly.block_device import Block
|
from aioshelly.block_device import Block
|
||||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
||||||
@ -37,7 +37,7 @@ class BlockNumberDescription(BlockEntityDescription, NumberEntityDescription):
|
|||||||
rest_arg: str = ""
|
rest_arg: str = ""
|
||||||
|
|
||||||
|
|
||||||
NUMBERS: Final = {
|
NUMBERS: dict[tuple[str, str], BlockNumberDescription] = {
|
||||||
("device", "valvePos"): BlockNumberDescription(
|
("device", "valvePos"): BlockNumberDescription(
|
||||||
key="device|valvepos",
|
key="device|valvepos",
|
||||||
icon="mdi:pipe-valve",
|
icon="mdi:pipe-valve",
|
||||||
|
@ -69,7 +69,7 @@ class RestSensorDescription(RestEntityDescription, SensorEntityDescription):
|
|||||||
"""Class to describe a REST sensor."""
|
"""Class to describe a REST sensor."""
|
||||||
|
|
||||||
|
|
||||||
SENSORS: Final = {
|
SENSORS: dict[tuple[str, str], BlockSensorDescription] = {
|
||||||
("device", "battery"): BlockSensorDescription(
|
("device", "battery"): BlockSensorDescription(
|
||||||
key="device|battery",
|
key="device|battery",
|
||||||
name="Battery",
|
name="Battery",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user