1 """Support for interfacing with Russound via RNET Protocol."""
3 from __future__
import annotations
8 from russound
import russound
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as MEDIA_PLAYER_PLATFORM_SCHEMA,
14 MediaPlayerEntityFeature,
23 _LOGGER = logging.getLogger(__name__)
26 CONF_SOURCES =
"sources"
29 ZONE_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})
31 SOURCE_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})
33 PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend(
35 vol.Required(CONF_HOST): cv.string,
36 vol.Required(CONF_NAME): cv.string,
37 vol.Required(CONF_PORT): cv.port,
38 vol.Required(CONF_ZONES): vol.Schema({cv.positive_int: ZONE_SCHEMA}),
39 vol.Required(CONF_SOURCES): vol.All(cv.ensure_list, [SOURCE_SCHEMA]),
47 add_entities: AddEntitiesCallback,
48 discovery_info: DiscoveryInfoType |
None =
None,
50 """Set up the Russound RNET platform."""
51 host = config.get(CONF_HOST)
52 port = config.get(CONF_PORT)
54 if host
is None or port
is None:
55 _LOGGER.error(
"Invalid config. Expected %s and %s", CONF_HOST, CONF_PORT)
58 russ = russound.Russound(host, port)
61 sources = [source[
"name"]
for source
in config[CONF_SOURCES]]
63 if russ.is_connected():
64 for zone_id, extra
in config[CONF_ZONES].items():
69 _LOGGER.error(
"Not connected to %s:%s", host, port)
73 """Representation of a Russound RNET device."""
75 _attr_supported_features = (
76 MediaPlayerEntityFeature.VOLUME_MUTE
77 | MediaPlayerEntityFeature.VOLUME_SET
78 | MediaPlayerEntityFeature.TURN_ON
79 | MediaPlayerEntityFeature.TURN_OFF
80 | MediaPlayerEntityFeature.SELECT_SOURCE
83 def __init__(self, hass, russ, sources, zone_id, extra):
84 """Initialise the Russound RNET device."""
95 """Retrieve latest state."""
101 except BrokenPipeError:
102 _LOGGER.error(
"Broken Pipe Error, trying to reconnect to Russound RNET")
103 self.
_russ_russ.connect()
106 _LOGGER.debug(
"ret= %s", ret)
109 "Updating status for RNET zone %s on controller %s",
127 _LOGGER.error(
"Could not update status for zone %s", self.
_zone_id_zone_id)
130 """Set volume level. Volume has a range (0..1).
132 Translate this to a range of (0..100) as expected
133 by _russ.set_volume()
138 """Turn the media player on."""
142 """Turn off media player."""
146 """Send mute command."""
150 """Set the input source."""
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)