Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def test_process_power_status(self):
     """Test process / reading telegrams from telegram queue. Test if DPT20.105 controller mode is set correctly."""
     xknx = XKNX(loop=self.loop)
     climate = Climate(
         xknx,
         'TestClimate',
         group_address_on_off='1/2/2')
     telegram = Telegram(GroupAddress('1/2/2'))
     telegram.payload = DPTBinary(1)
     self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
     self.assertEqual(climate.is_on, True)
Ejemplo n.º 3
0
 def test_process_controller_mode(self):
     """Test process / reading telegrams from telegram queue. Test if DPT20.105 controller mode is set correctly."""
     xknx = XKNX(loop=self.loop)
     climate_mode = ClimateMode(
         xknx,
         'TestClimate',
         group_address_controller_mode='1/2/5')
     for _, operation_mode in DPTHVACContrMode.SUPPORTED_MODES.items():
         telegram = Telegram(GroupAddress('1/2/5'))
         telegram.payload = DPTArray(DPTHVACContrMode.to_knx(operation_mode))
         self.loop.run_until_complete(asyncio.Task(climate_mode.process(telegram)))
         self.assertEqual(climate_mode.operation_mode, operation_mode)
Ejemplo n.º 4
0
    def test_process_temperature(self):
        """Test process / reading telegrams from telegram queue. Test if temperature is processed correctly."""
        xknx = XKNX(loop=self.loop)
        climate = Climate(
            xknx,
            'TestClimate',
            group_address_temperature='1/2/3')

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.payload = DPTArray(DPTTemperature().to_knx(21.34))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        self.assertEqual(climate.temperature.value, 21.34)
Ejemplo n.º 5
0
    def test_process(self):
        """Test process / reading telegrams from telegram queue."""
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(
            xknx,
            'TestSensor',
            value_type='temperature',
            group_address_state='1/2/3')

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.payload = DPTArray((0x06, 0xa0))
        self.loop.run_until_complete(asyncio.Task(sensor.process(telegram)))
        self.assertEqual(sensor.sensor_value.payload, DPTArray((0x06, 0xa0)))
        self.assertEqual(sensor.resolve_state(), 16.96)
Ejemplo n.º 6
0
    def test_process_action(self):
        """Test process / reading telegrams from telegram queue. Test if action is executed."""
        xknx = XKNX(loop=self.loop)
        switch = Switch(xknx, 'TestOutlet', group_address='1/2/3')
        xknx.devices.add(switch)

        binary_sensor = BinarySensor(xknx, 'TestInput', group_address_state='1/2/3')
        action_on = Action(
            xknx,
            hook='on',
            target='TestOutlet',
            method='on')
        binary_sensor.actions.append(action_on)
        action_off = Action(
            xknx,
            hook='off',
            target='TestOutlet',
            method='off')
        binary_sensor.actions.append(action_off)
        xknx.devices.add(binary_sensor)

        self.assertEqual(
            xknx.devices['TestInput'].state,
            BinarySensorState.OFF)
        self.assertEqual(
            xknx.devices['TestOutlet'].state,
            False)

        telegram_on = Telegram()
        telegram_on.payload = DPTBinary(1)
        self.loop.run_until_complete(asyncio.Task(binary_sensor.process(telegram_on)))

        self.assertEqual(
            xknx.devices['TestInput'].state,
            BinarySensorState.ON)
        self.assertEqual(
            xknx.devices['TestOutlet'].state,
            True)

        telegram_off = Telegram()
        telegram_off.payload = DPTBinary(0)
        self.loop.run_until_complete(asyncio.Task(binary_sensor.process(telegram_off)))

        self.assertEqual(
            xknx.devices['TestInput'].state,
            BinarySensorState.OFF)
        self.assertEqual(
            xknx.devices['TestOutlet'].state,
            False)
Ejemplo n.º 7
0
    def test_process(self):
        """Test process / reading telegrams from telegram queue."""
        xknx = XKNX(loop=self.loop)
        binaryinput = BinarySensor(xknx, 'TestInput', '1/2/3')

        self.assertEqual(binaryinput.state, BinarySensorState.OFF)

        telegram_on = Telegram()
        telegram_on.payload = DPTBinary(1)
        self.loop.run_until_complete(asyncio.Task(binaryinput.process(telegram_on)))

        self.assertEqual(binaryinput.state, BinarySensorState.ON)

        telegram_off = Telegram()
        telegram_off.payload = DPTBinary(0)
        self.loop.run_until_complete(asyncio.Task(binaryinput.process(telegram_off)))
        self.assertEqual(binaryinput.state, BinarySensorState.OFF)
Ejemplo n.º 8
0
    def test_process_callback(self):
        """Test after_update_callback after state of switch was changed."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        switch = BinarySensor(xknx, 'TestInput', group_address_state='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.payload = DPTBinary(1)
        self.loop.run_until_complete(asyncio.Task(switch.process(telegram)))
        after_update_callback.assert_called_with(switch)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
 def test_cemi_frame(self):
     """Test string representation of KNX/IP CEMI Frame."""
     xknx = XKNX(loop=self.loop)
     cemi_frame = CEMIFrame(xknx)
     cemi_frame.src_addr = GroupAddress("1/2/3")
     cemi_frame.telegram = Telegram(group_address=GroupAddress('1/2/5'),
                                    payload=DPTBinary(7))
     self.assertEqual(
         str(cemi_frame),
         '<CEMIFrame SourceAddress="GroupAddress("1/2/3")" DestinationAddress="GroupAddress("1/2/5")" Flags="1011110011100000" Command="APCIC'
         'ommand.GROUP_WRITE" payload="<DPTBinary value="7" />" />')
Ejemplo n.º 11
0
    def test_process_percent(self):
        """Test reading percent expose sensor from bus."""
        xknx = XKNX(loop=self.loop)
        expose_sensor = ExposeSensor(xknx,
                                     'TestSensor',
                                     value_type='percent',
                                     group_address='1/2/3')
        expose_sensor.sensor_value.payload = DPTArray((0x40, ))

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.telegramtype = TelegramType.GROUP_READ
        self.loop.run_until_complete(
            asyncio.Task(expose_sensor.process(telegram)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram,
            Telegram(GroupAddress('1/2/3'),
                     TelegramType.GROUP_RESPONSE,
                     payload=DPTArray((0x40, ))))
Ejemplo n.º 12
0
 def test_process(self):
     """Test process telegram."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueUpDown(xknx,
                                      group_address=GroupAddress("1/2/3"))
     telegram = Telegram(group_address=GroupAddress("1/2/3"),
                         payload=DPTBinary(1))
     self.assertEqual(remote_value.value, None)
     self.loop.run_until_complete(
         asyncio.Task(remote_value.process(telegram)))
     self.assertEqual(remote_value.value, RemoteValueUpDown.Direction.DOWN)
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def test_process_operation_mode(self):
     """Test process / reading telegrams from telegram queue. Test if setpoint is processed correctly."""
     xknx = XKNX(loop=self.loop)
     climate_mode = ClimateMode(
         xknx,
         'TestClimate',
         group_address_operation_mode='1/2/5',
         group_address_controller_status='1/2/3')
     for operation_mode in DPT_20102_MODES:
         telegram = Telegram(GroupAddress('1/2/5'))
         telegram.payload = DPTArray(DPTHVACMode.to_knx(operation_mode))
         self.loop.run_until_complete(asyncio.Task(climate_mode.process(telegram)))
         self.assertEqual(climate_mode.operation_mode, operation_mode)
     for operation_mode in DPT_20102_MODES:
         if operation_mode == HVACOperationMode.AUTO:
             continue
         telegram = Telegram(GroupAddress('1/2/3'))
         telegram.payload = DPTArray(DPTControllerStatus.to_knx(operation_mode))
         self.loop.run_until_complete(asyncio.Task(climate_mode.process(telegram)))
         self.assertEqual(climate_mode.operation_mode, operation_mode)
Ejemplo n.º 16
0
    def test_process_callback_temp(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed when receiving temperature."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(
            xknx,
            'TestClimate',
            group_address_temperature='1/2/3')

        after_update_callback = Mock()

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

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.payload = DPTArray(DPTTemperature().to_knx(21.34))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
Ejemplo n.º 17
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
Ejemplo n.º 18
0
    def test_process_callback_updated_via_telegram(self):
        """Test if after_update_callback is called after update of Climate object."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(xknx,
                          'TestClimate',
                          group_address_temperature='1/2/1',
                          group_address_target_temperature='1/2/2',
                          group_address_setpoint_shift='1/2/3',
                          group_address_operation_mode='1/2/4')

        after_update_callback = Mock()

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

        climate.register_device_updated_cb(async_after_update_callback)

        telegram = Telegram(GroupAddress('1/2/1'),
                            payload=DPTArray(DPTTemperature.to_knx(23)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/2'),
                            payload=DPTArray(DPTTemperature.to_knx(23)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/3'),
                            payload=DPTArray(DPTValue1Count.to_knx(-4)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(1))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()
Ejemplo n.º 19
0
    def test_sync(self):
        """Test sync function / sending group reads to KNX bus."""
        xknx = XKNX(loop=self.loop)
        fan = Fan(xknx, name="TestFan", group_address_speed_state='1/2/3')
        self.loop.run_until_complete(asyncio.Task(fan.sync(False)))

        self.assertEqual(xknx.telegrams.qsize(), 1)

        telegram1 = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram1, Telegram(GroupAddress('1/2/3'),
                                TelegramType.GROUP_READ))
Ejemplo n.º 20
0
 def test_set(self):
     """Test setting value."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueColorRGB(xknx,
                                        group_address=GroupAddress("1/2/3"))
     self.loop.run_until_complete(
         asyncio.Task(remote_value.set((100, 101, 102))))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'),
                  payload=DPTArray((0x64, 0x65, 0x66))))
     self.loop.run_until_complete(
         asyncio.Task(remote_value.set((100, 101, 104))))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'),
                  payload=DPTArray((0x64, 0x65, 0x68))))
Ejemplo n.º 21
0
 def test_process_off(self):
     """Test process OFF telegram."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueSwitch(xknx,
                                      group_address=GroupAddress("1/2/3"))
     telegram = Telegram(group_address=GroupAddress("1/2/3"),
                         payload=DPTBinary(0))
     self.assertEqual(remote_value.value, None)
     self.loop.run_until_complete(
         asyncio.Task(remote_value.process(telegram)))
     self.assertIsNotNone(remote_value.payload)
     self.assertEqual(remote_value.value, False)
Ejemplo n.º 22
0
    def test_process_tunable_white(self):
        """Test process / reading telegrams from telegram queue. Test if tunable white is processed."""
        xknx = XKNX(loop=self.loop)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_tunable_white='1/2/5')
        self.assertEqual(light.current_tunable_white, None)

        telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray(23))
        self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
        self.assertEqual(light.current_tunable_white, 23)
Ejemplo n.º 23
0
    def test_process_color_temperature(self):
        """Test process / reading telegrams from telegram queue. Test if color temperature is processed."""
        xknx = XKNX(loop=self.loop)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_color_temperature='1/2/5')
        self.assertEqual(light.current_color_temperature, None)

        telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((0x0F, 0xA0, )))
        self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
        self.assertEqual(light.current_color_temperature, 4000)
Ejemplo n.º 24
0
 def test_set_color_temp(self):
     """Test setting the color temperature value of a Light."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color_temperature='1/2/5')
     self.loop.run_until_complete(asyncio.Task(light.set_color_temperature(4000)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/5'), payload=DPTArray((0x0F, 0xA0, ))))
Ejemplo n.º 25
0
 def test_process_color_rgbw(self):
     """Test process / reading telegrams from telegram queue. Test if RGBW is processed."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color='1/2/4',
                   group_address_rgbw='1/2/5')
     self.assertEqual(light.current_color, (None, None))
     telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((0, 15, 23, 24, 25, 26)))
     self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
     self.assertEqual(light.current_color, ([23, 24, 25], 26))
Ejemplo n.º 26
0
 def test_sync_state(self):
     """Test sync function / sending group reads to KNX bus."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(
         xknx,
         "Warning",
         group_address='1/2/3')
     self.loop.run_until_complete(asyncio.Task(notification.sync(False)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/3'), TelegramType.GROUP_READ))
Ejemplo n.º 27
0
 def test_set_tw(self):
     """Test setting the tunable white value of a Light."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_tunable_white='1/2/5')
     self.loop.run_until_complete(asyncio.Task(light.set_tunable_white(23)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/5'), payload=DPTArray(23)))
Ejemplo n.º 28
0
    def sync_state(self):
        if self.group_address_position_feedback is None:
            print("group_position not defined for device {0}" \
                .format(self.get_name()))
            return
        if self.travelcalculator.is_traveling():
            # Cover is traveling, requesting state will return false results
            return

        telegram = Telegram(self.group_address_position_feedback,
                            TelegramType.GROUP_READ)
        self.xknx.telegrams.put_nowait(telegram)
Ejemplo n.º 29
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
Ejemplo n.º 30
0
    def test_process_callback_temp(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed when receiving temperature."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(
            xknx,
            'TestClimate',
            group_address_temperature='1/2/3')

        after_update_callback = Mock()

        @asyncio.coroutine
        def async_after_update_callback(device):
            """Async callback."""
            after_update_callback(device)
        climate.register_device_updated_cb(async_after_update_callback)

        telegram = Telegram(Address('1/2/3'))
        telegram.payload = DPTArray(DPTTemperature().to_knx(21.34))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
Ejemplo n.º 31
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)
Ejemplo n.º 32
0
    def test_process_temperature(self):
        """Test reading temperature expose sensor from bus."""
        xknx = XKNX(loop=self.loop)
        expose_sensor = ExposeSensor(
            xknx,
            'TestSensor',
            value_type='temperature',
            group_address='1/2/3')
        expose_sensor.sensor_value.payload = DPTArray((0x0c, 0x1a))

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.telegramtype = TelegramType.GROUP_READ
        self.loop.run_until_complete(asyncio.Task(expose_sensor.process(telegram)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram,
            Telegram(
                GroupAddress('1/2/3'),
                TelegramType.GROUP_RESPONSE,
                payload=DPTArray((0x0c, 0x1a))))
Ejemplo n.º 33
0
 def test_set(self):
     """Test notificationing off notification."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     self.loop.run_until_complete(
         asyncio.Task(notification.set("Ein Prosit!")))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'),
                  payload=DPTArray(DPTString().to_knx("Ein Prosit!"))))
Ejemplo n.º 34
0
 def test_do(self):
     """Test running scene with do command."""
     xknx = XKNX(loop=self.loop)
     scene = Scene(xknx,
                   'TestScene',
                   group_address='1/2/1',
                   scene_number=23)
     self.loop.run_until_complete(asyncio.Task(scene.do("run")))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram, Telegram(GroupAddress('1/2/1'), payload=DPTArray(0x16)))
Ejemplo n.º 35
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)
Ejemplo n.º 36
0
 def test_set_brightness(self):
     xknx = XKNX(self.loop, start=False)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_dimm='1/2/4',
                   group_address_brightness='1/2/5')
     light.set_brightness(23)
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(Address('1/2/5'), payload=DPTArray(23)))
Ejemplo n.º 37
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is called."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(
            xknx,
            'TestSensor',
            group_address_state='1/2/3',
            value_type="temperature")

        after_update_callback = Mock()

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

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.payload = DPTArray((0x01, 0x02))
        self.loop.run_until_complete(asyncio.Task(sensor.process(telegram)))
        after_update_callback.assert_called_with(sensor)
Ejemplo n.º 38
0
    def test_sync(self):
        """Test sync function / sending group reads to KNX bus."""
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(xknx, 'TestSensor', group_address='1/2/3')

        self.loop.run_until_complete(asyncio.Task(sensor.sync(False)))

        self.assertEqual(xknx.telegrams.qsize(), 1)

        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(telegram,
                         Telegram(Address('1/2/3'), TelegramType.GROUP_READ))
Ejemplo n.º 39
0
    def test_process_dimm(self):
        xknx = XKNX(self.loop, start=False)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_dimm='1/2/4',
                      group_address_brightness='1/2/5')
        self.assertEqual(light.brightness, 0)

        telegram = Telegram(Address('1/2/5'), payload=DPTArray(23))
        light.process(telegram)
        self.assertEqual(light.brightness, 23)
Ejemplo n.º 40
0
    def test_process_dimm(self):
        """Test process / reading telegrams from telegram queue. Test if brightness is processed."""
        xknx = XKNX(loop=self.loop)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_brightness='1/2/5')
        self.assertEqual(light.brightness, 0)

        telegram = Telegram(Address('1/2/5'), payload=DPTArray(23))
        self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
        self.assertEqual(light.brightness, 23)
Ejemplo n.º 41
0
 def test_set_on(self):
     """Test switching on a Light."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_brightness='1/2/5')
     self.loop.run_until_complete(asyncio.Task(light.set_on()))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(Address('1/2/3'), payload=DPTBinary(1)))
Ejemplo n.º 42
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is called."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(
            xknx,
            'TestSensor',
            group_address='1/2/3',
            value_type="temperature")

        after_update_callback = Mock()

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

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.payload = DPTArray((0x01, 0x02))
        self.loop.run_until_complete(asyncio.Task(sensor.process(telegram)))
        after_update_callback.assert_called_with(sensor)
Ejemplo n.º 43
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)
Ejemplo n.º 44
0
 def test_process_angle(self):
     """Test process / reading telegrams from telegram queue. Test if position is processed correctly."""
     xknx = XKNX(loop=self.loop)
     cover = Cover(xknx,
                   'TestCover',
                   group_address_long='1/2/1',
                   group_address_short='1/2/2',
                   group_address_angle='1/2/3',
                   group_address_angle_state='1/2/4')
     telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(42))
     self.loop.run_until_complete(asyncio.Task(cover.process(telegram)))
     self.assertEqual(cover.current_angle(), 84)
Ejemplo n.º 45
0
 def test_sync(self):
     """Test sync function / sending group reads to KNX bus."""
     xknx = XKNX(loop=self.loop)
     climate = Climate(xknx,
                       'TestClimate',
                       group_address_temperature='1/2/3')
     self.loop.run_until_complete(asyncio.Task(climate.sync(False)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram1 = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram1, Telegram(GroupAddress('1/2/3'),
                             TelegramType.GROUP_READ))
Ejemplo n.º 46
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)
Ejemplo n.º 47
0
    def test_process_significant_bit(self):
        """Test process / reading telegrams from telegram queue with specific significant bit set."""
        xknx = XKNX(loop=self.loop)
        binaryinput = BinarySensor(xknx, 'TestInput', '1/2/3', significant_bit=3)

        self.assertEqual(binaryinput.state, BinarySensorState.OFF)

        # Wrong significant bit: 0000 1011 = 11
        telegram_on = Telegram()
        telegram_on.payload = DPTBinary(11)
        self.loop.run_until_complete(asyncio.Task(binaryinput.process(telegram_on)))
        self.assertEqual(binaryinput.state, BinarySensorState.OFF)

        # Correct significant bit: 0000 1101 = 13
        telegram_on = Telegram()
        telegram_on.payload = DPTBinary(13)
        self.loop.run_until_complete(asyncio.Task(binaryinput.process(telegram_on)))
        self.assertEqual(binaryinput.state, BinarySensorState.ON)

        # Resetting, significant bit: 0000 0011 = 3
        telegram_off = Telegram()
        telegram_off.payload = DPTBinary(3)
        self.loop.run_until_complete(asyncio.Task(binaryinput.process(telegram_off)))
        self.assertEqual(binaryinput.state, BinarySensorState.OFF)