11"""Support for VELUX KLF 200 devices."""
22
3+ from __future__ import annotations
4+
5+ from dataclasses import dataclass
6+
37from pyvlx import PyVLX , PyVLXException
48
59from homeassistant .config_entries import ConfigEntry
610from homeassistant .const import CONF_HOST , CONF_PASSWORD , EVENT_HOMEASSISTANT_STOP
711from homeassistant .core import HomeAssistant , ServiceCall
12+ from homeassistant .helpers import device_registry as dr
813
914from .const import DOMAIN , LOGGER , PLATFORMS
1015
11- type VeluxConfigEntry = ConfigEntry [PyVLX ]
16+
17+ @dataclass
18+ class VeluxData :
19+ """Runtime data for Velux integration."""
20+
21+ pyvlx : PyVLX
22+ gateway_device_id : tuple [str , str ]
1223
1324
14- async def async_setup_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
25+ type VeluxConfigEntry = ConfigEntry [VeluxData ]
26+
27+
28+ async def async_setup_entry (hass : HomeAssistant , entry : VeluxConfigEntry ) -> bool :
1529 """Set up the velux component."""
1630 host = entry .data [CONF_HOST ]
1731 password = entry .data [CONF_PASSWORD ]
@@ -25,7 +39,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
2539 LOGGER .exception ("Can't connect to velux interface: %s" , ex )
2640 return False
2741
28- entry .runtime_data = pyvlx
42+ device_identifier = (DOMAIN , f"gateway_{ entry .entry_id } " )
43+ entry .runtime_data = VeluxData (pyvlx = pyvlx , gateway_device_id = device_identifier )
44+
45+ device_registry = dr .async_get (hass )
46+ device_registry .async_get_or_create (
47+ config_entry_id = entry .entry_id ,
48+ identifiers = {device_identifier },
49+ name = "KLF 200 Gateway" ,
50+ manufacturer = "Velux" ,
51+ model = "KLF 200" ,
52+ hw_version = str (pyvlx .klf200 .version .hardwareversion )
53+ if pyvlx .klf200 .version
54+ else None ,
55+ sw_version = str (pyvlx .klf200 .version .softwareversion )
56+ if pyvlx .klf200 .version
57+ else None ,
58+ )
2959
3060 async def on_hass_stop (event ):
3161 """Close connection when hass stops."""
@@ -46,6 +76,6 @@ async def async_reboot_gateway(service_call: ServiceCall) -> None:
4676 return True
4777
4878
49- async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
79+ async def async_unload_entry (hass : HomeAssistant , entry : VeluxConfigEntry ) -> bool :
5080 """Unload a config entry."""
5181 return await hass .config_entries .async_unload_platforms (entry , PLATFORMS )
0 commit comments