From 458e47f9815684a41ee5a988a1c4da37bd9c512d Mon Sep 17 00:00:00 2001 From: jezcooke <61294178+jezcooke@users.noreply.github.com> Date: Sun, 23 Feb 2020 16:05:24 +0000 Subject: [PATCH] Add name option for Frontier Silicon devices (#32085) * Added the option to specify the name of the device in confirguration.yaml * Adding missing default name parameter in auto-discovery FSAPIDevice constructor. * Fixed Black formatting. * Removed DEFAULT_NAME constant. * Apply suggestions from code review Co-Authored-By: springstan <46536646+springstan@users.noreply.github.com> Co-authored-by: springstan <46536646+springstan@users.noreply.github.com> --- .../components/frontier_silicon/media_player.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/frontier_silicon/media_player.py b/homeassistant/components/frontier_silicon/media_player.py index 2336a9e0e06..711a8940493 100644 --- a/homeassistant/components/frontier_silicon/media_player.py +++ b/homeassistant/components/frontier_silicon/media_player.py @@ -24,6 +24,7 @@ from homeassistant.components.media_player.const import ( ) from homeassistant.const import ( CONF_HOST, + CONF_NAME, CONF_PASSWORD, CONF_PORT, STATE_IDLE, @@ -61,6 +62,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string, + vol.Optional(CONF_NAME): cv.string, } ) @@ -69,17 +71,19 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= """Set up the Frontier Silicon platform.""" if discovery_info is not None: async_add_entities( - [AFSAPIDevice(discovery_info["ssdp_description"], DEFAULT_PASSWORD)], True + [AFSAPIDevice(discovery_info["ssdp_description"], DEFAULT_PASSWORD, None)], + True, ) return True host = config.get(CONF_HOST) port = config.get(CONF_PORT) password = config.get(CONF_PASSWORD) + name = config.get(CONF_NAME) try: async_add_entities( - [AFSAPIDevice(DEVICE_URL.format(host, port), password)], True + [AFSAPIDevice(DEVICE_URL.format(host, port), password, name)], True ) _LOGGER.debug("FSAPI device %s:%s -> %s", host, port, password) return True @@ -94,13 +98,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= class AFSAPIDevice(MediaPlayerDevice): """Representation of a Frontier Silicon device on the network.""" - def __init__(self, device_url, password): + def __init__(self, device_url, password, name): """Initialize the Frontier Silicon API device.""" self._device_url = device_url self._password = password self._state = None - self._name = None + self._name = name self._title = None self._artist = None self._album_name = None