Skip to content

Commit 60dcca4

Browse files
authored
Show Plugwise configuration-link on gateway only (home-assistant#158094)
1 parent 01f498f commit 60dcca4

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

homeassistant/components/plugwise/entity.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from plugwise.constants import GwEntityData
5+
from plugwise import GwEntityData
66

77
from homeassistant.const import ATTR_NAME, ATTR_VIA_DEVICE, CONF_HOST
88
from homeassistant.helpers.device_registry import (
@@ -30,37 +30,43 @@ def __init__(
3030
super().__init__(coordinator)
3131
self._dev_id = device_id
3232

33-
configuration_url: str | None = None
34-
if entry := self.coordinator.config_entry:
35-
configuration_url = f"http://{entry.data[CONF_HOST]}"
33+
api = coordinator.api
34+
gateway_id = api.gateway_id
35+
entry = coordinator.config_entry
3636

37-
data = coordinator.data[device_id]
37+
# Link configuration-URL for the gateway device
38+
configuration_url = (
39+
f"http://{entry.data[CONF_HOST]}"
40+
if device_id == gateway_id and entry
41+
else None
42+
)
43+
44+
# Build connections set
3845
connections = set()
39-
if mac := data.get("mac_address"):
46+
if mac := self.device.get("mac_address"):
4047
connections.add((CONNECTION_NETWORK_MAC, mac))
41-
if mac := data.get("zigbee_mac_address"):
42-
connections.add((CONNECTION_ZIGBEE, mac))
48+
if zigbee_mac := self.device.get("zigbee_mac_address"):
49+
connections.add((CONNECTION_ZIGBEE, zigbee_mac))
4350

51+
# Set base device info
4452
self._attr_device_info = DeviceInfo(
4553
configuration_url=configuration_url,
4654
identifiers={(DOMAIN, device_id)},
4755
connections=connections,
48-
manufacturer=data.get("vendor"),
49-
model=data.get("model"),
50-
model_id=data.get("model_id"),
51-
name=coordinator.api.smile.name,
52-
sw_version=data.get("firmware"),
53-
hw_version=data.get("hardware"),
56+
manufacturer=self.device.get("vendor"),
57+
model=self.device.get("model"),
58+
model_id=self.device.get("model_id"),
59+
name=api.smile.name,
60+
sw_version=self.device.get("firmware"),
61+
hw_version=self.device.get("hardware"),
5462
)
5563

56-
if device_id != coordinator.api.gateway_id:
64+
# Add extra info if not the gateway device
65+
if device_id != gateway_id:
5766
self._attr_device_info.update(
5867
{
59-
ATTR_NAME: data.get(ATTR_NAME),
60-
ATTR_VIA_DEVICE: (
61-
DOMAIN,
62-
str(self.coordinator.api.gateway_id),
63-
),
68+
ATTR_NAME: self.device.get(ATTR_NAME),
69+
ATTR_VIA_DEVICE: (DOMAIN, gateway_id),
6470
}
6571
)
6672

0 commit comments

Comments
 (0)