Skip to content

Commit

Permalink
Merge pull request #2927 from bramstroker/fix/multi-switch-light-sele…
Browse files Browse the repository at this point in the history
…ction

Allow to select lights in multi_switch entity selection
  • Loading branch information
bramstroker authored Jan 11, 2025
2 parents 16cdc48 + cb622af commit fa92244
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/powercalc/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def create_schema_multi_switch(self) -> vol.Schema:
entities = [
entity.entity_id
for entity in entity_registry.entities.get_entries_for_device_id(self.source_entity.device_entry.id)
if entity.domain == Platform.SWITCH
if entity.domain in (Platform.SWITCH, Platform.LIGHT)
]

# pre-populate the entity selector with the switches from the device
Expand Down
48 changes: 48 additions & 0 deletions tests/config_flow/test_virtual_power_multi_switch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from selectors import SelectSelector
from unittest.mock import AsyncMock

import voluptuous as vol
Expand Down Expand Up @@ -190,6 +191,53 @@ async def test_regression_2612(hass: HomeAssistant, mock_entity_with_model_infor
assert hass.states.get("sensor.foo_bar_energy")


async def test_light_switches_selectable(hass: HomeAssistant) -> None:
"""
Some integrations allow you to change the type of a switch to light.
Make sure that light entities are also selectable in the multi switch setup
"""
hass.config.config_dir = get_test_config_dir()

device_id = "abcdef"
device_entry = DeviceEntry(
id=device_id,
manufacturer="test",
model="multi_switch",
name="Test",
)
mock_device_registry(
hass,
{
device_id: device_entry,
},
)
mock_registry(
hass,
{
"switch.test1": RegistryEntry(
id="switch.test1",
entity_id="switch.test1",
unique_id=f"{device_id}1",
device_id=device_id,
platform="switch",
),
"light.test2": RegistryEntry(
id="light.test2",
entity_id="light.test2",
unique_id=f"{device_id}2",
device_id=device_id,
platform="light",
),
},
)

result = await initialize_device_discovery_flow(hass, device_entry)
data_schema: vol.Schema = result["data_schema"]
entities_select: SelectSelector = data_schema.schema["entities"]
options = entities_select.config["include_entities"]
assert options == ["switch.test1", "light.test2"]


async def initialize_device_discovery_flow(hass: HomeAssistant, device_entry: DeviceEntry) -> FlowResult:
source_entity = SourceEntity(
object_id=device_entry.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Test",
"device_type": "smart_switch",
"discovery_by": "device",
"calculation_strategy": "multi_switch",
"standby_power": 0.5,
"multi_switch_config": {
"power": 0.725
},
"only_self_usage": true
}

0 comments on commit fa92244

Please sign in to comment.