diff --git a/custom_components/tahoma/__init__.py b/custom_components/tahoma/__init__.py index e4d1eb211..e5c6f58c5 100644 --- a/custom_components/tahoma/__init__.py +++ b/custom_components/tahoma/__init__.py @@ -246,6 +246,36 @@ async def handle_get_execution_history(call): handle_get_execution_history, ) + device_registry = await dr.async_get_registry(hass) + + for gateway in gateways: + _LOGGER.debug( + "Added gateway (%s - %s - %s)", + gateway.id, + gateway.type, + gateway.sub_type, + ) + + gateway_model = ( + beautify_name(gateway.sub_type.name) + if isinstance(gateway.sub_type, Enum) + else None + ) + gateway_name = ( + f"{beautify_name(gateway.type.name)} hub" + if isinstance(gateway.type, Enum) + else None + ) + + device_registry.async_get_or_create( + config_entry_id=entry.entry_id, + identifiers={(DOMAIN, gateway.id)}, + model=gateway_model, + manufacturer="Somfy", + name=gateway_name, + sw_version=gateway.connectivity.protocol_version, + ) + return True @@ -289,6 +319,11 @@ def print_homekit_setup_code(device: Device): _LOGGER.info("HomeKit support detected with setup code %s.", homekit.value) +def beautify_name(name: str): + """Return human readable string.""" + return name.replace("_", " ").title() + + async def write_execution_history_to_log(client: TahomaClient): """Retrieve execution history and write output to log.""" history = await client.get_execution_history()