Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions homeassistant/components/overseerr/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
LOGGER = logging.getLogger(__package__)

REQUESTS = "requests"
ISSUES = "issues"

ATTR_STATUS = "status"
ATTR_SORT_ORDER = "sort_order"
ATTR_REQUESTED_BY = "requested_by"
ATTR_ISSUE_TYPE = "issue_type"
ATTR_ISSUE_STATUS = "issue_status"
ATTR_MESSAGE = "message"
ATTR_MEDIA_ID = "media_id"
ATTR_ISSUE_ID = "issue_id"
ATTR_PROBLEM_SEASON = "problem_season"
ATTR_PROBLEM_EPISODE = "problem_episode"

EVENT_KEY = f"{DOMAIN}_event"

Expand All @@ -22,6 +30,10 @@
| NotificationType.REQUEST_AVAILABLE
| NotificationType.REQUEST_PROCESSING_FAILED
| NotificationType.REQUEST_AUTOMATICALLY_APPROVED
| NotificationType.ISSUE_REPORTED
| NotificationType.ISSUE_COMMENTED
| NotificationType.ISSUE_RESOLVED
| NotificationType.ISSUE_REOPENED
)
JSON_PAYLOAD = (
'"{\\"notification_type\\":\\"{{notification_type}}\\",\\"subject\\":\\"{{subject}'
Expand Down
10 changes: 6 additions & 4 deletions homeassistant/components/overseerr/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
OverseerrAuthenticationError,
OverseerrClient,
OverseerrConnectionError,
RequestCount,
)
from yarl import URL

Expand All @@ -18,11 +17,12 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import DOMAIN, LOGGER
from .models import OverseerrData

type OverseerrConfigEntry = ConfigEntry[OverseerrCoordinator]


class OverseerrCoordinator(DataUpdateCoordinator[RequestCount]):
class OverseerrCoordinator(DataUpdateCoordinator[OverseerrData]):
"""Class to manage fetching Overseerr data."""

config_entry: OverseerrConfigEntry
Expand All @@ -49,10 +49,12 @@ def __init__(self, hass: HomeAssistant, entry: OverseerrConfigEntry) -> None:
self.url = URL.build(host=host, port=port, scheme="https" if ssl else "http")
self.push = False

async def _async_update_data(self) -> RequestCount:
async def _async_update_data(self) -> OverseerrData:
"""Fetch data from API endpoint."""
try:
return await self.client.get_request_count()
requests = await self.client.get_request_count()
issues = await self.client.get_issue_count()
return OverseerrData(requests=requests, issues=issues)
except OverseerrAuthenticationError as err:
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
Expand Down
13 changes: 13 additions & 0 deletions homeassistant/components/overseerr/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Data models for Overseerr integration."""

from dataclasses import dataclass

from python_overseerr import IssueCount, RequestCount


@dataclass
class OverseerrData:
"""Data model for Overseerr coordinator."""

requests: RequestCount
issues: IssueCount
57 changes: 46 additions & 11 deletions homeassistant/components/overseerr/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from collections.abc import Callable
from dataclasses import dataclass

from python_overseerr import RequestCount

from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
Expand All @@ -13,9 +11,10 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .const import REQUESTS
from .const import ISSUES, REQUESTS
from .coordinator import OverseerrConfigEntry, OverseerrCoordinator
from .entity import OverseerrEntity
from .models import OverseerrData

PARALLEL_UPDATES = 0

Expand All @@ -24,51 +23,87 @@
class OverseerrSensorEntityDescription(SensorEntityDescription):
"""Describes Overseerr config sensor entity."""

value_fn: Callable[[RequestCount], int]
value_fn: Callable[[OverseerrData], int]


SENSORS: tuple[OverseerrSensorEntityDescription, ...] = (
OverseerrSensorEntityDescription(
key="total_requests",
native_unit_of_measurement=REQUESTS,
state_class=SensorStateClass.TOTAL,
value_fn=lambda count: count.total,
value_fn=lambda data: data.requests.total,
),
OverseerrSensorEntityDescription(
key="movie_requests",
native_unit_of_measurement=REQUESTS,
state_class=SensorStateClass.TOTAL,
value_fn=lambda count: count.movie,
value_fn=lambda data: data.requests.movie,
),
OverseerrSensorEntityDescription(
key="tv_requests",
native_unit_of_measurement=REQUESTS,
state_class=SensorStateClass.TOTAL,
value_fn=lambda count: count.tv,
value_fn=lambda data: data.requests.tv,
),
OverseerrSensorEntityDescription(
key="pending_requests",
native_unit_of_measurement=REQUESTS,
state_class=SensorStateClass.TOTAL,
value_fn=lambda count: count.pending,
value_fn=lambda data: data.requests.pending,
),
OverseerrSensorEntityDescription(
key="declined_requests",
native_unit_of_measurement=REQUESTS,
state_class=SensorStateClass.TOTAL,
value_fn=lambda count: count.declined,
value_fn=lambda data: data.requests.declined,
),
OverseerrSensorEntityDescription(
key="processing_requests",
native_unit_of_measurement=REQUESTS,
state_class=SensorStateClass.TOTAL,
value_fn=lambda count: count.processing,
value_fn=lambda data: data.requests.processing,
),
OverseerrSensorEntityDescription(
key="available_requests",
native_unit_of_measurement=REQUESTS,
state_class=SensorStateClass.TOTAL,
value_fn=lambda count: count.available,
value_fn=lambda data: data.requests.available,
),
OverseerrSensorEntityDescription(
key="total_issues",
native_unit_of_measurement=ISSUES,
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: data.issues.total,
),
OverseerrSensorEntityDescription(
key="open_issues",
native_unit_of_measurement=ISSUES,
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: data.issues.open,
),
OverseerrSensorEntityDescription(
key="closed_issues",
native_unit_of_measurement=ISSUES,
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: data.issues.closed,
),
OverseerrSensorEntityDescription(
key="video_issues",
native_unit_of_measurement=ISSUES,
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: data.issues.video,
),
OverseerrSensorEntityDescription(
key="audio_issues",
native_unit_of_measurement=ISSUES,
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: data.issues.audio,
),
OverseerrSensorEntityDescription(
key="subtitle_issues",
native_unit_of_measurement=ISSUES,
state_class=SensorStateClass.TOTAL,
value_fn=lambda data: data.issues.subtitles,
),
)

Expand Down
Loading