mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve Shelly light application/consumption type handling (#56461)
This commit is contained in:
parent
5249c89c3f
commit
542f637ac4
@ -51,7 +51,13 @@ from .const import (
|
|||||||
STANDARD_RGB_EFFECTS,
|
STANDARD_RGB_EFFECTS,
|
||||||
)
|
)
|
||||||
from .entity import ShellyBlockEntity, ShellyRpcEntity
|
from .entity import ShellyBlockEntity, ShellyRpcEntity
|
||||||
from .utils import async_remove_shelly_entity, get_device_entry_gen, get_rpc_key_ids
|
from .utils import (
|
||||||
|
async_remove_shelly_entity,
|
||||||
|
get_device_entry_gen,
|
||||||
|
get_rpc_key_ids,
|
||||||
|
is_block_channel_type_light,
|
||||||
|
is_rpc_channel_type_light,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER: Final = logging.getLogger(__name__)
|
_LOGGER: Final = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -82,10 +88,9 @@ async def async_setup_block_entry(
|
|||||||
if block.type == "light":
|
if block.type == "light":
|
||||||
blocks.append(block)
|
blocks.append(block)
|
||||||
elif block.type == "relay":
|
elif block.type == "relay":
|
||||||
app_type = wrapper.device.settings["relays"][int(block.channel)].get(
|
if not is_block_channel_type_light(
|
||||||
"appliance_type"
|
wrapper.device.settings, int(block.channel)
|
||||||
)
|
):
|
||||||
if not app_type or app_type.lower() != "light":
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
blocks.append(block)
|
blocks.append(block)
|
||||||
@ -110,8 +115,7 @@ async def async_setup_rpc_entry(
|
|||||||
|
|
||||||
switch_ids = []
|
switch_ids = []
|
||||||
for id_ in switch_key_ids:
|
for id_ in switch_key_ids:
|
||||||
con_types = wrapper.device.config["sys"]["ui_data"].get("consumption_types")
|
if not is_rpc_channel_type_light(wrapper.device.config, id_):
|
||||||
if con_types is None or con_types[id_] != "lights":
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
switch_ids.append(id_)
|
switch_ids.append(id_)
|
||||||
|
@ -13,7 +13,13 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from . import BlockDeviceWrapper, RpcDeviceWrapper
|
from . import BlockDeviceWrapper, RpcDeviceWrapper
|
||||||
from .const import BLOCK, DATA_CONFIG_ENTRY, DOMAIN, RPC
|
from .const import BLOCK, DATA_CONFIG_ENTRY, DOMAIN, RPC
|
||||||
from .entity import ShellyBlockEntity, ShellyRpcEntity
|
from .entity import ShellyBlockEntity, ShellyRpcEntity
|
||||||
from .utils import async_remove_shelly_entity, get_device_entry_gen, get_rpc_key_ids
|
from .utils import (
|
||||||
|
async_remove_shelly_entity,
|
||||||
|
get_device_entry_gen,
|
||||||
|
get_rpc_key_ids,
|
||||||
|
is_block_channel_type_light,
|
||||||
|
is_rpc_channel_type_light,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -46,13 +52,9 @@ async def async_setup_block_entry(
|
|||||||
relay_blocks = []
|
relay_blocks = []
|
||||||
assert wrapper.device.blocks
|
assert wrapper.device.blocks
|
||||||
for block in wrapper.device.blocks:
|
for block in wrapper.device.blocks:
|
||||||
if block.type != "relay":
|
if block.type != "relay" or is_block_channel_type_light(
|
||||||
continue
|
wrapper.device.settings, int(block.channel)
|
||||||
|
):
|
||||||
app_type = wrapper.device.settings["relays"][int(block.channel)].get(
|
|
||||||
"appliance_type"
|
|
||||||
)
|
|
||||||
if app_type and app_type.lower() == "light":
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
relay_blocks.append(block)
|
relay_blocks.append(block)
|
||||||
@ -76,8 +78,7 @@ async def async_setup_rpc_entry(
|
|||||||
|
|
||||||
switch_ids = []
|
switch_ids = []
|
||||||
for id_ in switch_key_ids:
|
for id_ in switch_key_ids:
|
||||||
con_types = wrapper.device.config["sys"]["ui_data"].get("consumption_types")
|
if is_rpc_channel_type_light(wrapper.device.config, id_):
|
||||||
if con_types is not None and con_types[id_] == "lights":
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
switch_ids.append(id_)
|
switch_ids.append(id_)
|
||||||
|
@ -302,3 +302,15 @@ def get_rpc_key_ids(keys_dict: dict[str, Any], key: str) -> list[int]:
|
|||||||
def is_rpc_momentary_input(config: dict[str, Any], key: str) -> bool:
|
def is_rpc_momentary_input(config: dict[str, Any], key: str) -> bool:
|
||||||
"""Return true if rpc input button settings is set to a momentary type."""
|
"""Return true if rpc input button settings is set to a momentary type."""
|
||||||
return cast(bool, config[key]["type"] == "button")
|
return cast(bool, config[key]["type"] == "button")
|
||||||
|
|
||||||
|
|
||||||
|
def is_block_channel_type_light(settings: dict[str, Any], channel: int) -> bool:
|
||||||
|
"""Return true if block channel appliance type is set to light."""
|
||||||
|
app_type = settings["relays"][channel].get("appliance_type")
|
||||||
|
return app_type is not None and app_type.lower().startswith("light")
|
||||||
|
|
||||||
|
|
||||||
|
def is_rpc_channel_type_light(config: dict[str, Any], channel: int) -> bool:
|
||||||
|
"""Return true if rpc channel consumption type is set to light."""
|
||||||
|
con_types = config["sys"]["ui_data"].get("consumption_types")
|
||||||
|
return con_types is not None and con_types[channel].lower().startswith("light")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user