mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Bump pytautulli (#54594)
This commit is contained in:
parent
2eba633382
commit
a892605a90
@ -2,7 +2,7 @@
|
|||||||
"domain": "tautulli",
|
"domain": "tautulli",
|
||||||
"name": "Tautulli",
|
"name": "Tautulli",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/tautulli",
|
"documentation": "https://www.home-assistant.io/integrations/tautulli",
|
||||||
"requirements": ["pytautulli==0.5.0"],
|
"requirements": ["pytautulli==21.8.1"],
|
||||||
"codeowners": ["@ludeeus"],
|
"codeowners": ["@ludeeus"],
|
||||||
"iot_class": "local_polling"
|
"iot_class": "local_polling"
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""A platform which allows you to get information from Tautulli."""
|
"""A platform which allows you to get information from Tautulli."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from pytautulli import Tautulli
|
from pytautulli import PyTautulli
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
@ -60,10 +60,19 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
|
|
||||||
session = async_get_clientsession(hass, verify_ssl)
|
session = async_get_clientsession(hass, verify_ssl)
|
||||||
tautulli = TautulliData(
|
tautulli = TautulliData(
|
||||||
Tautulli(host, port, api_key, hass.loop, session, use_ssl, path)
|
PyTautulli(
|
||||||
|
api_token=api_key,
|
||||||
|
hostname=host,
|
||||||
|
session=session,
|
||||||
|
verify_ssl=verify_ssl,
|
||||||
|
port=port,
|
||||||
|
ssl=use_ssl,
|
||||||
|
base_api_path=path,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not await tautulli.test_connection():
|
await tautulli.async_update()
|
||||||
|
if not tautulli.activity or not tautulli.home_stats or not tautulli.users:
|
||||||
raise PlatformNotReady
|
raise PlatformNotReady
|
||||||
|
|
||||||
sensor = [TautulliSensor(tautulli, name, monitored_conditions, user)]
|
sensor = [TautulliSensor(tautulli, name, monitored_conditions, user)]
|
||||||
@ -88,25 +97,52 @@ class TautulliSensor(SensorEntity):
|
|||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest data from the Tautulli API."""
|
"""Get the latest data from the Tautulli API."""
|
||||||
await self.tautulli.async_update()
|
await self.tautulli.async_update()
|
||||||
self.home = self.tautulli.api.home_data
|
if (
|
||||||
self.sessions = self.tautulli.api.session_data
|
not self.tautulli.activity
|
||||||
self._attributes["Top Movie"] = self.home.get("movie")
|
or not self.tautulli.home_stats
|
||||||
self._attributes["Top TV Show"] = self.home.get("tv")
|
or not self.tautulli.users
|
||||||
self._attributes["Top User"] = self.home.get("user")
|
):
|
||||||
for key in self.sessions:
|
return
|
||||||
if "sessions" not in key:
|
|
||||||
self._attributes[key] = self.sessions[key]
|
self._attributes = {
|
||||||
for user in self.tautulli.api.users:
|
"stream_count": self.tautulli.activity.stream_count,
|
||||||
if self.usernames is None or user in self.usernames:
|
"stream_count_direct_play": self.tautulli.activity.stream_count_direct_play,
|
||||||
userdata = self.tautulli.api.user_data
|
"stream_count_direct_stream": self.tautulli.activity.stream_count_direct_stream,
|
||||||
self._attributes[user] = {}
|
"stream_count_transcode": self.tautulli.activity.stream_count_transcode,
|
||||||
self._attributes[user]["Activity"] = userdata[user]["Activity"]
|
"total_bandwidth": self.tautulli.activity.total_bandwidth,
|
||||||
|
"lan_bandwidth": self.tautulli.activity.lan_bandwidth,
|
||||||
|
"wan_bandwidth": self.tautulli.activity.wan_bandwidth,
|
||||||
|
}
|
||||||
|
|
||||||
|
for stat in self.tautulli.home_stats:
|
||||||
|
if stat.stat_id == "top_movies":
|
||||||
|
self._attributes["Top Movie"] = (
|
||||||
|
stat.rows[0].title if stat.rows else None
|
||||||
|
)
|
||||||
|
elif stat.stat_id == "top_tv":
|
||||||
|
self._attributes["Top TV Show"] = (
|
||||||
|
stat.rows[0].title if stat.rows else None
|
||||||
|
)
|
||||||
|
elif stat.stat_id == "top_users":
|
||||||
|
self._attributes["Top User"] = stat.rows[0].user if stat.rows else None
|
||||||
|
|
||||||
|
for user in self.tautulli.users:
|
||||||
|
if (
|
||||||
|
self.usernames
|
||||||
|
and user.username not in self.usernames
|
||||||
|
or user.username == "Local"
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
self._attributes.setdefault(user.username, {})["Activity"] = None
|
||||||
|
|
||||||
|
for session in self.tautulli.activity.sessions:
|
||||||
|
if not self._attributes.get(session.username):
|
||||||
|
continue
|
||||||
|
|
||||||
|
self._attributes[session.username]["Activity"] = session.state
|
||||||
if self.monitored_conditions:
|
if self.monitored_conditions:
|
||||||
for key in self.monitored_conditions:
|
for key in self.monitored_conditions:
|
||||||
try:
|
self._attributes[session.username][key] = getattr(session, key)
|
||||||
self._attributes[user][key] = userdata[user][key]
|
|
||||||
except (KeyError, TypeError):
|
|
||||||
self._attributes[user][key] = ""
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -116,7 +152,9 @@ class TautulliSensor(SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.sessions.get("stream_count")
|
if not self.tautulli.activity:
|
||||||
|
return 0
|
||||||
|
return self.tautulli.activity.stream_count
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
@ -140,14 +178,13 @@ class TautulliData:
|
|||||||
def __init__(self, api):
|
def __init__(self, api):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self.api = api
|
self.api = api
|
||||||
|
self.activity = None
|
||||||
|
self.home_stats = None
|
||||||
|
self.users = None
|
||||||
|
|
||||||
@Throttle(TIME_BETWEEN_UPDATES)
|
@Throttle(TIME_BETWEEN_UPDATES)
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest data from Tautulli."""
|
"""Get the latest data from Tautulli."""
|
||||||
await self.api.get_data()
|
self.activity = await self.api.async_get_activity()
|
||||||
|
self.home_stats = await self.api.async_get_home_stats()
|
||||||
async def test_connection(self):
|
self.users = await self.api.async_get_users()
|
||||||
"""Test connection to Tautulli."""
|
|
||||||
await self.api.test_connection()
|
|
||||||
connection_status = self.api.connection
|
|
||||||
return connection_status
|
|
||||||
|
@ -1803,7 +1803,7 @@ pysyncthru==0.7.3
|
|||||||
pytankerkoenig==0.0.6
|
pytankerkoenig==0.0.6
|
||||||
|
|
||||||
# homeassistant.components.tautulli
|
# homeassistant.components.tautulli
|
||||||
pytautulli==0.5.0
|
pytautulli==21.8.1
|
||||||
|
|
||||||
# homeassistant.components.tfiac
|
# homeassistant.components.tfiac
|
||||||
pytfiac==0.4
|
pytfiac==0.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user