mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Pass config into NAD constructor (#34961)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
9aac8482d5
commit
1186c2c48c
@ -64,65 +64,42 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the NAD platform."""
|
"""Set up the NAD platform."""
|
||||||
if config.get(CONF_TYPE) == "RS232":
|
if config.get(CONF_TYPE) in ("RS232", "Telnet"):
|
||||||
add_entities(
|
add_entities(
|
||||||
[
|
[NAD(config)], True,
|
||||||
NAD(
|
|
||||||
config.get(CONF_NAME),
|
|
||||||
NADReceiver(config.get(CONF_SERIAL_PORT)),
|
|
||||||
config.get(CONF_MIN_VOLUME),
|
|
||||||
config.get(CONF_MAX_VOLUME),
|
|
||||||
config.get(CONF_SOURCE_DICT),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
True,
|
|
||||||
)
|
|
||||||
elif config.get(CONF_TYPE) == "Telnet":
|
|
||||||
add_entities(
|
|
||||||
[
|
|
||||||
NAD(
|
|
||||||
config.get(CONF_NAME),
|
|
||||||
NADReceiverTelnet(config.get(CONF_HOST), config.get(CONF_PORT)),
|
|
||||||
config.get(CONF_MIN_VOLUME),
|
|
||||||
config.get(CONF_MAX_VOLUME),
|
|
||||||
config.get(CONF_SOURCE_DICT),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
True,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
add_entities(
|
add_entities(
|
||||||
[
|
[NADtcp(config)], True,
|
||||||
NADtcp(
|
|
||||||
config.get(CONF_NAME),
|
|
||||||
NADReceiverTCP(config.get(CONF_HOST)),
|
|
||||||
config.get(CONF_MIN_VOLUME),
|
|
||||||
config.get(CONF_MAX_VOLUME),
|
|
||||||
config.get(CONF_VOLUME_STEP),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NAD(MediaPlayerEntity):
|
class NAD(MediaPlayerEntity):
|
||||||
"""Representation of a NAD Receiver."""
|
"""Representation of a NAD Receiver."""
|
||||||
|
|
||||||
def __init__(self, name, nad_receiver, min_volume, max_volume, source_dict):
|
def __init__(self, config):
|
||||||
"""Initialize the NAD Receiver device."""
|
"""Initialize the NAD Receiver device."""
|
||||||
self._name = name
|
self.config = config
|
||||||
self._nad_receiver = nad_receiver
|
self._instantiate_nad_receiver()
|
||||||
self._min_volume = min_volume
|
self._min_volume = config[CONF_MIN_VOLUME]
|
||||||
self._max_volume = max_volume
|
self._max_volume = config[CONF_MAX_VOLUME]
|
||||||
self._source_dict = source_dict
|
self._source_dict = config[CONF_SOURCE_DICT]
|
||||||
self._reverse_mapping = {value: key for key, value in self._source_dict.items()}
|
self._reverse_mapping = {value: key for key, value in self._source_dict.items()}
|
||||||
|
|
||||||
self._volume = self._state = self._mute = self._source = None
|
self._volume = self._state = self._mute = self._source = None
|
||||||
|
|
||||||
|
def _instantiate_nad_receiver(self) -> NADReceiver:
|
||||||
|
if self.config[CONF_TYPE] == "RS232":
|
||||||
|
self._nad_receiver = NADReceiver(self.config[CONF_SERIAL_PORT])
|
||||||
|
else:
|
||||||
|
host = self.config.get(CONF_HOST)
|
||||||
|
port = self.config[CONF_PORT]
|
||||||
|
self._nad_receiver = NADReceiverTelnet(host, port)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
return self._name
|
return self.config[CONF_NAME]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -232,13 +209,13 @@ class NAD(MediaPlayerEntity):
|
|||||||
class NADtcp(MediaPlayerEntity):
|
class NADtcp(MediaPlayerEntity):
|
||||||
"""Representation of a NAD Digital amplifier."""
|
"""Representation of a NAD Digital amplifier."""
|
||||||
|
|
||||||
def __init__(self, name, nad_device, min_volume, max_volume, volume_step):
|
def __init__(self, config):
|
||||||
"""Initialize the amplifier."""
|
"""Initialize the amplifier."""
|
||||||
self._name = name
|
self._name = config[CONF_NAME]
|
||||||
self._nad_receiver = nad_device
|
self._nad_receiver = NADReceiverTCP(config.get(CONF_HOST))
|
||||||
self._min_vol = (min_volume + 90) * 2 # from dB to nad vol (0-200)
|
self._min_vol = (config[CONF_MIN_VOLUME] + 90) * 2 # from dB to nad vol (0-200)
|
||||||
self._max_vol = (max_volume + 90) * 2 # from dB to nad vol (0-200)
|
self._max_vol = (config[CONF_MAX_VOLUME] + 90) * 2 # from dB to nad vol (0-200)
|
||||||
self._volume_step = volume_step
|
self._volume_step = config[CONF_VOLUME_STEP]
|
||||||
self._state = None
|
self._state = None
|
||||||
self._mute = None
|
self._mute = None
|
||||||
self._nad_volume = None
|
self._nad_volume = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user