mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Adapt wmspro to set via_device_id in DeviceInfo (#177852)
This commit is contained in:
@@ -24,10 +24,12 @@ async def async_setup_entry(
|
||||
entities: list[WebControlProGenericEntity] = []
|
||||
for dest in hub.dests.values():
|
||||
if dest.hasAction(ACTION_DESC.Identify):
|
||||
entities.append(WebControlProIdentifyButton(config_entry.entry_id, dest))
|
||||
entities.append(
|
||||
WebControlProIdentifyButton(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
if dest.hasAction(ACTION_DESC.SlatRotate):
|
||||
entities.append(
|
||||
WebControlProRotationResetButton(config_entry.entry_id, dest)
|
||||
WebControlProRotationResetButton(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
@@ -40,16 +40,20 @@ async def async_setup_entry(
|
||||
entities: list[WebControlProGenericEntity] = []
|
||||
for dest in hub.dests.values():
|
||||
if dest.hasAction(ACTION_DESC.AwningDrive):
|
||||
entities.append(WebControlProAwning(config_entry.entry_id, dest))
|
||||
entities.append(WebControlProAwning(hass, config_entry.entry_id, dest))
|
||||
if dest.hasAction(ACTION_DESC.ValanceDrive):
|
||||
entities.append(WebControlProValance(config_entry.entry_id, dest))
|
||||
entities.append(WebControlProValance(hass, config_entry.entry_id, dest))
|
||||
elif dest.hasAction(ACTION_DESC.RollerShutterBlindDrive):
|
||||
entities.append(WebControlProRollerShutter(config_entry.entry_id, dest))
|
||||
entities.append(
|
||||
WebControlProRollerShutter(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
elif dest.hasAction(ACTION_DESC.SlatDrive):
|
||||
if dest.hasAction(ACTION_DESC.SlatRotate):
|
||||
entities.append(WebControlProSlatRotate(config_entry.entry_id, dest))
|
||||
entities.append(
|
||||
WebControlProSlatRotate(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
else:
|
||||
entities.append(WebControlProSlat(config_entry.entry_id, dest))
|
||||
entities.append(WebControlProSlat(hass, config_entry.entry_id, dest))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ from typing import override
|
||||
|
||||
from wmspro.destination import Destination
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
@@ -16,7 +18,9 @@ class WebControlProGenericEntity(Entity):
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, config_entry_id: str, dest: Destination) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry_id: str, dest: Destination
|
||||
) -> None:
|
||||
"""Initialize the entity with destination channel."""
|
||||
dest_id_str = str(dest.id)
|
||||
self._dest = dest
|
||||
@@ -30,7 +34,9 @@ class WebControlProGenericEntity(Entity):
|
||||
name=dest.name,
|
||||
serial_number=dest_id_str,
|
||||
suggested_area=dest.room.name,
|
||||
via_device=(DOMAIN, config_entry_id),
|
||||
via_device_id=dr.async_get_device_id_by_identifier(
|
||||
hass, (DOMAIN, config_entry_id), config_entry_id=config_entry_id
|
||||
),
|
||||
configuration_url=f"http://{dest.host}/control",
|
||||
)
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ async def async_setup_entry(
|
||||
entities: list[WebControlProGenericEntity] = []
|
||||
for dest in hub.dests.values():
|
||||
if dest.hasAction(ACTION_DESC.LightDimming):
|
||||
entities.append(WebControlProDimmer(config_entry.entry_id, dest))
|
||||
entities.append(WebControlProDimmer(hass, config_entry.entry_id, dest))
|
||||
elif dest.hasAction(ACTION_DESC.LightSwitch):
|
||||
entities.append(WebControlProLight(config_entry.entry_id, dest))
|
||||
entities.append(WebControlProLight(hass, config_entry.entry_id, dest))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
@@ -29,12 +29,20 @@ async def async_setup_entry(
|
||||
entities: list[WebControlProGenericEntity] = []
|
||||
for dest in hub.dests.values():
|
||||
if dest.hasAction(ACTION_DESC.SlatRotate):
|
||||
entities.append(WebControlProSlatRangeMin(config_entry.entry_id, dest))
|
||||
entities.append(WebControlProSlatRangeMax(config_entry.entry_id, dest))
|
||||
entities.append(WebControlProSlatRotationRaw(config_entry.entry_id, dest))
|
||||
entities.append(
|
||||
WebControlProSlatRangeMin(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
entities.append(
|
||||
WebControlProSlatRangeMax(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
entities.append(
|
||||
WebControlProSlatRotationRaw(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
if not dest.hasAction(ACTION_DESC.SlatDrive):
|
||||
# Only add the numeric slat rotation entity if no cover entity exists
|
||||
entities.append(WebControlProSlatRotation(config_entry.entry_id, dest))
|
||||
entities.append(
|
||||
WebControlProSlatRotation(hass, config_entry.entry_id, dest)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from wmspro.scene import Scene as WMS_Scene
|
||||
|
||||
from homeassistant.components.scene import Scene
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
@@ -22,7 +23,7 @@ async def async_setup_entry(
|
||||
hub = config_entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
WebControlProScene(config_entry.entry_id, scene)
|
||||
WebControlProScene(hass, config_entry.entry_id, scene)
|
||||
for scene in hub.scenes.values()
|
||||
)
|
||||
|
||||
@@ -33,7 +34,9 @@ class WebControlProScene(Scene):
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, config_entry_id: str, scene: WMS_Scene) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry_id: str, scene: WMS_Scene
|
||||
) -> None:
|
||||
"""Initialize the entity with the configured scene."""
|
||||
super().__init__()
|
||||
|
||||
@@ -53,7 +56,9 @@ class WebControlProScene(Scene):
|
||||
name=room_name,
|
||||
serial_number=room_id_str,
|
||||
suggested_area=room_name,
|
||||
via_device=(DOMAIN, config_entry_id),
|
||||
via_device_id=dr.async_get_device_id_by_identifier(
|
||||
hass, (DOMAIN, config_entry_id), config_entry_id=config_entry_id
|
||||
),
|
||||
configuration_url=f"http://{scene.host}/control",
|
||||
)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ async def async_setup_entry(
|
||||
hub = config_entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
WebControlProSwitch(config_entry.entry_id, dest)
|
||||
WebControlProSwitch(hass, config_entry.entry_id, dest)
|
||||
for dest in hub.dests.values()
|
||||
if dest.hasAction(ACTION_DESC.LoadSwitch)
|
||||
)
|
||||
|
||||
@@ -96,6 +96,11 @@ async def test_device_setup(
|
||||
)
|
||||
assert len(device_entries) > len(mock_hub_configuration.destinations)
|
||||
|
||||
hub_device_entry = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, mock_config_entry.entry_id), mock_config_entry.entry_id
|
||||
)
|
||||
assert hub_device_entry is not None
|
||||
|
||||
device_entries = list(
|
||||
filter(
|
||||
lambda e: e.identifiers != {(DOMAIN, mock_config_entry.entry_id)},
|
||||
@@ -104,4 +109,5 @@ async def test_device_setup(
|
||||
)
|
||||
assert len(device_entries) >= len(mock_hub_configuration.destinations)
|
||||
for device_entry in device_entries:
|
||||
assert device_entry.via_device_id == hub_device_entry.id
|
||||
assert device_entry == snapshot(name=f"device-{device_entry.serial_number}")
|
||||
|
||||
Reference in New Issue
Block a user