|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -from plugwise.constants import GwEntityData |
| 5 | +from plugwise import GwEntityData |
6 | 6 |
|
7 | 7 | from homeassistant.const import ATTR_NAME, ATTR_VIA_DEVICE, CONF_HOST |
8 | 8 | from homeassistant.helpers.device_registry import ( |
@@ -30,37 +30,43 @@ def __init__( |
30 | 30 | super().__init__(coordinator) |
31 | 31 | self._dev_id = device_id |
32 | 32 |
|
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 |
36 | 36 |
|
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 |
38 | 45 | connections = set() |
39 | | - if mac := data.get("mac_address"): |
| 46 | + if mac := self.device.get("mac_address"): |
40 | 47 | 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)) |
43 | 50 |
|
| 51 | + # Set base device info |
44 | 52 | self._attr_device_info = DeviceInfo( |
45 | 53 | configuration_url=configuration_url, |
46 | 54 | identifiers={(DOMAIN, device_id)}, |
47 | 55 | 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"), |
54 | 62 | ) |
55 | 63 |
|
56 | | - if device_id != coordinator.api.gateway_id: |
| 64 | + # Add extra info if not the gateway device |
| 65 | + if device_id != gateway_id: |
57 | 66 | self._attr_device_info.update( |
58 | 67 | { |
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), |
64 | 70 | } |
65 | 71 | ) |
66 | 72 |
|
|
0 commit comments