Exemplo n.º 1
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Denon platform."""
    import denonavr

    # Initialize list with receivers to be started
    receivers = []

    cache = hass.data.get(KEY_DENON_CACHE)
    if cache is None:
        cache = hass.data[KEY_DENON_CACHE] = set()

    # Start assignment of host and name
    show_all_sources = config.get(CONF_SHOW_ALL_SOURCES)
    # 1. option: manual setting
    if config.get(CONF_HOST) is not None:
        host = config.get(CONF_HOST)
        name = config.get(CONF_NAME)
        # Check if host not in cache, append it and save for later starting
        if host not in cache:
            cache.add(host)
            receivers.append(
                DenonDevice(denonavr.DenonAVR(host, name, show_all_sources)))
            _LOGGER.info("Denon receiver at host %s initialized", host)
    # 2. option: discovery using netdisco
    if discovery_info is not None:
        host = discovery_info.get('host')
        name = discovery_info.get('name')
        # Check if host not in cache, append it and save for later starting
        if host not in cache:
            cache.add(host)
            receivers.append(
                DenonDevice(denonavr.DenonAVR(host, name, show_all_sources)))
            _LOGGER.info("Denon receiver at host %s initialized", host)
    # 3. option: discovery using denonavr library
    if config.get(CONF_HOST) is None and discovery_info is None:
        d_receivers = denonavr.discover()
        # More than one receiver could be discovered by that method
        if d_receivers is not None:
            for d_receiver in d_receivers:
                host = d_receiver["host"]
                name = d_receiver["friendlyName"]
                # Check if host not in cache, append it and save for later
                # starting
                if host not in cache:
                    cache.add(host)
                    receivers.append(
                        DenonDevice(
                            denonavr.DenonAVR(host, name, show_all_sources)))
                    _LOGGER.info("Denon receiver at host %s initialized", host)

    # Add all freshly discovered receivers
    if receivers:
        add_devices(receivers)
Exemplo n.º 2
0
def main():
    print("Content-Type: text/html\n\n")  # just used as convention
    try:
        if sys.argv[2] == 'one':  #The station given is one
            d = denonavr.DenonAVR('10.61.20.10')  #set IP for station one
            d.input_func = sys.argv[1]  # change the input of station one
            print("Input on station " + sys.argv[2] +
                  " successfully changed to " + sys.argv[1])
        else:
            d = denonavr.DenonAVR('10.61.22.58')  #set IP for station two
            d.input_func = sys.argv[1]
            print("Input on station " + sys.argv[2] +
                  " successfully changed to " + sys.argv[1])
    except Exception as e:
        print(e)
Exemplo n.º 3
0
    def cmd(self, cmd):
        if "denon" in cmd:
            d = denonavr.DenonAVR(app_cfg['denon']['ip'])
            d.update()

            if cmd == "denon_input_digital":
                d.input_func = app_cfg['denon']['digital_in']
            elif cmd == "denon_power_off":
                d.power_off()
            elif cmd == "denon_power_on":
                d.power_on()
            elif cmd == "denon_vol_down":
                d.volume_down()
            elif cmd == "denon_vol_mute":
                d.mute(True)  #FIXME
            elif cmd == "denon_vol_up":
                d.volume_up()
            else:
                return '{"response":"invalid_cmd"}'

            return '{"response":"ok"}'

        elif "lg" in cmd:
            w = WebOsClient(app_cfg['lg']['ip'])
            w.register()

            if "lg_arr_" in cmd:
                w.request(
                    "com.webos.service.networkinput/getPointerInputSocket")
                ws = websocket.WebSocket()
                ws.connect(w.last_response['payload']['socketPath'])
                if cmd == "lg_arr_down":
                    ws.send('type:button\nname:DOWN\n\n')
                elif cmd == "lg_arr_up":
                    ws.send('type:button\nname:UP\n\n')
                elif cmd == "lg_arr_left":
                    ws.send('type:button\nname:LEFT\n\n')
                elif cmd == "lg_arr_right":
                    ws.send('type:button\nname:RIGHT\n\n')
                elif cmd == "lg_arr_ok":
                    ws.send('type:button\nname:ENTER\n\n')
                elif cmd == "lg_arr_back":
                    ws.send('type:button\nname:BACK\n\n')
            elif cmd == "lg_cmd_pause":
                w.pause()
            elif cmd == "lg_input_netflix":
                w.launch_app(app_cfg['lg']['netflix'])
            elif cmd == "lg_input_ps4":
                w.set_input(app_cfg['lg']['ps4'])
            elif cmd == "lg_power_on":
                send_magic_packet(app_cfg['lg']['mac'])
            elif cmd == "lg_power_off":
                w.power_off()
            else:
                return '{"response":"invalid_cmd"}'

            return '{"response":"ok"}'

        else:
            return '{"response":"invalid_cmd"}'
Exemplo n.º 4
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Denon platform."""
    import denonavr

    receiver = denonavr.DenonAVR(config.get(CONF_HOST), config.get(CONF_NAME))

    add_devices([DenonDevice(receiver)])
    _LOGGER.info("Denon receiver at host %s initialized",
                 config.get(CONF_HOST))
Exemplo n.º 5
0
 def test_attributes_not_none(self, mock):
     """Check that certain attributes are not None."""
     mock.add_matcher(self.custom_matcher)
     for receiver, zones in TESTING_RECEIVERS.items():
         # Switch receiver and update to load new sample files
         self._testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=zones)
         self.assertIsNotNone(
             self.denon.power,
             "Power status is None for receiver {}".format(receiver))
         self.assertIsNotNone(
             self.denon.state,
             "State is None for receiver {}".format(receiver))
Exemplo n.º 6
0
 async def test_attributes_not_none(self, httpx_mock: HTTPXMock):
     """Check that certain attributes are not None."""
     httpx_mock.add_callback(self.custom_matcher)
     for receiver, spec in TESTING_RECEIVERS.items():
         print("Receiver: {}".format(receiver))
         # Switch receiver and update to load new sample files
         self.testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
         await self.denon.async_update()
         assert self.denon.power is not None, (
             "Power status is None for receiver {}".format(receiver))
         assert self.denon.state is not None, (
             "State is None for receiver {}".format(receiver))
Exemplo n.º 7
0
 def test_input_func_switch(self, mock):
     """Switch through all input functions of all tested receivers."""
     mock.add_matcher(self.custom_matcher)
     for receiver, zones in TESTING_RECEIVERS.items():
         # Switch receiver and update to load new sample files
         self._testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=zones)
         # Switch through all functions and check if successful
         for zone in self.denon.zones.values():
             for input_func in zone.input_func_list:
                 self.denon.set_input_func(input_func)
                 self.assertEqual(
                     input_func, self.denon.input_func,
                     ("Input function change to {func} "
                      "not successful").format(func=input_func))
Exemplo n.º 8
0
 async def test_input_func_switch(self, httpx_mock: HTTPXMock):
     """Switch through all input functions of all tested receivers."""
     httpx_mock.add_callback(self.custom_matcher)
     for receiver, spec in TESTING_RECEIVERS.items():
         # Switch receiver and update to load new sample files
         self.testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
         # Switch through all functions and check if successful
         for name, zone in self.denon.zones.items():
             print("Receiver: {}, Zone: {}".format(receiver, name))
             await self.denon.zones[name].async_update()
             assert len(zone.input_func_list) > 0
             for input_func in zone.input_func_list:
                 await self.denon.zones[name].async_set_input_func(
                     input_func)
Exemplo n.º 9
0
 async def test_receiver_type(self, httpx_mock: HTTPXMock):
     """Check that receiver type is determined correctly."""
     httpx_mock.add_callback(self.custom_matcher)
     for receiver, spec in TESTING_RECEIVERS.items():
         print("Receiver: {}".format(receiver))
         # Switch receiver and update to load new sample files
         self.testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
         await self.denon.async_update()
         assert self.denon.receiver_type == spec[1].type, (
             "Receiver type is {} not {} for receiver {}".format(
                 self.denon.receiver_type, spec[1].type, receiver))
         assert self.denon.receiver_port == spec[1].port, (
             "Receiver port is {} not {} for receiver {}".format(
                 self.denon.receiver_port, spec[1].port, receiver))
Exemplo n.º 10
0
 def test_receiver_type(self, mock):
     """Check that receiver type is determined correctly."""
     mock.add_matcher(self.custom_matcher)
     for receiver, spec in TESTING_RECEIVERS.items():
         # Switch receiver and update to load new sample files
         self._testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
         self.assertEqual(
             self.denon.receiver_type, spec[1].type,
             "Receiver type is {} not {} for receiver {}".format(
                 self.denon.receiver_type, spec[1].type, receiver))
         self.assertEqual(
             self.denon.receiver_port, spec[1].port,
             "Receiver port is {} not {} for receiver {}".format(
                 self.denon.receiver_port, spec[1].port, receiver))
Exemplo n.º 11
0
    def init_receiver_class(self):
        """Initialize the DenonAVR class in a way that can called by async_add_executor_job."""
        try:
            self._receiver = denonavr.DenonAVR(
                host=self._host,
                show_all_inputs=self._show_all_inputs,
                timeout=self._timeout,
                add_zones=self._zones,
            )
        except ConnectionError:
            _LOGGER.error(
                "ConnectionError during setup of denonavr with host %s", self._host
            )
            return False

        return True
Exemplo n.º 12
0
 async def test_sound_mode(self, httpx_mock: HTTPXMock):
     """Check if a valid sound mode is returned."""
     httpx_mock.add_callback(self.custom_matcher)
     for receiver, spec in TESTING_RECEIVERS.items():
         # Switch receiver and update to load new sample files
         self.testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
         # Switch through all functions and check if successful
         for name in self.denon.zones:
             print("Receiver: {}, Zone: {}".format(receiver, name))
             await self.denon.zones[name].async_update()
             support_sound_mode = self.denon.zones[name].support_sound_mode
             sound_mode = self.denon.zones[name].sound_mode
             assert (
                 sound_mode in [*SOUND_MODE_MAPPING, None] or
                 support_sound_mode is not True)
Exemplo n.º 13
0
 def test_input_func_switch(self, mock):
     """Switch through all input functions of all tested receivers."""
     mock.add_matcher(self.custom_matcher)
     for receiver, spec in TESTING_RECEIVERS.items():
         # Switch receiver and update to load new sample files
         self._testing_receiver = receiver
         self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0])
         # Switch through all functions and check if successful
         for name, zone in self.denon.zones.items():
             print("Receiver: {}, Zone: {}".format(receiver, name))
             self.assertGreater(len(zone.input_func_list), 0)
             for input_func in zone.input_func_list:
                 self.denon.zones[name].set_input_func(input_func)
                 self.assertEqual(input_func,
                                  self.denon.zones[name].input_func,
                                  ("Input function change to {func} "
                                   "not successful for {receiver}").format(
                                       func=input_func, receiver=receiver))
Exemplo n.º 14
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Denon platform."""
    import denonavr

    # Initialize list with receivers to be started
    receivers = []

    cache = hass.data.get(KEY_DENON_CACHE)
    if cache is None:
        cache = hass.data[KEY_DENON_CACHE] = set()

    # Get config option for show_all_sources and timeout
    show_all_sources = config.get(CONF_SHOW_ALL_SOURCES)
    timeout = config.get(CONF_TIMEOUT)

    # Get config option for additional zones
    zones = config.get(CONF_ZONES)
    if zones is not None:
        add_zones = {}
        for entry in zones:
            add_zones[entry[CONF_ZONE]] = entry.get(CONF_NAME)
    else:
        add_zones = None

    # Start assignment of host and name
    new_hosts = []
    # 1. option: manual setting
    if config.get(CONF_HOST) is not None:
        host = config.get(CONF_HOST)
        name = config.get(CONF_NAME)
        new_hosts.append(NewHost(host=host, name=name))

    # 2. option: discovery using netdisco
    if discovery_info is not None:
        host = discovery_info.get('host')
        name = discovery_info.get('name')
        new_hosts.append(NewHost(host=host, name=name))

    # 3. option: discovery using denonavr library
    if config.get(CONF_HOST) is None and discovery_info is None:
        d_receivers = denonavr.discover()
        # More than one receiver could be discovered by that method
        for d_receiver in d_receivers:
            host = d_receiver["host"]
            name = d_receiver["friendlyName"]
            new_hosts.append(NewHost(host=host, name=name))

    for entry in new_hosts:
        # Check if host not in cache, append it and save for later
        # starting
        if entry.host not in cache:
            new_device = denonavr.DenonAVR(host=entry.host,
                                           name=entry.name,
                                           show_all_inputs=show_all_sources,
                                           timeout=timeout,
                                           add_zones=add_zones)
            for new_zone in new_device.zones.values():
                receivers.append(DenonDevice(new_zone))
            cache.add(host)
            _LOGGER.info("Denon receiver at host %s initialized", host)

    # Add all freshly discovered receivers
    if receivers:
        add_entities(receivers)
Exemplo n.º 15
0
 def setUp(self, m):
     """Setup method, using the first receiver from list"""
     self._testing_receiver = TESTING_RECEIVERS[0]
     super(TestMainFunctions, self).setUp()
     m.add_matcher(self.custom_matcher)
     self.denon = denonavr.DenonAVR(FAKE_IP)
Exemplo n.º 16
0
import denonavr
import rumps

zone2 = {"Zone2": "Office"}
d = denonavr.DenonAVR("192.168.1.212", add_zones=zone2)
d.update()


class AvrApp(object):
    def __init__(self):
        self.app = rumps.App("AVR", "🎛️")

    print(d.volume, d.zones["Zone2"].volume)

    @rumps.clicked("Volume +")
    def volume_up(self):
        d.zones["Zone2"].volume_up()
        d.zones["Zone2"].update()
        print("Up volume is: ", d.zones["Zone2"].volume)

    @rumps.clicked("Volume -")
    def volume_down(self):
        d.zones["Zone2"].volume_down()
        d.zones["Zone2"].update()
        print("Down volume is: ", d.zones["Zone2"].volume)

    @rumps.clicked("Mute On")
    def mute_on(self):
        d.zones["Zone2"].mute(True)
        d.zones["Zone2"].update()
Exemplo n.º 17
0

def ping(host):
    """
    Returns True if host responds to a ping request
    """

    # Ping parameters as function of OS
    args = "ping -c 1 -W 1 " + host
    return subprocess.call(args,
                           shell=True,
                           stdout=subprocess.DEVNULL,
                           stderr=subprocess.DEVNULL) == 0


denon = denonavr.DenonAVR(IP_AUDIO)
app = Flask(__name__)
api = Api(app)


@api.route('/beamer/<string:action>')
class Beamer(Resource):
    def put(self, action):
        if action == "on":
            for l in range(1, 5):
                os.system("irsend SEND_ONCE EPSON-TW6000 KEY_POWERUP")
                time.sleep(0.05)
            return {'result': "OK"}
        elif action == "off":
            for l in range(1, 5):
                os.system("irsend SEND_ONCE EPSON-TW6000 KEY_SUSPEND")
import denonavr
import os
import time
import config as CONFIG

# Setup connection
denon = denonavr.DenonAVR(CONFIG.CONNECTION.IP)


# define clear
def clear():
    # for windows
    if os.name == 'nt':
        os.system('cls')

    # for mac and linux
    else:
        os.system('clear')


# Power Check Function
def power_check():
    if denon.power == 'ON':
        menu()
    if denon.power == 'OFF':
        print("::: Device is OFF")
        question_power = input("::: Turn device on? (Yes[y] No[n]): ").lower()
        if question_power in ['y', 'yes']:
            try:
                denon.power_on()
                print("::: Power is ON, going to menu...")
Exemplo n.º 19
0
        'AUX': 'AUX1',
        'TV AUDIO': 'TV'
    }
    denon._input_func_list = inputMapping  # pylint: disable=protected-access
    return inputMapping

def source(denon, mqttClient, arg):
    inputMapping = updateInputList(denon)

    if arg in inputMapping:
        denon.input_func = arg
    else:
        LOGGER.info('INPUT, invalid argument: %s', arg)

def play(denon, mqttClient, arg):
    LOGGER.info('PLAY/PAUSE')
    denon.toggle_play_pause()
    refresh(denon, mqttClient)

if __name__ == '__main__':
    d = denonavr.DenonAVR(DENON_HOST, 'Denon')
    updateInputList(d)

    d.update()

    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = lambda client, userdata, msg: on_message(d, client, userdata, msg)
    client.connect(MQTT_BROKER, 1883, 60)
    client.loop_forever()
Exemplo n.º 20
0

def volume_down(tray):
    """Volume Down by 5dB."""
    AVR.update()
    volume_before = AVR.volume
    AVR.set_volume(volume_before - 5)
    AVR.update()
    volume_after = AVR.volume
    print("Volume turned down from %i to %i." %
          (volume_before + DB_OFFSET, volume_after + DB_OFFSET))
    return tray


# initialize connection
AVR = denonavr.DenonAVR(RECEIVER_ADDRESS)

# create source selection menu options
SOURCE_SELECTORS = []
for source in AVR.input_func_list:
    source_short = "".join(x for x in source if x.isalpha())
    exec("def select_%s(systray): AVR.input_func = '%s'" %
         (source_short, source))
    SOURCE_SELECTORS += [("Select %s" % source, None,
                          eval("select_%s" % source_short))]

# build up full set of tray icon menu options
MENU_OPTIONS = [
    ("Power On", None, power_on),
    ("Power Off", None, power_off),
    ("Volume Up", None, volume_up),