Don't do http requests to determine Cast device details (#34082)
* Don't do http requests to determine cast device details * Fix tests * Update homeassistant/components/cast/media_player.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
200e140e80
commit
ec2c7ea932
4 changed files with 26 additions and 139 deletions
|
@ -2,7 +2,6 @@
|
|||
from typing import Optional, Tuple
|
||||
|
||||
import attr
|
||||
from pychromecast import dial
|
||||
from pychromecast.const import CAST_MANUFACTURERS
|
||||
|
||||
from .const import DEFAULT_PORT
|
||||
|
@ -29,11 +28,6 @@ class ChromecastInfo:
|
|||
"""Return if this is an audio group."""
|
||||
return self.port != DEFAULT_PORT
|
||||
|
||||
@property
|
||||
def is_information_complete(self) -> bool:
|
||||
"""Return if all information is filled out."""
|
||||
return all(attr.astuple(self))
|
||||
|
||||
@property
|
||||
def host_port(self) -> Tuple[str, int]:
|
||||
"""Return the host+port tuple."""
|
||||
|
@ -46,43 +40,6 @@ class ChromecastInfo:
|
|||
return None
|
||||
return CAST_MANUFACTURERS.get(self.model_name.lower(), "Google Inc.")
|
||||
|
||||
def fill_out_missing_chromecast_info(self) -> "ChromecastInfo":
|
||||
"""Return a new ChromecastInfo object with missing attributes filled in.
|
||||
|
||||
Uses blocking HTTP.
|
||||
"""
|
||||
if self.is_information_complete:
|
||||
# We have all information, no need to check HTTP API. Or this is an
|
||||
# audio group, so checking via HTTP won't give us any new information.
|
||||
return self
|
||||
|
||||
if self.is_audio_group:
|
||||
return ChromecastInfo(
|
||||
service=self.service,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
uuid=self.uuid,
|
||||
friendly_name=self.friendly_name,
|
||||
model_name=self.model_name,
|
||||
)
|
||||
|
||||
# Fill out some missing information (friendly_name, uuid) via HTTP dial.
|
||||
http_device_status = dial.get_device_status(
|
||||
self.host, services=[self.service], zconf=ChromeCastZeroconf.get_zeroconf()
|
||||
)
|
||||
if http_device_status is None:
|
||||
# HTTP dial didn't give us any new information.
|
||||
return self
|
||||
|
||||
return ChromecastInfo(
|
||||
service=self.service,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
uuid=(self.uuid or http_device_status.uuid),
|
||||
friendly_name=(self.friendly_name or http_device_status.friendly_name),
|
||||
model_name=self.model_name,
|
||||
)
|
||||
|
||||
|
||||
class ChromeCastZeroconf:
|
||||
"""Class to hold a zeroconf instance."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue