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
03968b44
Unverified
Commit
03968b44
authored
7 months ago
by
Joost Lekkerkerker
Committed by
GitHub
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve typing in Yamaha (#123982)
Co-authored-by:
Franck Nijhof
<
frenck@frenck.nl
>
parent
686d591f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/yamaha/media_player.py
+22
-12
22 additions, 12 deletions
homeassistant/components/yamaha/media_player.py
with
22 additions
and
12 deletions
homeassistant/components/yamaha/media_player.py
+
22
−
12
View file @
03968b44
...
@@ -7,6 +7,7 @@ from typing import Any
...
@@ -7,6 +7,7 @@ from typing import Any
import
requests
import
requests
import
rxv
import
rxv
from
rxv
import
RXV
import
voluptuous
as
vol
import
voluptuous
as
vol
from
homeassistant.components.media_player
import
(
from
homeassistant.components.media_player
import
(
...
@@ -112,7 +113,7 @@ class YamahaConfigInfo:
...
@@ -112,7 +113,7 @@ class YamahaConfigInfo:
self
.
from_discovery
=
True
self
.
from_discovery
=
True
def
_discovery
(
config_info
)
:
def
_discovery
(
config_info
:
YamahaConfigInfo
)
->
list
[
RXV
]
:
"""
Discover list of zone controllers from configuration in the network.
"""
"""
Discover list of zone controllers from configuration in the network.
"""
if
config_info
.
from_discovery
:
if
config_info
.
from_discovery
:
_LOGGER
.
debug
(
"
Discovery Zones
"
)
_LOGGER
.
debug
(
"
Discovery Zones
"
)
...
@@ -163,6 +164,7 @@ async def async_setup_platform(
...
@@ -163,6 +164,7 @@ async def async_setup_platform(
_LOGGER
.
debug
(
"
Ignore receiver zone: %s %s
"
,
config_info
.
name
,
zctrl
.
zone
)
_LOGGER
.
debug
(
"
Ignore receiver zone: %s %s
"
,
config_info
.
name
,
zctrl
.
zone
)
continue
continue
assert
config_info
.
name
entity
=
YamahaDeviceZone
(
entity
=
YamahaDeviceZone
(
config_info
.
name
,
config_info
.
name
,
zctrl
,
zctrl
,
...
@@ -206,16 +208,24 @@ async def async_setup_platform(
...
@@ -206,16 +208,24 @@ async def async_setup_platform(
class
YamahaDeviceZone
(
MediaPlayerEntity
):
class
YamahaDeviceZone
(
MediaPlayerEntity
):
"""
Representation of a Yamaha device zone.
"""
"""
Representation of a Yamaha device zone.
"""
def
__init__
(
self
,
name
,
zctrl
,
source_ignore
,
source_names
,
zone_names
):
_reverse_mapping
:
dict
[
str
,
str
]
def
__init__
(
self
,
name
:
str
,
zctrl
:
RXV
,
source_ignore
:
list
[
str
]
|
None
,
source_names
:
dict
[
str
,
str
]
|
None
,
zone_names
:
dict
[
str
,
str
]
|
None
,
)
->
None
:
"""
Initialize the Yamaha Receiver.
"""
"""
Initialize the Yamaha Receiver.
"""
self
.
zctrl
=
zctrl
self
.
zctrl
=
zctrl
self
.
_attr_is_volume_muted
=
False
self
.
_attr_is_volume_muted
=
False
self
.
_attr_volume_level
=
0
self
.
_attr_volume_level
=
0
self
.
_attr_state
=
MediaPlayerState
.
OFF
self
.
_attr_state
=
MediaPlayerState
.
OFF
self
.
_source_ignore
=
source_ignore
or
[]
self
.
_source_ignore
:
list
[
str
]
=
source_ignore
or
[]
self
.
_source_names
=
source_names
or
{}
self
.
_source_names
:
dict
[
str
,
str
]
=
source_names
or
{}
self
.
_zone_names
=
zone_names
or
{}
self
.
_zone_names
:
dict
[
str
,
str
]
=
zone_names
or
{}
self
.
_reverse_mapping
=
None
self
.
_playback_support
=
None
self
.
_playback_support
=
None
self
.
_is_playback_supported
=
False
self
.
_is_playback_supported
=
False
self
.
_play_status
=
None
self
.
_play_status
=
None
...
@@ -267,7 +277,7 @@ class YamahaDeviceZone(MediaPlayerEntity):
...
@@ -267,7 +277,7 @@ class YamahaDeviceZone(MediaPlayerEntity):
self
.
_attr_sound_mode
=
None
self
.
_attr_sound_mode
=
None
self
.
_attr_sound_mode_list
=
None
self
.
_attr_sound_mode_list
=
None
def
build_source_list
(
self
):
def
build_source_list
(
self
)
->
None
:
"""
Build the source list.
"""
"""
Build the source list.
"""
self
.
_reverse_mapping
=
{
self
.
_reverse_mapping
=
{
alias
:
source
for
source
,
alias
in
self
.
_source_names
.
items
()
alias
:
source
for
source
,
alias
in
self
.
_source_names
.
items
()
...
@@ -280,7 +290,7 @@ class YamahaDeviceZone(MediaPlayerEntity):
...
@@ -280,7 +290,7 @@ class YamahaDeviceZone(MediaPlayerEntity):
)
)
@property
@property
def
name
(
self
):
def
name
(
self
)
->
str
:
"""
Return the name of the device.
"""
"""
Return the name of the device.
"""
name
=
self
.
_name
name
=
self
.
_name
zone_name
=
self
.
_zone_names
.
get
(
self
.
_zone
,
self
.
_zone
)
zone_name
=
self
.
_zone_names
.
get
(
self
.
_zone
,
self
.
_zone
)
...
@@ -290,7 +300,7 @@ class YamahaDeviceZone(MediaPlayerEntity):
...
@@ -290,7 +300,7 @@ class YamahaDeviceZone(MediaPlayerEntity):
return
name
return
name
@property
@property
def
zone_id
(
self
):
def
zone_id
(
self
)
->
str
:
"""
Return a zone_id to ensure 1 media player per zone.
"""
"""
Return a zone_id to ensure 1 media player per zone.
"""
return
f
"
{
self
.
zctrl
.
ctrl_url
}
:
{
self
.
_zone
}
"
return
f
"
{
self
.
zctrl
.
ctrl_url
}
:
{
self
.
_zone
}
"
...
@@ -387,15 +397,15 @@ class YamahaDeviceZone(MediaPlayerEntity):
...
@@ -387,15 +397,15 @@ class YamahaDeviceZone(MediaPlayerEntity):
if
media_type
==
"
NET RADIO
"
:
if
media_type
==
"
NET RADIO
"
:
self
.
zctrl
.
net_radio
(
media_id
)
self
.
zctrl
.
net_radio
(
media_id
)
def
enable_output
(
self
,
port
,
enabled
)
:
def
enable_output
(
self
,
port
:
str
,
enabled
:
bool
)
->
None
:
"""
Enable or disable an output port..
"""
"""
Enable or disable an output port..
"""
self
.
zctrl
.
enable_output
(
port
,
enabled
)
self
.
zctrl
.
enable_output
(
port
,
enabled
)
def
menu_cursor
(
self
,
cursor
)
:
def
menu_cursor
(
self
,
cursor
:
str
)
->
None
:
"""
Press a menu cursor button.
"""
"""
Press a menu cursor button.
"""
getattr
(
self
.
zctrl
,
CURSOR_TYPE_MAP
[
cursor
])()
getattr
(
self
.
zctrl
,
CURSOR_TYPE_MAP
[
cursor
])()
def
set_scene
(
self
,
scene
)
:
def
set_scene
(
self
,
scene
:
str
)
->
None
:
"""
Set the current scene.
"""
"""
Set the current scene.
"""
try
:
try
:
self
.
zctrl
.
scene
=
scene
self
.
zctrl
.
scene
=
scene
...
...
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