Lookup manufacturer name for casts (#33845)
* Lookup manufacturer name, remove use of get_multizone_status * Bump pychromecast * Bump pychromecast * Fix testpull/33891/head
parent
87e7e7fe8a
commit
3845539577
|
@ -3,6 +3,7 @@ from typing import Optional, Tuple
|
|||
|
||||
import attr
|
||||
from pychromecast import dial
|
||||
from pychromecast.const import CAST_MANUFACTURERS
|
||||
|
||||
from .const import DEFAULT_PORT
|
||||
|
||||
|
@ -20,7 +21,6 @@ class ChromecastInfo:
|
|||
uuid = attr.ib(
|
||||
type=Optional[str], converter=attr.converters.optional(str), default=None
|
||||
) # always convert UUID to string if not None
|
||||
manufacturer = attr.ib(type=str, default="")
|
||||
model_name = attr.ib(type=str, default="")
|
||||
friendly_name = attr.ib(type=Optional[str], default=None)
|
||||
is_dynamic_group = attr.ib(type=Optional[bool], default=None)
|
||||
|
@ -52,6 +52,13 @@ class ChromecastInfo:
|
|||
"""Return the host+port tuple."""
|
||||
return self.host, self.port
|
||||
|
||||
@property
|
||||
def manufacturer(self) -> str:
|
||||
"""Return the manufacturer."""
|
||||
if not self.model_name:
|
||||
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.
|
||||
|
||||
|
@ -62,22 +69,8 @@ class ChromecastInfo:
|
|||
# audio group, so checking via HTTP won't give us any new information.
|
||||
return self
|
||||
|
||||
# Fill out missing information via HTTP dial.
|
||||
if self.is_audio_group:
|
||||
is_dynamic_group = False
|
||||
http_group_status = None
|
||||
dynamic_groups = []
|
||||
if self.uuid:
|
||||
http_group_status = dial.get_multizone_status(
|
||||
self.host,
|
||||
services=[self.service],
|
||||
zconf=ChromeCastZeroconf.get_zeroconf(),
|
||||
)
|
||||
if http_group_status is not None:
|
||||
dynamic_groups = [
|
||||
str(g.uuid) for g in http_group_status.dynamic_groups
|
||||
]
|
||||
is_dynamic_group = self.uuid in dynamic_groups
|
||||
|
||||
return ChromecastInfo(
|
||||
service=self.service,
|
||||
|
@ -85,11 +78,11 @@ class ChromecastInfo:
|
|||
port=self.port,
|
||||
uuid=self.uuid,
|
||||
friendly_name=self.friendly_name,
|
||||
manufacturer=self.manufacturer,
|
||||
model_name=self.model_name,
|
||||
is_dynamic_group=is_dynamic_group,
|
||||
)
|
||||
|
||||
# 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()
|
||||
)
|
||||
|
@ -103,8 +96,7 @@ class ChromecastInfo:
|
|||
port=self.port,
|
||||
uuid=(self.uuid or http_device_status.uuid),
|
||||
friendly_name=(self.friendly_name or http_device_status.friendly_name),
|
||||
manufacturer=(self.manufacturer or http_device_status.manufacturer),
|
||||
model_name=(self.model_name or http_device_status.model_name),
|
||||
model_name=self.model_name,
|
||||
)
|
||||
|
||||
def same_dynamic_group(self, other: "ChromecastInfo") -> bool:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Google Cast",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/cast",
|
||||
"requirements": ["pychromecast==4.2.0"],
|
||||
"requirements": ["pychromecast==4.2.3"],
|
||||
"after_dependencies": ["cloud"],
|
||||
"zeroconf": ["_googlecast._tcp.local."],
|
||||
"codeowners": ["@emontnemery"]
|
||||
|
|
|
@ -1205,7 +1205,7 @@ pycfdns==0.0.1
|
|||
pychannels==1.0.0
|
||||
|
||||
# homeassistant.components.cast
|
||||
pychromecast==4.2.0
|
||||
pychromecast==4.2.3
|
||||
|
||||
# homeassistant.components.cmus
|
||||
pycmus==0.1.1
|
||||
|
|
|
@ -475,7 +475,7 @@ pyblackbird==0.5
|
|||
pybotvac==0.0.17
|
||||
|
||||
# homeassistant.components.cast
|
||||
pychromecast==4.2.0
|
||||
pychromecast==4.2.3
|
||||
|
||||
# homeassistant.components.coolmaster
|
||||
pycoolmasternet==0.0.4
|
||||
|
|
|
@ -182,9 +182,7 @@ async def test_internal_discovery_callback_fill_out(hass):
|
|||
|
||||
discover_cast, _ = await async_setup_cast_internal_discovery(hass)
|
||||
info = get_fake_chromecast_info(uuid=None)
|
||||
full_info = attr.evolve(
|
||||
info, model_name="google home", friendly_name="Speaker", uuid=FakeUUID
|
||||
)
|
||||
full_info = attr.evolve(info, model_name="", friendly_name="Speaker", uuid=FakeUUID)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.cast.helpers.dial.get_device_status",
|
||||
|
|
Loading…
Reference in New Issue