Skip to content

Commit

Permalink
UniFi - handle device not having a name (home-assistant#25713)
Browse files Browse the repository at this point in the history
* Handle device not having a name
  • Loading branch information
Kane610 committed Aug 6, 2019
1 parent 5b02555 commit 7ff7c7b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
20 changes: 15 additions & 5 deletions homeassistant/components/unifi/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ def update_items(controller, async_add_entities, tracked):
tracked[client_id] = UniFiClientTracker(client, controller)
new_tracked.append(tracked[client_id])
LOGGER.debug(
"New UniFi client tracker %s (%s)", client.hostname, client.mac
"New UniFi client tracker %s (%s)",
client.name or client.hostname,
client.mac,
)

if not controller.unifi_config.get(CONF_DONT_TRACK_DEVICES, False):
Expand All @@ -208,7 +210,11 @@ def update_items(controller, async_add_entities, tracked):

tracked[device_id] = UniFiDeviceTracker(device, controller)
new_tracked.append(tracked[device_id])
LOGGER.debug("New UniFi device tracker %s (%s)", device.name, device.mac)
LOGGER.debug(
"New UniFi device tracker %s (%s)",
device.name or device.model,
device.mac,
)

if new_tracked:
async_add_entities(new_tracked)
Expand Down Expand Up @@ -311,7 +317,7 @@ def source_type(self):
@property
def name(self) -> str:
"""Return the name of the device."""
return self.device.name
return self.device.name or self.device.model

@property
def unique_id(self) -> str:
Expand All @@ -326,14 +332,18 @@ def available(self) -> bool:
@property
def device_info(self):
"""Return a device description for device registry."""
return {
info = {
"connections": {(CONNECTION_NETWORK_MAC, self.device.mac)},
"manufacturer": ATTR_MANUFACTURER,
"model": self.device.model,
"name": self.device.name,
"sw_version": self.device.version,
}

if self.device.name:
info["name"] = self.device.name

return info

@property
def device_state_attributes(self):
"""Return the device state attributes."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/unifi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/components/unifi",
"requirements": [
"aiounifi==9"
"aiounifi==10"
],
"dependencies": [],
"codeowners": [
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ aiopvapi==1.6.14
aioswitcher==2019.4.26

# homeassistant.components.unifi
aiounifi==9
aiounifi==10

# homeassistant.components.wwlln
aiowwlln==1.0.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ aionotion==1.1.0
aioswitcher==2019.4.26

# homeassistant.components.unifi
aiounifi==9
aiounifi==10

# homeassistant.components.wwlln
aiowwlln==1.0.0
Expand Down

0 comments on commit 7ff7c7b

Please sign in to comment.