Exemplo n.º 1
0
 def test_warn_payload_valid(self):
     """Test for warning if payload_valid is not implemented."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValue(xknx)
     with patch('logging.Logger.warning') as mock_warn:
         remote_value.payload_valid(DPTBinary(0))
         mock_warn.assert_called_with(
             'payload_valid not implemented for %s', 'RemoteValue')
Exemplo n.º 2
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, False)

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

        self.assertEqual(binaryinput.state, True)

        telegram_off = Telegram(group_address=GroupAddress('1/2/3'))
        telegram_off.payload = DPTBinary(0)
        self.loop.run_until_complete(asyncio.Task(binaryinput.process(telegram_off)))
        self.assertEqual(binaryinput.state, False)
Exemplo n.º 3
0
 def from_knx(self, payload):
     """Convert current payload to value."""
     if payload == DPTBinary(1):
         return self.controller_mode
     if payload == DPTBinary(0):
         # return the other operation mode
         return next(
             (_op for _op in self.supported_operation_modes()
              if _op is not self.controller_mode),
             None,
         )
     raise CouldNotParseTelegram(
         "payload invalid",
         payload=payload,
         device_name=self.device_name,
         feature_name=self.feature_name,
     )
Exemplo n.º 4
0
 def test_telegram(self):
     """Test string representation of Telegram."""
     telegram = Telegram(group_address=GroupAddress('1/2/3'),
                         payload=DPTBinary(7))
     self.assertEqual(
         str(telegram),
         '<Telegram group_address="GroupAddress("1/2/3")", payload="<DPTBinary value="7" />" telegramtype="TelegramType.GROUP_WRITE" direction='
         '"TelegramDirection.OUTGOING" />')
Exemplo n.º 5
0
    def test_process_invert(self):
        """Test process / reading telegrams from telegram queue."""
        xknx = XKNX()
        bs_invert = BinarySensor(xknx, "TestInput", "1/2/3", invert=True)

        self.assertEqual(bs_invert.state, None)

        telegram_on = Telegram(group_address=GroupAddress("1/2/3"),
                               payload=DPTBinary(0))
        self.loop.run_until_complete(bs_invert.process(telegram_on))

        self.assertEqual(bs_invert.state, True)

        telegram_off = Telegram(group_address=GroupAddress("1/2/3"),
                                payload=DPTBinary(1))
        self.loop.run_until_complete(bs_invert.process(telegram_off))
        self.assertEqual(bs_invert.state, False)
Exemplo n.º 6
0
    def test_process_invert(self):
        """Test process / reading telegrams from telegram queue with inverted switch."""
        xknx = XKNX()
        switch = Switch(xknx, "TestOutlet", group_address="1/2/3", invert=True)
        self.assertEqual(switch.state, False)

        telegram_on = Telegram(
            group_address=GroupAddress("1/2/3"), payload=DPTBinary(0)
        )
        self.loop.run_until_complete(switch.process(telegram_on))
        self.assertEqual(switch.state, True)

        telegram_off = Telegram(
            group_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
        )
        self.loop.run_until_complete(switch.process(telegram_off))
        self.assertEqual(switch.state, False)
Exemplo n.º 7
0
 def test_process_wrong_payload(self):
     """Test process wrong telegram (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(
             asyncio.Task(notification.process(telegram)))
Exemplo n.º 8
0
 def test_compare_array_binary(self):
     """Test comparison of empty DPTArray objects with DPTBinary objects."""
     assert DPTArray(()) != DPTBinary(0)
     assert DPTBinary(0) != DPTArray(())
     assert DPTBinary(0) != DPTArray(0)
     assert DPTBinary(1) != DPTArray(1)
     assert DPTArray((1, 2, 3)) != DPTBinary(2)
     assert DPTBinary(2) != DPTArray((1, 2, 3))
     assert DPTArray((2,)) != DPTBinary(2)
     assert DPTBinary(2) != DPTArray((2,))
Exemplo n.º 9
0
 def test_compare_array_binary(self):
     """Test comparison of empty DPTArray objects with DPTBinary objects."""
     self.assertNotEqual(DPTArray(()), DPTBinary(0))
     self.assertNotEqual(DPTBinary(0), DPTArray(()))
     self.assertNotEqual(DPTBinary(0), DPTArray(0))
     self.assertNotEqual(DPTBinary(1), DPTArray(1))
     self.assertNotEqual(DPTArray((1, 2, 3)), DPTBinary(2))
     self.assertNotEqual(DPTBinary(2), DPTArray((1, 2, 3)))
     self.assertNotEqual(DPTArray((2,)), DPTBinary(2))
     self.assertNotEqual(DPTBinary(2), DPTArray((2,)))
Exemplo n.º 10
0
    async def test_to_process_error(self):
        """Test process errornous telegram."""
        xknx = XKNX()
        rv_0 = RemoteValueRaw(xknx, payload_length=0, group_address="1/0/0")
        rv_1 = RemoteValueRaw(xknx, payload_length=1, group_address="1/1/1")
        rv_2 = RemoteValueRaw(xknx, payload_length=2, group_address="1/2/2")

        telegram = Telegram(
            destination_address=GroupAddress("1/0/0"),
            payload=GroupValueWrite(DPTArray((0x01, ))),
        )
        assert await rv_0.process(telegram) is False

        telegram = Telegram(
            destination_address=GroupAddress("1/0/0"),
            payload=GroupValueWrite(DPTArray((0x64, 0x65))),
        )
        assert await rv_0.process(telegram) is False
        assert rv_0.value is None

        telegram = Telegram(
            destination_address=GroupAddress("1/1/1"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        assert await rv_1.process(telegram) is False

        telegram = Telegram(
            destination_address=GroupAddress("1/1/1"),
            payload=GroupValueWrite(DPTArray((0x64, 0x65))),
        )
        assert await rv_1.process(telegram) is False
        assert rv_1.value is None

        telegram = Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        assert await rv_2.process(telegram) is False

        telegram = Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTArray((0x64, ))),
        )
        assert await rv_2.process(telegram) is False
        assert rv_2.value is None
Exemplo n.º 11
0
    async def test_to_process_error(self):
        """Test process errornous telegram."""
        xknx = XKNX()
        rv_0 = RemoteValueRaw(xknx, payload_length=0, group_address="1/0/0")
        rv_1 = RemoteValueRaw(xknx, payload_length=1, group_address="1/1/1")
        rv_2 = RemoteValueRaw(xknx, payload_length=2, group_address="1/2/2")

        with pytest.raises(CouldNotParseTelegram):
            telegram = Telegram(
                destination_address=GroupAddress("1/0/0"),
                payload=GroupValueWrite(DPTArray((0x01, ))),
            )
            await rv_0.process(telegram)
        with pytest.raises(CouldNotParseTelegram):
            telegram = Telegram(
                destination_address=GroupAddress("1/0/0"),
                payload=GroupValueWrite(DPTArray((0x64, 0x65))),
            )
            await rv_0.process(telegram)

        with pytest.raises(CouldNotParseTelegram):
            telegram = Telegram(
                destination_address=GroupAddress("1/1/1"),
                payload=GroupValueWrite(DPTBinary(1)),
            )
            await rv_1.process(telegram)
        with pytest.raises(CouldNotParseTelegram):
            telegram = Telegram(
                destination_address=GroupAddress("1/1/1"),
                payload=GroupValueWrite(DPTArray((0x64, 0x65))),
            )
            await rv_1.process(telegram)

        with pytest.raises(CouldNotParseTelegram):
            telegram = Telegram(
                destination_address=GroupAddress("1/2/2"),
                payload=GroupValueWrite(DPTBinary(1)),
            )
            await rv_2.process(telegram)
        with pytest.raises(CouldNotParseTelegram):
            telegram = Telegram(
                destination_address=GroupAddress("1/2/2"),
                payload=GroupValueWrite(DPTArray((0x64, ))),
            )
            await rv_2.process(telegram)
Exemplo n.º 12
0
 async def test_set(self):
     """Test setting value."""
     xknx = XKNX()
     remote_value = RemoteValueSwitch(xknx, group_address=GroupAddress("1/2/3"))
     await remote_value.on()
     assert xknx.telegrams.qsize() == 1
     telegram = xknx.telegrams.get_nowait()
     assert telegram == Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTBinary(1)),
     )
     await remote_value.off()
     assert xknx.telegrams.qsize() == 1
     telegram = xknx.telegrams.get_nowait()
     assert telegram == Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTBinary(0)),
     )
Exemplo n.º 13
0
 def test_warn_from_knx(self):
     """Test for warning if from_knx is not implemented."""
     xknx = XKNX()
     remote_value = RemoteValue(xknx)
     with patch("logging.Logger.warning") as mock_warn:
         remote_value.from_knx(DPTBinary(0))
         mock_warn.assert_called_with(
             "'from_knx()' not implemented for %s", "RemoteValue"
         )
Exemplo n.º 14
0
    def test_set_invert(self):
        """Test switching on/off inverted switch."""
        xknx = XKNX()
        switch = Switch(xknx, "TestOutlet", group_address="1/2/3", invert=True)

        self.loop.run_until_complete(switch.set_on())
        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram, Telegram(GroupAddress("1/2/3"), payload=DPTBinary(0))
        )

        self.loop.run_until_complete(switch.set_off())
        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram, Telegram(GroupAddress("1/2/3"), payload=DPTBinary(1))
        )
Exemplo n.º 15
0
 def test_set_off(self):
     """Test switching off switch."""
     xknx = XKNX(loop=self.loop)
     switch = Switch(xknx, 'TestOutlet', group_address='1/2/3')
     self.loop.run_until_complete(asyncio.Task(switch.set_off()))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/3'), payload=DPTBinary(0)))
Exemplo n.º 16
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)

        climate_inv = Climate(xknx,
                              'TestClimate',
                              group_address_on_off='1/2/2',
                              on_off_invert=True)
        telegram = Telegram(GroupAddress('1/2/2'))
        telegram.payload = DPTBinary(1)
        self.loop.run_until_complete(
            asyncio.Task(climate_inv.process(telegram)))
        self.assertEqual(climate_inv.is_on, False)
Exemplo n.º 17
0
 def to_knx(self, value):
     """Convert value to payload."""
     if isinstance(value, HVACOperationMode):
         # foreign operation modes will set the RemoteValue to False
         return DPTBinary(value == self.operation_mode)
     raise ConversionError("value invalid",
                           value=value,
                           device_name=self.device_name,
                           feature_name=self.feature_name)
Exemplo n.º 18
0
    def test_process_switch(self):
        """Test process / reading telegrams from telegram queue. Test if switch position is processed correctly."""
        xknx = XKNX()
        light = Light(
            xknx,
            name="TestLight",
            group_address_switch="1/2/3",
            group_address_brightness="1/2/5",
        )
        self.assertEqual(light.state, False)

        telegram = Telegram(GroupAddress("1/2/3"), payload=DPTBinary(1))
        self.loop.run_until_complete(light.process(telegram))
        self.assertEqual(light.state, True)

        telegram = Telegram(GroupAddress("1/2/3"), payload=DPTBinary(0))
        self.loop.run_until_complete(light.process(telegram))
        self.assertEqual(light.state, False)
Exemplo n.º 19
0
async def main():
    """Connect to a tunnel, send 2 telegrams and disconnect."""
    xknx = XKNX()
    gatewayscanner = GatewayScanner(xknx)
    gateways = await gatewayscanner.scan()

    if not gateways:
        print("No Gateways found")
        return

    gateway = gateways[0]
    # an individual address will most likely be assigned by the tunnelling server
    xknx.own_address = IndividualAddress("15.15.249")

    print(
        f"Connecting to {gateway.ip_addr}:{gateway.port} from {gateway.local_ip}"
    )

    tunnel = UDPTunnel(
        xknx,
        telegram_received_callback=received_callback,
        gateway_ip=gateway.ip_addr,
        gateway_port=gateway.port,
        local_ip=gateway.local_ip,
        local_port=0,
        route_back=False,
    )

    await tunnel.connect()

    await tunnel.send_telegram(
        Telegram(
            destination_address=GroupAddress("1/0/15"),
            payload=GroupValueWrite(DPTBinary(1)),
        ))
    await asyncio.sleep(2)
    await tunnel.send_telegram(
        Telegram(
            destination_address=GroupAddress("1/0/15"),
            payload=GroupValueWrite(DPTBinary(0)),
        ))
    await asyncio.sleep(2)

    await tunnel.disconnect()
Exemplo n.º 20
0
    async def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""

        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessCallback",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_stop="1/2/3",
            group_address_position="1/2/4",
            group_address_position_state="1/2/5",
            group_address_angle="1/2/6",
            group_address_angle_state="1/2/7",
        )

        after_update_callback = AsyncMock()

        cover.register_device_updated_cb(after_update_callback)
        for address, payload, _feature in [
            ("1/2/1", DPTBinary(1), "long"),
            ("1/2/2", DPTBinary(1), "short"),
            ("1/2/4", DPTArray(42), "position"),
            ("1/2/5", DPTArray(42), "position state"),
            ("1/2/6", DPTArray(42), "angle"),
            ("1/2/7", DPTArray(51), "angle state"),
        ]:
            telegram = Telegram(
                destination_address=GroupAddress(address),
                payload=GroupValueWrite(payload),
            )
            await cover.process(telegram)
            after_update_callback.assert_called_with(cover)
            after_update_callback.reset_mock()
        # Stop only when cover is travelling
        telegram = Telegram(GroupAddress("1/2/3"),
                            payload=GroupValueWrite(DPTBinary(1)))
        await cover.process(telegram)
        after_update_callback.assert_not_called()
        await cover.set_down()
        await cover.process(telegram)
        after_update_callback.assert_called_with(cover)

        await cover.stop()  # clean up tasks
Exemplo n.º 21
0
    def test_value_reader_telegram_received(self):
        """Test value reader: telegram_received."""
        xknx = XKNX()
        test_group_address = GroupAddress("0/0/0")
        expected_telegram_1 = Telegram(
            group_address=test_group_address,
            telegramtype=TelegramType.GROUP_RESPONSE,
            direction=TelegramDirection.INCOMING,
            payload=DPTBinary(1),
        )
        expected_telegram_2 = Telegram(
            group_address=test_group_address,
            telegramtype=TelegramType.GROUP_WRITE,
            direction=TelegramDirection.INCOMING,
            payload=DPTBinary(1),
        )
        telegram_wrong_address = Telegram(
            group_address=GroupAddress("0/0/1"),
            telegramtype=TelegramType.GROUP_RESPONSE,
            direction=TelegramDirection.INCOMING,
            payload=DPTBinary(1),
        )
        telegram_wrong_type = Telegram(
            group_address=test_group_address,
            telegramtype=TelegramType.GROUP_READ,
            direction=TelegramDirection.INCOMING,
            payload=DPTBinary(1),
        )

        value_reader = ValueReader(xknx, test_group_address)

        def async_telegram_received(test_telegram):
            return self.loop.run_until_complete(
                value_reader.telegram_received(test_telegram))

        self.assertFalse(async_telegram_received(telegram_wrong_address))
        self.assertFalse(async_telegram_received(telegram_wrong_type))
        self.assertIsNone(value_reader.received_telegram)

        self.assertTrue(async_telegram_received(expected_telegram_1))
        self.assertEqual(value_reader.received_telegram, expected_telegram_1)

        self.assertTrue(async_telegram_received(expected_telegram_2))
        self.assertEqual(value_reader.received_telegram, expected_telegram_2)
Exemplo n.º 22
0
    async def test_set_speed(self):
        """Test setting the speed of a Fan."""
        xknx = XKNX()
        fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
        await fan.set_speed(55)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # 140 is 55% as byte (0...255)
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(140)),
        )
        await fan.process(telegram)
        assert fan.is_on == True

        # A speed of 0 will turn off the fan implicitly if there is no
        # dedicated switch GA
        await fan.set_speed(0)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # 140 is 55% as byte (0...255)
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0)),
        )
        await fan.process(telegram)
        assert fan.is_on == False

        fan_with_switch = Fan(
            xknx,
            name="TestFan",
            group_address_speed="1/2/3",
            group_address_switch="4/5/6",
        )
        await fan_with_switch.turn_on()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("4/5/6"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        await fan_with_switch.process(telegram)
        assert fan_with_switch.is_on == True

        # A speed of 0 will not turn off the fan implicitly if there is a
        # dedicated switch GA defined. So we only expect a speed change telegram,
        # but no state switch one.
        await fan_with_switch.set_speed(0)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0)),
        )
        await fan_with_switch.process(telegram)
        assert fan_with_switch.is_on == True
Exemplo n.º 23
0
    def test_day_night(self):
        """Test day night mapping."""
        xknx = XKNX()
        weather: Weather = Weather(
            name="weather", xknx=xknx, group_address_day_night="1/3/20"
        )

        weather._day_night.payload = DPTBinary(0)

        self.assertEqual(weather.ha_current_state(), WeatherCondition.clear_night)
Exemplo n.º 24
0
    async def test_rate_limit(self, async_sleep_mock):
        """Test rate limit."""
        xknx = XKNX()
        xknx.rate_limit = 20  # 50 ms per outgoing telegram
        sleep_time = 0.05  # 1 / 20

        telegram_in = Telegram(
            direction=TelegramDirection.INCOMING,
            payload=GroupValueWrite(DPTBinary(1)),
        )

        telegram_out = Telegram(
            direction=TelegramDirection.OUTGOING,
            payload=GroupValueWrite(DPTBinary(1)),
        )
        telegram_internal = Telegram(
            direction=TelegramDirection.OUTGOING,
            payload=GroupValueWrite(DPTBinary(1)),
            destination_address=InternalGroupAddress("i-test"),
        )
        await xknx.telegram_queue.start()

        # no sleep for incoming telegrams
        xknx.telegrams.put_nowait(telegram_in)
        xknx.telegrams.put_nowait(telegram_in)
        await xknx.telegrams.join()
        assert async_sleep_mock.call_count == 0

        # sleep for outgoing telegrams
        xknx.telegrams.put_nowait(telegram_out)
        xknx.telegrams.put_nowait(telegram_out)
        await xknx.telegrams.join()
        assert async_sleep_mock.call_count == 2
        async_sleep_mock.assert_called_with(sleep_time)

        async_sleep_mock.reset_mock()
        # no sleep for internal group address telegrams
        xknx.telegrams.put_nowait(telegram_internal)
        xknx.telegrams.put_nowait(telegram_internal)
        await xknx.telegrams.join()
        async_sleep_mock.assert_not_called()

        await xknx.telegram_queue.stop()
Exemplo n.º 25
0
 def to_knx(self, value: bool):
     """Convert value to payload."""
     if isinstance(value, bool):
         return DPTBinary(value ^ self.invert)
     raise ConversionError(
         "value invalid",
         value=value,
         device_name=self.device_name,
         feature_name=self.feature_name,
     )
Exemplo n.º 26
0
 def test_process_speed_wrong_payload(self):  # pylint: disable=invalid-name
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTBinary(1)),
     )
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(fan.process(telegram))
Exemplo n.º 27
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""
        # pylint: disable=no-self-use
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCover",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_stop="1/2/3",
            group_address_position="1/2/4",
            group_address_position_state="1/2/5",
            group_address_angle="1/2/6",
            group_address_angle_state="1/2/7",
        )

        after_update_callback = Mock()

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

        cover.register_device_updated_cb(async_after_update_callback)
        for address, payload, feature in [
            ("1/2/1", DPTBinary(1), "long"),
            ("1/2/2", DPTBinary(1), "short"),
            ("1/2/4", DPTArray(42), "position"),
            ("1/2/5", DPTArray(42), "position state"),
            ("1/2/6", DPTArray(42), "angle"),
            ("1/2/7", DPTArray(51), "angle state"),
        ]:
            with self.subTest(address=address, feature=feature):
                telegram = Telegram(GroupAddress(address), payload=payload)
                self.loop.run_until_complete(cover.process(telegram))
                after_update_callback.assert_called_with(cover)
                after_update_callback.reset_mock()
        # Stop only when cover is travelling
        telegram = Telegram(GroupAddress("1/2/3"), payload=DPTBinary(1))
        self.loop.run_until_complete(cover.process(telegram))
        after_update_callback.assert_not_called()
        self.loop.run_until_complete(cover.set_down())
        self.loop.run_until_complete(cover.process(telegram))
        after_update_callback.assert_called_with(cover)
Exemplo n.º 28
0
 def test_process_color_temperature_wrong_payload(self):
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color_temperature='1/2/5')
     telegram = Telegram(GroupAddress('1/2/5'), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
Exemplo n.º 29
0
    def test_str_binary(self):
        """Test resolve state with binary sensor."""
        xknx = XKNX()
        expose_sensor = ExposeSensor(
            xknx, "TestSensor", group_address="1/2/3", value_type="binary"
        )
        expose_sensor.sensor_value.payload = DPTBinary(1)

        self.assertEqual(expose_sensor.resolve_state(), True)
        self.assertEqual(expose_sensor.unit_of_measurement(), None)
Exemplo n.º 30
0
    def test_process_binary(self):
        """Test reading binary expose sensor from bus."""
        xknx = XKNX()
        expose_sensor = ExposeSensor(
            xknx, "TestSensor", value_type="binary", group_address="1/2/3"
        )
        expose_sensor.sensor_value.payload = DPTBinary(1)

        telegram = Telegram(GroupAddress("1/2/3"), payload=GroupValueRead())
        self.loop.run_until_complete(expose_sensor.process(telegram))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram,
            Telegram(
                destination_address=GroupAddress("1/2/3"),
                payload=GroupValueResponse(DPTBinary(True)),
            ),
        )