Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
3934f7bf
Unverified
Commit
3934f7bf
authored
6 years ago
by
Paulus Schoutsen
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add device info to Chromecast (#16261)
parent
96cf6d59
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/media_player/cast.py
+31
-3
31 additions, 3 deletions
homeassistant/components/media_player/cast.py
tests/components/media_player/test_cast.py
+6
-5
6 additions, 5 deletions
tests/components/media_player/test_cast.py
with
37 additions
and
8 deletions
homeassistant/components/media_player/cast.py
+
31
−
3
View file @
3934f7bf
...
...
@@ -73,7 +73,8 @@ class ChromecastInfo:
port
=
attr
.
ib
(
type
=
int
)
uuid
=
attr
.
ib
(
type
=
Optional
[
str
],
converter
=
attr
.
converters
.
optional
(
str
),
default
=
None
)
# always convert UUID to string if not None
model_name
=
attr
.
ib
(
type
=
str
,
default
=
''
)
# needed for cast type
manufacturer
=
attr
.
ib
(
type
=
str
,
default
=
''
)
model_name
=
attr
.
ib
(
type
=
str
,
default
=
''
)
friendly_name
=
attr
.
ib
(
type
=
Optional
[
str
],
default
=
None
)
@property
...
...
@@ -111,6 +112,7 @@ def _fill_out_missing_chromecast_info(info: ChromecastInfo) -> ChromecastInfo:
host
=
info
.
host
,
port
=
info
.
port
,
uuid
=
(
info
.
uuid
or
http_device_status
.
uuid
),
friendly_name
=
(
info
.
friendly_name
or
http_device_status
.
friendly_name
),
manufacturer
=
(
info
.
manufacturer
or
http_device_status
.
manufacturer
),
model_name
=
(
info
.
model_name
or
http_device_status
.
model_name
)
)
...
...
@@ -148,7 +150,13 @@ def _setup_internal_discovery(hass: HomeAssistantType) -> None:
def
internal_callback
(
name
):
"""
Handle zeroconf discovery of a new chromecast.
"""
mdns
=
listener
.
services
[
name
]
_discover_chromecast
(
hass
,
ChromecastInfo
(
*
mdns
))
_discover_chromecast
(
hass
,
ChromecastInfo
(
host
=
mdns
[
0
],
port
=
mdns
[
1
],
uuid
=
mdns
[
2
],
model_name
=
mdns
[
3
],
friendly_name
=
mdns
[
4
],
))
_LOGGER
.
debug
(
"
Starting internal pychromecast discovery.
"
)
listener
,
browser
=
pychromecast
.
start_discovery
(
internal_callback
)
...
...
@@ -365,7 +373,10 @@ class CastDevice(MediaPlayerDevice):
# pylint: disable=protected-access
_LOGGER
.
debug
(
"
Connecting to cast device %s
"
,
cast_info
)
chromecast
=
await
self
.
hass
.
async_add_job
(
pychromecast
.
_get_chromecast_from_host
,
attr
.
astuple
(
cast_info
))
pychromecast
.
_get_chromecast_from_host
,
(
cast_info
.
host
,
cast_info
.
port
,
cast_info
.
uuid
,
cast_info
.
model_name
,
cast_info
.
friendly_name
))
self
.
_chromecast
=
chromecast
self
.
_status_listener
=
CastStatusListener
(
self
,
chromecast
)
# Initialise connection status as connected because we can only
...
...
@@ -494,6 +505,23 @@ class CastDevice(MediaPlayerDevice):
"""
Return the name of the device.
"""
return
self
.
_cast_info
.
friendly_name
@property
def
device_info
(
self
):
"""
Return information about the device.
"""
cast_info
=
self
.
_cast_info
if
cast_info
.
model_name
==
"
Google Cast Group
"
:
return
None
return
{
'
name
'
:
cast_info
.
friendly_name
,
'
identifiers
'
:
{
(
CAST_DOMAIN
,
cast_info
.
uuid
.
replace
(
'
-
'
,
''
))
},
'
model
'
:
cast_info
.
model_name
,
'
manufacturer
'
:
cast_info
.
manufacturer
,
}
@property
def
state
(
self
):
"""
Return the state of the player.
"""
...
...
This diff is collapsed.
Click to expand it.
tests/components/media_player/test_cast.py
+
6
−
5
View file @
3934f7bf
...
...
@@ -77,7 +77,10 @@ async def async_setup_cast_internal_discovery(hass, config=None,
def
discover_chromecast
(
service_name
:
str
,
info
:
ChromecastInfo
)
->
None
:
"""
Discover a chromecast device.
"""
listener
.
services
[
service_name
]
=
attr
.
astuple
(
info
)
listener
.
services
[
service_name
]
=
(
info
.
host
,
info
.
port
,
info
.
uuid
,
info
.
model_name
,
info
.
friendly_name
)
discovery_callback
(
service_name
)
return
discover_chromecast
,
add_entities
...
...
@@ -152,8 +155,7 @@ async def test_internal_discovery_callback_only_generates_once(hass):
discover_cast
(
'
the-service
'
,
info
)
await
hass
.
async_block_till_done
()
discover
=
signal
.
mock_calls
[
0
][
1
][
0
]
# attr's __eq__ somehow breaks here, use tuples instead
assert
attr
.
astuple
(
discover
)
==
attr
.
astuple
(
info
)
assert
discover
==
info
signal
.
reset_mock
()
# discovering it a second time shouldn't
...
...
@@ -183,8 +185,7 @@ async def test_internal_discovery_callback_fill_out(hass):
# when called with incomplete info, it should use HTTP to get missing
discover
=
signal
.
mock_calls
[
0
][
1
][
0
]
# attr's __eq__ somehow breaks here, use tuples instead
assert
attr
.
astuple
(
discover
)
==
attr
.
astuple
(
full_info
)
assert
discover
==
full_info
async
def
test_create_cast_device_without_uuid
(
hass
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment