Add support for multiple Russound RNET controllers (#96793)
* add mutiple russound rnet controller support * Update homeassistant/components/russound_rnet/media_player.py --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>pull/96890/head
parent
01e66d6fb2
commit
87d0b026c2
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
from russound import russound
|
from russound import russound
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -85,17 +86,25 @@ class RussoundRNETDevice(MediaPlayerEntity):
|
||||||
self._attr_name = extra["name"]
|
self._attr_name = extra["name"]
|
||||||
self._russ = russ
|
self._russ = russ
|
||||||
self._attr_source_list = sources
|
self._attr_source_list = sources
|
||||||
self._zone_id = zone_id
|
# Each controller has a maximum of 6 zones, every increment of 6 zones
|
||||||
|
# maps to an additional controller for easier backward compatibility
|
||||||
|
self._controller_id = str(math.ceil(zone_id / 6))
|
||||||
|
# Each zone resets to 1-6 per controller
|
||||||
|
self._zone_id = (zone_id - 1) % 6 + 1
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
# Updated this function to make a single call to get_zone_info, so that
|
# Updated this function to make a single call to get_zone_info, so that
|
||||||
# with a single call we can get On/Off, Volume and Source, reducing the
|
# with a single call we can get On/Off, Volume and Source, reducing the
|
||||||
# amount of traffic and speeding up the update process.
|
# amount of traffic and speeding up the update process.
|
||||||
ret = self._russ.get_zone_info("1", self._zone_id, 4)
|
ret = self._russ.get_zone_info(self._controller_id, self._zone_id, 4)
|
||||||
_LOGGER.debug("ret= %s", ret)
|
_LOGGER.debug("ret= %s", ret)
|
||||||
if ret is not None:
|
if ret is not None:
|
||||||
_LOGGER.debug("Updating status for zone %s", self._zone_id)
|
_LOGGER.debug(
|
||||||
|
"Updating status for RNET zone %s on controller %s",
|
||||||
|
self._zone_id,
|
||||||
|
self._controller_id,
|
||||||
|
)
|
||||||
if ret[0] == 0:
|
if ret[0] == 0:
|
||||||
self._attr_state = MediaPlayerState.OFF
|
self._attr_state = MediaPlayerState.OFF
|
||||||
else:
|
else:
|
||||||
|
@ -118,23 +127,23 @@ class RussoundRNETDevice(MediaPlayerEntity):
|
||||||
Translate this to a range of (0..100) as expected
|
Translate this to a range of (0..100) as expected
|
||||||
by _russ.set_volume()
|
by _russ.set_volume()
|
||||||
"""
|
"""
|
||||||
self._russ.set_volume("1", self._zone_id, volume * 100)
|
self._russ.set_volume(self._controller_id, self._zone_id, volume * 100)
|
||||||
|
|
||||||
def turn_on(self) -> None:
|
def turn_on(self) -> None:
|
||||||
"""Turn the media player on."""
|
"""Turn the media player on."""
|
||||||
self._russ.set_power("1", self._zone_id, "1")
|
self._russ.set_power(self._controller_id, self._zone_id, "1")
|
||||||
|
|
||||||
def turn_off(self) -> None:
|
def turn_off(self) -> None:
|
||||||
"""Turn off media player."""
|
"""Turn off media player."""
|
||||||
self._russ.set_power("1", self._zone_id, "0")
|
self._russ.set_power(self._controller_id, self._zone_id, "0")
|
||||||
|
|
||||||
def mute_volume(self, mute: bool) -> None:
|
def mute_volume(self, mute: bool) -> None:
|
||||||
"""Send mute command."""
|
"""Send mute command."""
|
||||||
self._russ.toggle_mute("1", self._zone_id)
|
self._russ.toggle_mute(self._controller_id, self._zone_id)
|
||||||
|
|
||||||
def select_source(self, source: str) -> None:
|
def select_source(self, source: str) -> None:
|
||||||
"""Set the input source."""
|
"""Set the input source."""
|
||||||
if self.source_list and source in self.source_list:
|
if self.source_list and source in self.source_list:
|
||||||
index = self.source_list.index(source)
|
index = self.source_list.index(source)
|
||||||
# 0 based value for source
|
# 0 based value for source
|
||||||
self._russ.set_source("1", self._zone_id, index)
|
self._russ.set_source(self._controller_id, self._zone_id, index)
|
||||||
|
|
Loading…
Reference in New Issue