Exemplo n.º 1
0
    def __init__(self,
                 config=None,
                 loop=None,
                 own_address=Address(DEFAULT_ADDRESS),
                 address_format=AddressFormat.LEVEL3,
                 telegram_received_cb=None,
                 device_updated_cb=None):
        """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 = None
        self.knxip_interface = None
        self.started = False
        self.address_format = address_format
        self.own_address = own_address
        self.logger = logging.getLogger('xknx.log')
        self.knx_logger = logging.getLogger('xknx.knx')
        self.telegram_logger = logging.getLogger('xknx.telegram')

        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)
Exemplo n.º 2
0
 def test_version_2(self):
     """Test connection section from config file."""
     # Replaces setting from xknx.yaml
     test_config = """
     version: 2
     """
     config = yaml.safe_load(test_config)
     self.assertRaises(NotImplementedError,
                       Config(TestConfig.xknx).parse, config)
Exemplo n.º 3
0
    def test_config_connection(self):
        """Test connection section from config file."""

        # Default connection setting from xknx.yaml (auto:)
        self.assertEqual(
            TestConfig.xknx.connection_config,
            ConnectionConfig(connection_type=ConnectionType.AUTOMATIC),
        )
        # Replaces setting from xknx.yaml
        test_configs = [
            (
                """
            connection:
                tunneling:
                    local_ip: '192.168.1.2'
                    gateway_ip: 192.168.1.15
                    gateway_port: 6000
            """,
                ConnectionConfig(
                    connection_type=ConnectionType.TUNNELING,
                    local_ip="192.168.1.2",
                    gateway_ip="192.168.1.15",
                    gateway_port=6000,
                ),
            ),
            (
                """
            connection:
                tunneling:
                    gateway_ip: '192.168.1.2'
            """,
                ConnectionConfig(connection_type=ConnectionType.TUNNELING,
                                 gateway_ip="192.168.1.2"),
            ),
            (
                """
            connection:
                routing:
                    local_ip: '192.168.1.2'
            """,
                ConnectionConfig(connection_type=ConnectionType.ROUTING,
                                 local_ip="192.168.1.2"),
            ),
            (
                """
            connection:
                routing:
            """,
                ConnectionConfig(connection_type=ConnectionType.ROUTING),
            ),
        ]
        for yaml_string, expected_conn in test_configs:
            config = yaml.safe_load(yaml_string)
            Config(TestConfig.xknx).parse_connection(config)
            self.assertEqual(TestConfig.xknx.connection_config, expected_conn)
Exemplo n.º 4
0
 def test_config_invalid_connection(self):
     """Test invalid connection section from config file."""
     import yaml
     test_configs = [("""
         connection:
             tunneling:
                 local_ip: '192.168.1.2'
         """, XKNXException,
                      "`gateway_ip` is required for tunneling connection.")]
     for yaml_string, expected_exception, exception_message in test_configs:
         with self.assertRaises(expected_exception, msg=exception_message):
             config = yaml.safe_load(yaml_string)
             Config(TestConfig.xknx).parse_connection(config)
Exemplo n.º 5
0
Arquivo: xknx.py Projeto: jonppe/xknx
    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)
Exemplo n.º 6
0
Arquivo: xknx.py Projeto: cian/xknx
    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)