@@ -42,40 +42,43 @@ def __init__(
4242 super ().__init__ (coordinator )
4343 self ._dev_id = device_id
4444
45- configuration_url : str | None = None
46- if (
47- device_id == coordinator .api .gateway_id
48- and (entry := self .coordinator .config_entry )
49- ):
50- configuration_url = f"http://{ entry .data [CONF_HOST ]} "
51-
52- data = coordinator .data [device_id ]
45+ api = coordinator .api
46+ gateway_id = api .gateway_id
47+ entry = coordinator .config_entry
48+
49+ # Link configuration-URL for the gateway device
50+ configuration_url = (
51+ f"http://{ entry .data [CONF_HOST ]} "
52+ if device_id == gateway_id and entry
53+ else None
54+ )
55+
56+ # Build connections set
5357 connections = set ()
54- if mac := data .get (MAC_ADDRESS ):
58+ if mac := self . device .get (MAC_ADDRESS ):
5559 connections .add ((CONNECTION_NETWORK_MAC , mac ))
56- if mac := data .get (ZIGBEE_MAC_ADDRESS ):
57- connections .add ((CONNECTION_ZIGBEE , mac ))
60+ if zigbee_mac := self . device .get (ZIGBEE_MAC_ADDRESS ):
61+ connections .add ((CONNECTION_ZIGBEE , zigbee_mac ))
5862
63+ # Set base device info
5964 self ._attr_device_info = DeviceInfo (
6065 configuration_url = configuration_url ,
6166 identifiers = {(DOMAIN , device_id )},
6267 connections = connections ,
63- manufacturer = data .get (VENDOR ),
64- model = data .get (MODEL ),
65- model_id = data .get (MODEL_ID ),
66- name = coordinator . api .smile .name ,
67- sw_version = data .get (FIRMWARE ),
68- hw_version = data .get (HARDWARE ),
68+ manufacturer = self . device .get (VENDOR ),
69+ model = self . device .get (MODEL ),
70+ model_id = self . device .get (MODEL_ID ),
71+ name = api .smile .name ,
72+ sw_version = self . device .get (FIRMWARE ),
73+ hw_version = self . device .get (HARDWARE ),
6974 )
7075
71- if device_id != coordinator .api .gateway_id :
76+ # Add extra info if not the gateway device
77+ if device_id != gateway_id :
7278 self ._attr_device_info .update (
7379 {
74- ATTR_NAME : data .get (ATTR_NAME ),
75- ATTR_VIA_DEVICE : (
76- DOMAIN ,
77- str (self .coordinator .api .gateway_id ),
78- ),
80+ ATTR_NAME : self .device .get (ATTR_NAME ),
81+ ATTR_VIA_DEVICE : (DOMAIN , gateway_id ),
7982 }
8083 )
8184
0 commit comments