Skip to content

Commit

Permalink
Remove unused constants and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdelorenzo committed Jun 24, 2021
1 parent 13b6dae commit 1341b3e
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions cast_control/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from mimetypes import guess_type
from functools import lru_cache
import logging

from pychromecast.controllers.receiver import CastStatus
from pychromecast.controllers.media import MediaStatus, \
Expand Down Expand Up @@ -36,8 +37,6 @@
RESOLUTION: Final[int] = 1
MAX_TITLES: Final[int] = 3

TITLE_SEP: Final[str] = ' - '

YOUTUBE_URLS: Final[set[str]] = {
'youtube.com/',
'youtu.be/'
Expand All @@ -55,8 +54,14 @@ class Titles(NamedTuple):
album: Optional[str] = None


class CachedIcon(NamedTuple):
url: str
app_id: str
title: str


class Controllers(NamedTuple):
yt: YouTubeController = None
yt: YouTubeController
spotify: SpotifyController = None
# dash: DashCastController
# bbc_ip: BbcIplayerController
Expand All @@ -76,6 +81,9 @@ class Wrapper(Protocol):
cached_icon: Optional[CachedIcon] = None
light_icon: bool = DEFAULT_ICON

def __getattr__(self, name: str) -> Any:
return getattr(self.dev, name)

@property
def name(self) -> str:
return self.dev.name or NAME
Expand All @@ -102,9 +110,6 @@ def on_new_status(self, *args, **kwargs):


class StatusMixin(Wrapper):
def __getattr__(self, name: str) -> Any:
return getattr(self.dev, name)

@property
def cast_status(self) -> Optional[CastStatus]:
if self.dev.status:
Expand Down Expand Up @@ -145,10 +150,8 @@ def _setup_controllers(self):
)

for ctl in self.ctls:
if not ctl:
continue

self._register(ctl)
if ctl:
self._register(ctl)

def _register(self, controller: BaseController):
self.dev.register_handler(controller)
Expand All @@ -157,10 +160,12 @@ def _launch_youtube(self):
self.ctls.yt.launch()

def _play_youtube(self, video_id: str):
if not self.ctls.yt.is_active:
yt = self.ctls.yt

if not yt.is_active:
self._launch_youtube()

self.ctls.yt.play_video(video_id)
yt.play_video(video_id)

def _is_youtube_vid(self, content_id: str) -> bool:
if not content_id or not self.ctls.yt.is_active:
Expand Down Expand Up @@ -334,12 +339,6 @@ def set_rate(self, val: RateDecimal):
pass


class CachedIcon(NamedTuple):
url: str
app_id: str
title: str


class IconsMixin(Wrapper):
def set_icon(self, lighter: bool = False):
self.light_icon: bool = lighter
Expand Down

0 comments on commit 1341b3e

Please sign in to comment.