mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Yamaha MusicCast: check known_hosts (#9580)
* Yamaha MusicCast: check known_hosts - pymusiccast: Version bump * Update requirements
This commit is contained in:
parent
52561d4f7c
commit
94370eda54
@ -33,7 +33,9 @@ SUPPORTED_FEATURES = (
|
|||||||
SUPPORT_SELECT_SOURCE
|
SUPPORT_SELECT_SOURCE
|
||||||
)
|
)
|
||||||
|
|
||||||
REQUIREMENTS = ['pymusiccast==0.1.0']
|
KNOWN_HOSTS_KEY = 'data_yamaha_musiccast'
|
||||||
|
|
||||||
|
REQUIREMENTS = ['pymusiccast==0.1.2']
|
||||||
|
|
||||||
DEFAULT_NAME = "Yamaha Receiver"
|
DEFAULT_NAME = "Yamaha Receiver"
|
||||||
DEFAULT_PORT = 5005
|
DEFAULT_PORT = 5005
|
||||||
@ -47,16 +49,48 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Yamaha MusicCast platform."""
|
"""Set up the Yamaha MusicCast platform."""
|
||||||
|
import socket
|
||||||
import pymusiccast
|
import pymusiccast
|
||||||
|
|
||||||
|
known_hosts = hass.data.get(KNOWN_HOSTS_KEY)
|
||||||
|
if known_hosts is None:
|
||||||
|
known_hosts = hass.data[KNOWN_HOSTS_KEY] = []
|
||||||
|
_LOGGER.debug("known_hosts: %s", known_hosts)
|
||||||
|
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
port = config.get(CONF_PORT)
|
port = config.get(CONF_PORT)
|
||||||
|
|
||||||
receiver = pymusiccast.McDevice(host, udp_port=port)
|
# Get IP of host to prevent duplicates
|
||||||
_LOGGER.debug("receiver: %s / Port: %d", receiver, port)
|
try:
|
||||||
|
ipaddr = socket.gethostbyname(host)
|
||||||
|
except (OSError) as error:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Could not communicate with %s:%d: %s", host, port, error)
|
||||||
|
return
|
||||||
|
|
||||||
add_devices([YamahaDevice(receiver, name)], True)
|
if [item for item in known_hosts if item[0] == ipaddr]:
|
||||||
|
_LOGGER.warning("Host %s:%d already registered.", host, port)
|
||||||
|
return
|
||||||
|
|
||||||
|
if [item for item in known_hosts if item[1] == port]:
|
||||||
|
_LOGGER.warning("Port %s:%d already registered.", host, port)
|
||||||
|
return
|
||||||
|
|
||||||
|
reg_host = (ipaddr, port)
|
||||||
|
known_hosts.append(reg_host)
|
||||||
|
|
||||||
|
try:
|
||||||
|
receiver = pymusiccast.McDevice(ipaddr, udp_port=port)
|
||||||
|
except pymusiccast.exceptions.YMCInitError as err:
|
||||||
|
_LOGGER.error(err)
|
||||||
|
receiver = None
|
||||||
|
|
||||||
|
if receiver:
|
||||||
|
_LOGGER.debug("receiver: %s / Port: %d", receiver, port)
|
||||||
|
add_devices([YamahaDevice(receiver, name)], True)
|
||||||
|
else:
|
||||||
|
known_hosts.remove(reg_host)
|
||||||
|
|
||||||
|
|
||||||
class YamahaDevice(MediaPlayerDevice):
|
class YamahaDevice(MediaPlayerDevice):
|
||||||
|
@ -675,7 +675,7 @@ pymochad==0.1.1
|
|||||||
pymodbus==1.3.1
|
pymodbus==1.3.1
|
||||||
|
|
||||||
# homeassistant.components.media_player.yamaha_musiccast
|
# homeassistant.components.media_player.yamaha_musiccast
|
||||||
pymusiccast==0.1.0
|
pymusiccast==0.1.2
|
||||||
|
|
||||||
# homeassistant.components.cover.myq
|
# homeassistant.components.cover.myq
|
||||||
pymyq==0.0.8
|
pymyq==0.0.8
|
||||||
|
Loading…
x
Reference in New Issue
Block a user