async def test_xknx_start_and_stop_with_dedicated_connection_config( self, start_mock): """Test xknx start and stop with connection config.""" xknx = XKNX() connection_config = ConnectionConfig( connection_type=ConnectionType.TUNNELING) xknx.connection_config = connection_config await xknx.start() start_mock.assert_called_once() assert xknx.knxip_interface.connection_config == connection_config await xknx.stop() assert xknx.knxip_interface is None assert xknx.telegram_queue._consumer_task.done() assert not xknx.state_updater.started
def test_xknx_start_and_stop_with_dedicated_connection_config( self, start_mock): """Test xknx start and stop with connection config.""" xknx = XKNX() connection_config = ConnectionConfig( connection_type=ConnectionType.TUNNELING) xknx.connection_config = connection_config self.loop.run_until_complete(xknx.start()) start_mock.assert_called_once() self.assertEqual(xknx.knxip_interface.connection_config, connection_config) self.loop.run_until_complete(xknx.stop()) self.assertIsNone(xknx.knxip_interface) self.assertTrue(xknx.telegram_queue._consumer_task.done()) self.assertFalse(xknx.state_updater.started)
def send_to_ga(self, ga, dpt, value): """ Connect to the KNX bus and set a value. """ if not self.busaccess: logging.warning( "Busaccess disabled, not sending val(%s) to ga(%s)", value, ga ) return loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) xknx = XKNX() if "connection" in self.config: connection_types = { "tunneling": ConnectionType.TUNNELING, "routing": ConnectionType.ROUTING, "auto": ConnectionType.AUTOMATIC, } connection_config = ConnectionConfig( connection_type=connection_types[ self.config["connection"].get("type", "auto") ], gateway_ip=self.config["connection"].get("gateway_ip", None), gateway_port=self.config["connection"].get( "gateway_port", DEFAULT_MCAST_PORT ), local_ip=self.config["connection"].get("local_ip", None), auto_reconnect=self.config["connection"].get("autoReconnect", True), ) logging.debug("Applying custom connection config %s", connection_config) xknx.connection_config = connection_config loop.run_until_complete(xknx.start()) expose_sensor = ExposeSensor( xknx, "CalendarSensor", group_address=ga, value_type=dpt ) logging.info("Sending val(%s) to ga(%s)", value, ga) loop.run_until_complete(expose_sensor.set(value)) logging.debug(expose_sensor) loop.run_until_complete(xknx.stop())