Add setup type hints to yamaha (#63811)

Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-10 16:45:59 +01:00 committed by GitHub
parent 505320f827
commit e3784b9c3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -31,7 +31,9 @@ from homeassistant.const import (
STATE_ON, STATE_ON,
STATE_PLAYING, STATE_PLAYING,
) )
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import ( from .const import (
@ -99,15 +101,17 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
class YamahaConfigInfo: class YamahaConfigInfo:
"""Configuration Info for Yamaha Receivers.""" """Configuration Info for Yamaha Receivers."""
def __init__(self, config: ConfigType, discovery_info: DiscoveryInfoType) -> None: def __init__(
self, config: ConfigType, discovery_info: DiscoveryInfoType | None
) -> None:
"""Initialize the Configuration Info for Yamaha Receiver.""" """Initialize the Configuration Info for Yamaha Receiver."""
self.name = config.get(CONF_NAME) self.name = config.get(CONF_NAME)
self.host = config.get(CONF_HOST) self.host = config.get(CONF_HOST)
self.ctrl_url: str | None = f"http://{self.host}:80/YamahaRemoteControl/ctrl" self.ctrl_url: str | None = f"http://{self.host}:80/YamahaRemoteControl/ctrl"
self.source_ignore = config.get(CONF_SOURCE_IGNORE) self.source_ignore = config[CONF_SOURCE_IGNORE]
self.source_names = config.get(CONF_SOURCE_NAMES) self.source_names = config[CONF_SOURCE_NAMES]
self.zone_ignore = config.get(CONF_ZONE_IGNORE) self.zone_ignore = config[CONF_ZONE_IGNORE]
self.zone_names = config.get(CONF_ZONE_NAMES) self.zone_names = config[CONF_ZONE_NAMES]
self.from_discovery = False self.from_discovery = False
if discovery_info is not None: if discovery_info is not None:
self.name = discovery_info.get("name") self.name = discovery_info.get("name")
@ -138,9 +142,13 @@ def _discovery(config_info):
return receivers return receivers
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Yamaha platform.""" """Set up the Yamaha platform."""
# Keep track of configured receivers so that we don't end up # Keep track of configured receivers so that we don't end up
# discovering a receiver dynamically that we have static config # discovering a receiver dynamically that we have static config
# for. Map each device from its zone_id . # for. Map each device from its zone_id .

View File

@ -74,6 +74,12 @@ async def test_setup_no_host(hass, device, main_zone):
async def test_setup_discovery(hass, device, main_zone): async def test_setup_discovery(hass, device, main_zone):
"""Test set up integration via discovery.""" """Test set up integration via discovery."""
with patch("rxv.find", return_value=[device]):
assert await async_setup_component(
hass, "media_player", {"media_player": {"platform": "yamaha"}}
)
await hass.async_block_till_done()
discovery_info = { discovery_info = {
"name": "Yamaha Receiver", "name": "Yamaha Receiver",
"model_name": "Yamaha", "model_name": "Yamaha",