3 """Utilities for dealing with the webcams."""
10 from decorator_utils import memoized
11 import smart_home.device as dev
13 logger = logging.getLogger(__name__)
16 class BaseChromecast(dev.Device):
17 def __init__(self, name: str, mac: str, keywords: str = "") -> None:
18 super().__init__(name.strip(), mac.strip(), keywords)
20 self.cast = pychromecast.Chromecast(ip)
25 return self.cast.is_idle
32 def get_friendly_name(self):
39 def get_model_name(self):
40 return self.cast.model_name
43 def get_cast_type(self):
44 return self.cast.cast_type
48 return self.cast.app_id
50 def get_app_display_name(self):
51 return self.cast.app_display_name
53 def get_media_controller(self):
54 return self.cast.media_controller
59 app = self.get_app_display_name()
60 mc = self.get_media_controller()
62 return f'{app} / {status.title}'
64 def start_app(self, app_id, force_launch=False):
65 """Start an app on the Chromecast."""
66 self.cast.start_app(app_id, force_launch)
69 """Tells the Chromecast to quit current app_id."""
72 def volume_up(self, delta=0.1):
73 """Increment volume by 0.1 (or delta) unless it is already maxed.
74 Returns the new volume.
76 return self.cast.volume_up(delta)
78 def volume_down(self, delta=0.1):
79 """Decrement the volume by 0.1 (or delta) unless it is already 0.
80 Returns the new volume.
82 return self.cast.volume_down(delta)
86 f"Chromecast({self.cast.socket_client.host!r}, port={self.cast.socket_client.port!r}, "
87 f"device={self.cast.device!r})"