Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device registry support for Plex #31797

Merged
merged 3 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add device registry support for Plex
  • Loading branch information
jjlawren committed Feb 13, 2020
commit 68fb33c796b034fad0daffd36ad57211c0f1cd85
18 changes: 18 additions & 0 deletions homeassistant/components/plex/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, plex_server, device, session=None):
self._make = ""
self._device_product = None
self._device_title = None
self._device_version = None
self._name = None
self._player_state = "idle"
self._previous_volume_level = 1 # Used in fake muting
Expand Down Expand Up @@ -195,6 +196,7 @@ def update(self):
self.device.proxyThroughServer()
self._device_product = self.device.product
self._device_title = self.device.title
self._device_version = self.device.version
self._device_protocol_capabilities = self.device.protocolCapabilities
self._player_state = self.device.state

Expand All @@ -214,6 +216,7 @@ def update(self):
self._player_state = session_device.state
self._device_product = self._device_product or session_device.product
self._device_title = self._device_title or session_device.title
self._device_version = self._device_version or session_device.version
else:
_LOGGER.warning("No player associated with active session")

Expand Down Expand Up @@ -715,3 +718,18 @@ def device_state_attributes(self):
}

return attr

@property
def device_info(self):
"""Return a device description for device registry."""
if self.machine_identifier is None:
return None

return {
"identifiers": {(PLEX_DOMAIN, self.machine_identifier)},
"manufacturer": "Plex",
"model": self._device_product or self._device_platform,
"name": self.name,
"sw_version": self._device_version,
"via_device": (PLEX_DOMAIN, self.plex_server.machine_identifier),
}
15 changes: 15 additions & 0 deletions homeassistant/components/plex/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,18 @@ def update(self):
now_playing.append((now_playing_user, now_playing_title))
self._state = len(self.sessions)
self._now_playing = now_playing

@property
def device_info(self):
"""Return a device description for device registry."""
if self.unique_id is None:
return None

return {
"identifiers": {(PLEX_DOMAIN, self.unique_id)},
"manufacturer": "Plex",
"model": "Plex Media Server",
"name": "Activity Sensor",
"sw_version": self._server.version,
"via_device": (PLEX_DOMAIN, self._server.machine_identifier),
}
8 changes: 8 additions & 0 deletions homeassistant/components/plex/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, hass, server_config, options=None):
self.options = options
self.server_choice = None
self._owner_username = None
self._version = None

# Header conditionally added as it is not available in config entry v1
if CONF_CLIENT_IDENTIFIER in server_config:
Expand Down Expand Up @@ -102,6 +103,8 @@ def _connect_with_url():
if owner_account:
self._owner_username = owner_account[0]

self._version = self._plex_server.version

def refresh_entity(self, machine_identifier, device, session):
"""Forward refresh dispatch to media_player."""
unique_id = f"{self.machine_identifier}:{machine_identifier}"
Expand Down Expand Up @@ -196,6 +199,11 @@ def owner(self):
"""Return the Plex server owner username."""
return self._owner_username

@property
def version(self):
"""Return the version of the Plex server."""
return self._version

@property
def friendly_name(self):
"""Return name of connected Plex server."""
Expand Down
5 changes: 5 additions & 0 deletions tests/components/plex/mock_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ def systemAccounts(self):
def url_in_use(self):
"""Return URL used by PlexServer."""
return self._baseurl

@property
def version(self):
"""Mock version of PlexServer."""
return "1.0"