Allow reconnecting wireless omada clients (#128491)

This commit is contained in:
Tristan Bastian 2024-11-15 17:02:31 +01:00 committed by GitHub
parent 23bac67550
commit ab5ddb8edf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 3 deletions

View File

@ -11,9 +11,9 @@ from tplink_omada_client.exceptions import (
UnsupportedControllerVersion, UnsupportedControllerVersion,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
@ -60,6 +60,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: OmadaConfigEntry) -> boo
entry.runtime_data = controller entry.runtime_data = controller
async def handle_reconnect_client(call: ServiceCall) -> None:
"""Handle the service action call."""
mac: str | None = call.data.get("mac")
if not mac:
return
await site_client.reconnect_client(mac)
hass.services.async_register(DOMAIN, "reconnect_client", handle_reconnect_client)
_remove_old_devices(hass, entry, controller.devices_coordinator.data) _remove_old_devices(hass, entry, controller.devices_coordinator.data)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@ -69,7 +79,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: OmadaConfigEntry) -> boo
async def async_unload_entry(hass: HomeAssistant, entry: OmadaConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: OmadaConfigEntry) -> bool:
"""Unload a config entry.""" """Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
loaded_entries = [
entry
for entry in hass.config_entries.async_entries(DOMAIN)
if entry.state == ConfigEntryState.LOADED
]
if len(loaded_entries) == 1:
# This is the last loaded instance of Omada, deregister any services
hass.services.async_remove(DOMAIN, "reconnect_client")
return unload_ok
def _remove_old_devices( def _remove_old_devices(

View File

@ -27,5 +27,10 @@
"default": "mdi:memory" "default": "mdi:memory"
} }
} }
},
"services": {
"reconnect_client": {
"service": "mdi:sync"
}
} }
} }

View File

@ -0,0 +1,7 @@
reconnect_client:
fields:
mac:
required: true
example: "01-23-45-67-89-AB"
selector:
text:

View File

@ -87,5 +87,17 @@
"name": "Memory usage" "name": "Memory usage"
} }
} }
},
"services": {
"reconnect_client": {
"name": "Reconnect wireless client",
"description": "Tries to get wireless client to reconnect to Omada Network.",
"fields": {
"mac": {
"name": "MAC address",
"description": "MAC address of the device."
}
}
}
} }
} }