示例#1
0
    def test_telegram_set(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet with DPTArray/DPTTime as payload."""
        xknx = XKNX(loop=self.loop)
        knxipframe = KNXIPFrame(xknx)
        knxipframe.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe.body.src_addr = PhysicalAddress("1.2.2")

        telegram = Telegram()
        telegram.group_address = GroupAddress(337)

        telegram.payload = DPTArray(DPTTime().to_knx({
            'hours': 13,
            'minutes': 23,
            'seconds': 42
        }))

        knxipframe.body.telegram = telegram

        knxipframe.body.set_hops(5)
        knxipframe.normalize()

        raw = ((0x06, 0x10, 0x05, 0x30, 0x00, 0x14, 0x29, 0x00, 0xbc, 0xd0,
                0x12, 0x02, 0x01, 0x51, 0x04, 0x00, 0x80, 13, 23, 42))

        self.assertEqual(knxipframe.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe.to_knx(), list(raw))
示例#2
0
 async def send(self, response=False):
     """Send payload as telegram to KNX bus."""
     telegram = Telegram()
     telegram.group_address = self.group_address
     telegram.telegramtype = TelegramType.GROUP_RESPONSE \
         if response else TelegramType.GROUP_WRITE
     telegram.payload = self.payload
     await self.xknx.telegrams.put(telegram)
示例#3
0
 async def send(self, response=False):
     """Send payload as telegram to KNX bus."""
     telegram = Telegram()
     telegram.group_address = self.group_address
     telegram.telegramtype = TelegramType.GROUP_RESPONSE \
         if response else TelegramType.GROUP_WRITE
     telegram.payload = self.payload
     await self.xknx.telegrams.put(telegram)
示例#4
0
文件: switch_test.py 项目: rnixx/xknx
    def test_process(self):
        """Test process / reading telegrams from telegram queue. Test if device was updated."""
        xknx = XKNX(loop=self.loop)
        switch = Switch(xknx, 'TestOutlet', group_address='1/2/3')

        self.assertEqual(switch.state, False)

        telegram_on = Telegram()
        telegram_on.group_address = GroupAddress('1/2/3')
        telegram_on.payload = DPTBinary(1)
        self.loop.run_until_complete(asyncio.Task(switch.process(telegram_on)))

        self.assertEqual(switch.state, True)

        telegram_off = Telegram()
        telegram_off.group_address = GroupAddress('1/2/3')
        telegram_off.payload = DPTBinary(0)
        self.loop.run_until_complete(asyncio.Task(switch.process(telegram_off)))

        self.assertEqual(switch.state, False)
示例#5
0
    def test_process(self):
        """Test process / reading telegrams from telegram queue. Test if device was updated."""
        xknx = XKNX(loop=self.loop)
        switch = Switch(xknx, 'TestOutlet', group_address='1/2/3')

        self.assertEqual(switch.state, False)

        telegram_on = Telegram()
        telegram_on.group_address = GroupAddress('1/2/3')
        telegram_on.payload = DPTBinary(1)
        self.loop.run_until_complete(asyncio.Task(switch.process(telegram_on)))

        self.assertEqual(switch.state, True)

        telegram_off = Telegram()
        telegram_off.group_address = GroupAddress('1/2/3')
        telegram_off.payload = DPTBinary(0)
        self.loop.run_until_complete(asyncio.Task(switch.process(telegram_off)))

        self.assertEqual(switch.state, False)
示例#6
0
    async def service_send_to_knx_bus(self, call):
        """Service for sending an arbitrary KNX message to the KNX bus."""
        from xknx.knx import Telegram, GroupAddress, DPTBinary, DPTArray
        attr_payload = call.data.get(SERVICE_KNX_ATTR_PAYLOAD)
        attr_address = call.data.get(SERVICE_KNX_ATTR_ADDRESS)

        def calculate_payload(attr_payload):
            """Calculate payload depending on type of attribute."""
            if isinstance(attr_payload, int):
                return DPTBinary(attr_payload)
            return DPTArray(attr_payload)
        payload = calculate_payload(attr_payload)
        address = GroupAddress(attr_address)

        telegram = Telegram()
        telegram.payload = payload
        telegram.group_address = address
        await self.xknx.telegrams.put(telegram)
示例#7
0
文件: knx.py 项目: gbeine/knx2mqtt
	def publish(self, group_address, payload):
		logging.debug("Try to publish payload {0} for group address {1}".format(payload, group_address))
		telegram = Telegram(direction=TelegramDirection.OUTGOING)
		telegram.group_address = group_address
		telegram.telegramtype = TelegramType.GROUP_WRITE
		telegram.payload = payload

		logging.debug(telegram)

		if self._xknx.started:
#			loop = asyncio.new_event_loop()
#			asyncio.set_event_loop(loop)
#			loop.run_until_complete(self._xknx.telegrams.put(telegram))
			asyncio.run(self._xknx.telegrams.put(telegram))
#			loop.run_until_complete(self._xknx.telegram_queue.process_telegram_outgoing(telegram))
#			asyncio.run(self._xknx.telegram_queue.process_telegram_outgoing(telegram))
			logging.info("Sent")
		else:
			logging.info("XKNX not started")
示例#8
0
    def telegram(self):
        """Return telegram."""
        telegram = Telegram()
        telegram.payload = self.payload
        telegram.group_address = self.dst_addr

        def resolve_telegram_type(cmd):
            """Return telegram type from APCI Command."""
            if cmd == APCICommand.GROUP_WRITE:
                return TelegramType.GROUP_WRITE
            if cmd == APCICommand.GROUP_READ:
                return TelegramType.GROUP_READ
            if cmd == APCICommand.GROUP_RESPONSE:
                return TelegramType.GROUP_RESPONSE
            raise ConversionError("Telegram not implemented for {0}".format(self.cmd))

        telegram.telegramtype = resolve_telegram_type(self.cmd)

        # TODO: Set telegram.direction [additional flag within KNXIP]
        return telegram
示例#9
0
文件: switch_test.py 项目: rnixx/xknx
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback was called."""
        # pylint: disable=no-self-use

        xknx = XKNX(loop=self.loop)
        switch = Switch(xknx, 'TestOutlet', group_address='1/2/3')

        after_update_callback = Mock()

        async def async_after_update_callback(device):
            """Async callback."""
            after_update_callback(device)
        switch.register_device_updated_cb(async_after_update_callback)

        telegram = Telegram()
        telegram.group_address = GroupAddress('1/2/3')
        telegram.payload = DPTBinary(1)
        self.loop.run_until_complete(asyncio.Task(switch.process(telegram)))

        after_update_callback.assert_called_with(switch)
示例#10
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback was called."""
        # pylint: disable=no-self-use

        xknx = XKNX(loop=self.loop)
        switch = Switch(xknx, 'TestOutlet', group_address='1/2/3')

        after_update_callback = Mock()

        async def async_after_update_callback(device):
            """Async callback."""
            after_update_callback(device)
        switch.register_device_updated_cb(async_after_update_callback)

        telegram = Telegram()
        telegram.group_address = GroupAddress('1/2/3')
        telegram.payload = DPTBinary(1)
        self.loop.run_until_complete(asyncio.Task(switch.process(telegram)))

        after_update_callback.assert_called_with(switch)
示例#11
0
文件: cemi_frame.py 项目: phbaer/xknx
    def telegram(self):
        """Return telegram."""
        telegram = Telegram()
        telegram.payload = self.payload
        telegram.group_address = self.dst_addr

        def resolve_telegram_type(cmd):
            """Return telegram type from APCI Command."""
            if cmd == APCICommand.GROUP_WRITE:
                return TelegramType.GROUP_WRITE
            if cmd == APCICommand.GROUP_READ:
                return TelegramType.GROUP_READ
            if cmd == APCICommand.GROUP_RESPONSE:
                return TelegramType.GROUP_RESPONSE
            raise ConversionError("Telegram not implemented for {0}".format(self.cmd))

        telegram.telegramtype = resolve_telegram_type(self.cmd)

        # TODO: Set telegram.direction [additional flag within KNXIP]
        return telegram
示例#12
0
    def telegram(self):
        telegram = Telegram()
        telegram.payload = self.payload
        telegram.group_address = self.dst_addr

        def resolve_telegram_type(cmd):
            if cmd == APCICommand.GROUP_WRITE:
                return TelegramType.GROUP_WRITE
            elif cmd == APCICommand.GROUP_READ:
                return TelegramType.GROUP_READ
            elif cmd == APCICommand.GROUP_RESPONSE:
                return TelegramType.GROUP_RESPONSE
            else:
                raise ConversionException("Telegram not implemented for {0}" \
                                      .format(self.cmd))

        telegram.telegramtype = resolve_telegram_type(self.cmd)

        # TODO: Set telegram.direction [additional flag within KNXIP]
        return telegram
示例#13
0
    def test_maximum_apci(self):
        telegram = Telegram()
        telegram.group_address = Address(337)
        telegram.payload = DPTBinary(DPTBinary.APCI_MAX_VALUE)

        knxipframe = KNXIPFrame()
        knxipframe.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe.body.src_addr = Address("1.3.1")
        knxipframe.body.telegram = telegram
        knxipframe.body.set_hops(5)
        knxipframe.normalize()

        raw = ((0x06, 0x10, 0x05, 0x30, 0x00, 0x11, 0x29, 0x00,
                0xbc, 0xd0, 0x13, 0x01, 0x01, 0x51, 0x01, 0x00,
                0xbf))
        self.assertEqual(knxipframe.to_knx(), list(raw))

        knxipframe2 = KNXIPFrame()
        knxipframe2.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe2.from_knx(knxipframe.to_knx())
        self.assertEqual(knxipframe2.body.telegram, telegram)
示例#14
0
    def test_maximum_apci(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, testing maximum APCI."""
        telegram = Telegram()
        telegram.group_address = GroupAddress(337)
        telegram.payload = DPTBinary(DPTBinary.APCI_MAX_VALUE)
        xknx = XKNX(loop=self.loop)
        knxipframe = KNXIPFrame(xknx)
        knxipframe.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe.body.src_addr = PhysicalAddress("1.3.1")
        knxipframe.body.telegram = telegram
        knxipframe.body.set_hops(5)
        knxipframe.normalize()

        raw = ((0x06, 0x10, 0x05, 0x30, 0x00, 0x11, 0x29, 0x00, 0xbc, 0xd0,
                0x13, 0x01, 0x01, 0x51, 0x01, 0x00, 0xbf))
        self.assertEqual(knxipframe.to_knx(), list(raw))

        knxipframe2 = KNXIPFrame(xknx)
        knxipframe2.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe2.from_knx(knxipframe.to_knx())
        self.assertEqual(knxipframe2.body.telegram, telegram)
示例#15
0
    def test_telegram_set(self):
        knxipframe = KNXIPFrame()
        knxipframe.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe.body.src_addr = Address("1.2.2")

        telegram = Telegram()
        telegram.group_address = Address(337)

        telegram.payload = DPTArray(DPTTime().to_knx(
            {'hours': 13, 'minutes': 23, 'seconds': 42}))

        knxipframe.body.telegram = telegram

        knxipframe.body.set_hops(5)
        knxipframe.normalize()

        raw = ((0x06, 0x10, 0x05, 0x30, 0x00, 0x14, 0x29, 0x00,
                0xbc, 0xd0, 0x12, 0x02, 0x01, 0x51, 0x04, 0x00,
                0x80, 13, 23, 42))

        self.assertEqual(knxipframe.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe.to_knx(), list(raw))
示例#16
0
 def send(self, group_address, payload):
     telegram = Telegram()
     telegram.group_address = group_address
     telegram.payload = payload
     self.xknx.telegrams.put_nowait(telegram)
示例#17
0
 def send(self, group_address, payload=None):
     """Send payload as telegram to KNX bus."""
     telegram = Telegram()
     telegram.group_address = group_address
     telegram.payload = payload
     yield from self.xknx.telegrams.put(telegram)
示例#18
0
 def broadcast_time(self):
     telegram = Telegram()
     telegram.group_address = self.group_address
     telegram.payload = DPTArray(DPTTime.current_time_as_knx())
     self.xknx.telegrams.put_nowait(telegram)