Beispiel #1
0
async def test_send_async_partial_handler(async_handler):
    """Tests sending to async handlers."""
    # Arrange
    partial = functools.partial(async_handler)
    dispatcher = Dispatcher()
    dispatcher.connect("TEST", partial)
    # Act
    await asyncio.gather(*dispatcher.send("TEST"))
    # Assert
    assert async_handler.fired
Beispiel #2
0
async def test_already_disconnected(handler):
    """Tests that disconnect can be called more than once."""
    # Arrange
    dispatcher = Dispatcher()
    disconnect = dispatcher.connect("TEST", handler)
    disconnect()
    # Act
    disconnect()
    # Assert
    assert handler not in dispatcher.signals["TEST"]
Beispiel #3
0
async def test_send(handler):
    """Tests sending to async handlers."""
    # Arrange
    dispatcher = Dispatcher()
    dispatcher.connect("TEST", handler)
    args = object()
    # Act
    await asyncio.gather(*dispatcher.send("TEST", args))
    # Assert
    assert handler.fired
    assert handler.args[0] == args
Beispiel #4
0
 def __init__(
     self,
     host,
     *,
     dispatcher: Dispatcher = Dispatcher(),
     heart_beat: Optional[float] = denon_const.DEFAULT_HEART_BEAT,
     http_api=None,
     telnet: bool = True,
     timeout: float = denon_const.DEFAULT_TIMEOUT,
     zone_aux_class: Zone = DenonAuxZone,
     zone_main_class: DenonMainZone = DenonMainZone,
 ):
     super().__init__(
         host,
         dispatcher=dispatcher,
         heart_beat=heart_beat,
         http_api=http_api,
         telnet=telnet,
         timeout=timeout,
         zone_aux_class=zone_aux_class,
         zone_main_class=zone_main_class,
     )
     self._connection = DenonTelnetConnection(
         self,
         host,
         timeout=timeout,
         heart_beat=heart_beat,
     )
Beispiel #5
0
    def __init__(
        self,
        host: str,
        *,
        dispatcher: Dispatcher = Dispatcher(),
        heart_beat: Optional[float] = const.DEFAULT_HEART_BEAT,
        http_api: HTTPApi = None,
        telnet: bool = True,
        timeout: float = const.DEFAULT_TIMEOUT,
        zone_aux_class: Zone = None,
        zone_main_class: Zone = None,
    ):
        """Init the device."""
        self._host = host
        self._dispatcher = dispatcher
        self._heart_beat = heart_beat
        self._http_api = http_api
        self._telnet = telnet
        self._timeout = timeout
        self._zone_aux_class = zone_aux_class
        self._zone_main_class = zone_main_class

        self._connection = None  # type: TelnetConnection
        self._connections = []
        self._device_info = {}
        self._sources = None  # type: dict
        self._state = defaultdict()

        self._main_zone = None  # type: Zone
        self._zone2, self._zone3, self._zone4 = None, None, None
Beispiel #6
0
async def test_disconnect_all(handler):
    """Tests the disconnect all function."""
    # Arrange
    dispatcher = Dispatcher()
    dispatcher.connect("TEST", handler)
    dispatcher.connect("TEST", handler)
    dispatcher.connect("TEST2", handler)
    dispatcher.connect("TEST3", handler)
    # Act
    dispatcher.disconnect_all()
    # Assert
    assert handler not in dispatcher.signals["TEST"]
    assert handler not in dispatcher.signals["TEST2"]
    assert handler not in dispatcher.signals["TEST3"]
Beispiel #7
0
async def test_custom_connect_and_send(handler):
    """Tests using the custom connect and send implementations."""
    # Arrange
    test_signal = "PREFIX_TEST"
    stored_target = None

    def connect(signal, target):
        assert signal == test_signal
        nonlocal stored_target
        stored_target = target

        def disconnect():
            nonlocal stored_target
            stored_target = None

        return disconnect

    def send(signal, *args):
        assert signal == test_signal
        stored_target(*args)  # pylint:disable=not-callable

    dispatcher = Dispatcher(connect=connect, send=send, signal_prefix="PREFIX_")

    # Act
    dispatcher.connect("TEST", handler)
    dispatcher.send("TEST")
    # Assert
    assert handler.fired
Beispiel #8
0
 def __init__(
     self,
     host,
     *,
     dispatcher: Dispatcher = Dispatcher(),
     heart_beat: Optional[float],
     http_api=None,
     telnet: bool = True,
     timeout: float,
     zone_aux_class: Zone,
     zone_main_class: MainZone,
 ):
     super().__init__(
         host,
         dispatcher=dispatcher,
         heart_beat=heart_beat,
         http_api=http_api,
         telnet=telnet,
         timeout=timeout,
         zone_aux_class=zone_aux_class,
         zone_main_class=zone_main_class,
     )
     self._connection = None  # Instance to your telnet, websocket, etc. connection
Beispiel #9
0
 def __init__(self):
     self.dispatcher = Dispatcher()