async def start(self, state_updater=False, daemon_mode=False, connection_config=None): """Start XKNX module. Connect to KNX/IP devices and start state updater.""" if connection_config is None: if self.connection_config is None: connection_config = ConnectionConfig() else: connection_config = self.connection_config self.knxip_interface = KNXIPInterface( self, connection_config=connection_config) self.logger.info('XKNX v%s starting %s connection to KNX bus.', VERSION, connection_config.connection_type.name.lower()) await self.knxip_interface.start() await self.telegram_queue.start() if state_updater: from xknx.core import StateUpdater self.state_updater = StateUpdater(self) await self.state_updater.start() if daemon_mode: await self.loop_until_sigint() self.started = True
def __init__( self, own_address: str | IndividualAddress = DEFAULT_ADDRESS, address_format: GroupAddressType = GroupAddressType.LONG, telegram_received_cb: Callable[[Telegram], Awaitable[None]] | None = None, device_updated_cb: Callable[[Device], Awaitable[None]] | None = None, connection_state_changed_cb: Callable[[XknxConnectionState], Awaitable[None]] | None = None, rate_limit: int = DEFAULT_RATE_LIMIT, multicast_group: str = DEFAULT_MCAST_GRP, multicast_port: int = DEFAULT_MCAST_PORT, log_directory: str | None = None, state_updater: bool = False, daemon_mode: bool = False, connection_config: ConnectionConfig = ConnectionConfig(), ) -> None: """Initialize XKNX class.""" self.devices = Devices() self.telegrams: asyncio.Queue[Telegram | None] = asyncio.Queue() self.sigint_received = asyncio.Event() self.telegram_queue = TelegramQueue(self) self.state_updater = StateUpdater(self) self.connection_manager = ConnectionManager() self.task_registry = TaskRegistry(self) self.start_state_updater = state_updater self.knxip_interface: KNXIPInterface | None = None self.started = asyncio.Event() self.address_format = address_format self.own_address = IndividualAddress(own_address) self.rate_limit = rate_limit self.multicast_group = multicast_group self.multicast_port = multicast_port self.connection_config = connection_config self.daemon_mode = daemon_mode self.version = VERSION self.current_address = IndividualAddress(0) if log_directory is not None: self.setup_logging(log_directory) if telegram_received_cb is not None: self.telegram_queue.register_telegram_received_cb( telegram_received_cb) if device_updated_cb is not None: self.devices.register_device_updated_cb(device_updated_cb) if connection_state_changed_cb is not None: self.connection_manager.register_connection_state_changed_cb( connection_state_changed_cb)
def __init__( self, config=None, own_address=DEFAULT_ADDRESS, address_format=GroupAddressType.LONG, telegram_received_cb=None, device_updated_cb=None, rate_limit=DEFAULT_RATE_LIMIT, multicast_group=DEFAULT_MCAST_GRP, multicast_port=DEFAULT_MCAST_PORT, log_directory=None, state_updater=False, daemon_mode=False, connection_config=ConnectionConfig(), ): """Initialize XKNX class.""" # pylint: disable=too-many-arguments self.devices = Devices() self.telegrams = asyncio.Queue() self.sigint_received = asyncio.Event() self.telegram_queue = TelegramQueue(self) self.state_updater = StateUpdater(self) self.knxip_interface = None self.started = asyncio.Event() self.address_format = address_format self.own_address = PhysicalAddress(own_address) self.rate_limit = rate_limit self.multicast_group = multicast_group self.multicast_port = multicast_port self.connection_config = connection_config self.start_state_updater = state_updater self.daemon_mode = daemon_mode self.version = VERSION if log_directory is not None: self.setup_logging(log_directory) if config is not None: Config(self).read(config) if telegram_received_cb is not None: self.telegram_queue.register_telegram_received_cb( telegram_received_cb) if device_updated_cb is not None: self.devices.register_device_updated_cb(device_updated_cb)
def __init__( self, config: Optional[str] = None, own_address: Union[str, IndividualAddress] = DEFAULT_ADDRESS, address_format: GroupAddressType = GroupAddressType.LONG, telegram_received_cb: Optional[Callable[[Telegram], Awaitable[None]]] = None, device_updated_cb: Optional[Callable[[Device], Awaitable[None]]] = None, rate_limit: int = DEFAULT_RATE_LIMIT, multicast_group: str = DEFAULT_MCAST_GRP, multicast_port: int = DEFAULT_MCAST_PORT, log_directory: Optional[str] = None, state_updater: bool = False, daemon_mode: bool = False, connection_config: ConnectionConfig = ConnectionConfig(), ) -> None: """Initialize XKNX class.""" # pylint: disable=too-many-arguments self.devices = Devices() self.telegrams: asyncio.Queue[Optional[Telegram]] = asyncio.Queue() self.sigint_received = asyncio.Event() self.telegram_queue = TelegramQueue(self) self.state_updater = StateUpdater(self) self.knxip_interface: Optional[KNXIPInterface] = None self.started = asyncio.Event() self.connected = asyncio.Event() self.address_format = address_format self.own_address = IndividualAddress(own_address) self.rate_limit = rate_limit self.multicast_group = multicast_group self.multicast_port = multicast_port self.connection_config = connection_config self.start_state_updater = state_updater self.daemon_mode = daemon_mode self.version = VERSION if log_directory is not None: self.setup_logging(log_directory) if config is not None: Config(self).read(config) if telegram_received_cb is not None: self.telegram_queue.register_telegram_received_cb(telegram_received_cb) if device_updated_cb is not None: self.devices.register_device_updated_cb(device_updated_cb)
def test_state_updater(self): """Test State updater.""" xknx = XKNX(loop=self.loop) light = Light(xknx, name='TestLight', group_address_switch='1/0/9') xknx.devices.add(light) state_updater = StateUpdater(xknx, timeout=0, start_timeout=0) state_updater.run_forever = False with patch('xknx.devices.Device.sync') as mock_sync: fut = asyncio.Future() fut.set_result(None) mock_sync.return_value = fut self.loop.run_until_complete(asyncio.Task(state_updater.start())) self.loop.run_until_complete(state_updater.run_task) mock_sync.assert_called_with()
def start(self, state_updater=False, daemon_mode=False, connection_config=ConnectionConfig()): """Start XKNX module. Connect to KNX/IP devices and start state updater.""" self.knxip_interface = KNXIPInterface( self, connection_config=connection_config) yield from self.knxip_interface.start() yield from self.telegram_queue.start() if state_updater: from xknx.core import StateUpdater self.state_updater = StateUpdater(self) yield from self.state_updater.start() if daemon_mode: yield from self.loop_until_sigint() self.started = True
def __init__( self, config=None, loop=None, own_address=DEFAULT_ADDRESS, address_format=GroupAddressType.LONG, telegram_received_cb=None, device_updated_cb=None, rate_limit=DEFAULT_RATE_LIMIT, multicast_group=DEFAULT_MCAST_GRP, multicast_port=DEFAULT_MCAST_PORT, ): """Initialize XKNX class.""" # pylint: disable=too-many-arguments self.devices = Devices() self.telegrams = asyncio.Queue() self.loop = loop or asyncio.get_event_loop() self.sigint_received = asyncio.Event() self.telegram_queue = TelegramQueue(self) self.state_updater = StateUpdater(self) self.knxip_interface = None self.started = asyncio.Event() self.address_format = address_format self.own_address = PhysicalAddress(own_address) self.rate_limit = rate_limit self.multicast_group = multicast_group self.multicast_port = multicast_port self.logger = logging.getLogger("xknx.log") self.knx_logger = logging.getLogger("xknx.knx") self.telegram_logger = logging.getLogger("xknx.telegram") self.raw_socket_logger = logging.getLogger("xknx.raw_socket") self.connection_config = None self.version = VERSION if config is not None: Config(self).read(config) if telegram_received_cb is not None: self.telegram_queue.register_telegram_received_cb( telegram_received_cb) if device_updated_cb is not None: self.devices.register_device_updated_cb(device_updated_cb)