Ruckus Unleashed Requested Changes (#41824)
This commit is contained in:
1 parent
a2574a4ed5
commit
ffb4a9112b
12 files changed
+351
-79
No files matched your search
@@ -1,18 +1,24 @@
|
||||
"""Support for Ruckus Unleashed devices."""
|
||||
from homeassistant.components.device_tracker import (
|
||||
ATTR_MAC,
|
||||
ATTR_SOURCE_TYPE,
|
||||
SOURCE_TYPE_ROUTER,
|
||||
)
|
||||
from typing import Optional
|
||||
|
||||
from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER
|
||||
from homeassistant.components.device_tracker.config_entry import ScannerEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import entity_registry
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import CLIENTS, COORDINATOR, DOMAIN, UNDO_UPDATE_LISTENERS
|
||||
from .const import (
|
||||
API_ACCESS_POINT,
|
||||
API_CLIENTS,
|
||||
API_NAME,
|
||||
COORDINATOR,
|
||||
DOMAIN,
|
||||
MANUFACTURER,
|
||||
UNDO_UPDATE_LISTENERS,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@@ -43,16 +49,16 @@ def add_new_entities(coordinator, async_add_entities, tracked):
|
||||
"""Add new tracker entities from the router."""
|
||||
new_tracked = []
|
||||
|
||||
for mac in coordinator.data[CLIENTS].keys():
|
||||
for mac in coordinator.data[API_CLIENTS]:
|
||||
if mac in tracked:
|
||||
continue
|
||||
|
||||
device = coordinator.data[CLIENTS][mac]
|
||||
new_tracked.append(RuckusUnleashedDevice(coordinator, mac, device[CONF_NAME]))
|
||||
device = coordinator.data[API_CLIENTS][mac]
|
||||
new_tracked.append(RuckusUnleashedDevice(coordinator, mac, device[API_NAME]))
|
||||
tracked.add(mac)
|
||||
|
||||
if new_tracked:
|
||||
async_add_entities(new_tracked, True)
|
||||
async_add_entities(new_tracked)
|
||||
|
||||
|
||||
@callback
|
||||
@@ -62,7 +68,7 @@ def restore_entities(registry, coordinator, entry, async_add_entities, tracked):
|
||||
|
||||
for entity in registry.entities.values():
|
||||
if entity.config_entry_id == entry.entry_id and entity.platform == DOMAIN:
|
||||
if entity.unique_id not in coordinator.data[CLIENTS]:
|
||||
if entity.unique_id not in coordinator.data[API_CLIENTS]:
|
||||
missing.append(
|
||||
RuckusUnleashedDevice(
|
||||
coordinator, entity.unique_id, entity.original_name
|
||||
@@ -71,7 +77,7 @@ def restore_entities(registry, coordinator, entry, async_add_entities, tracked):
|
||||
tracked.add(entity.unique_id)
|
||||
|
||||
if missing:
|
||||
async_add_entities(missing, True)
|
||||
async_add_entities(missing)
|
||||
|
||||
|
||||
class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity):
|
||||
@@ -93,15 +99,15 @@ class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity):
|
||||
"""Return the name."""
|
||||
if self.is_connected:
|
||||
return (
|
||||
self.coordinator.data[CLIENTS][self._mac][CONF_NAME]
|
||||
or f"Ruckus {self._mac}"
|
||||
self.coordinator.data[API_CLIENTS][self._mac][API_NAME]
|
||||
or f"{MANUFACTURER} {self._mac}"
|
||||
)
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_connected(self) -> bool:
|
||||
"""Return true if the device is connected to the network."""
|
||||
return self._mac in self.coordinator.data[CLIENTS]
|
||||
return self._mac in self.coordinator.data[API_CLIENTS]
|
||||
|
||||
@property
|
||||
def source_type(self) -> str:
|
||||
@@ -109,9 +115,15 @@ class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity):
|
||||
return SOURCE_TYPE_ROUTER
|
||||
|
||||
@property
|
||||
def state_attributes(self) -> dict:
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_SOURCE_TYPE: self.source_type,
|
||||
ATTR_MAC: self._mac,
|
||||
}
|
||||
def device_info(self) -> Optional[dict]:
|
||||
"""Return the device information."""
|
||||
if self.is_connected:
|
||||
return {
|
||||
"name": self.name,
|
||||
"connections": {(CONNECTION_NETWORK_MAC, self._mac)},
|
||||
"via_device": (
|
||||
CONNECTION_NETWORK_MAC,
|
||||
self.coordinator.data[API_CLIENTS][self._mac][API_ACCESS_POINT],
|
||||
),
|
||||
}
|
||||
return None
|
||||
Reference in new issue
Block a user