Exemplo n.º 1
0
 def test_from_knx(self):
     """Test from_knx function with normal operation."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx)
     self.assertEqual(
         remote_value.from_knx(
             DPTArray(
                 (
                     0x4B,
                     0x4E,
                     0x58,
                     0x20,
                     0x69,
                     0x73,
                     0x20,
                     0x4F,
                     0x4B,
                     0x00,
                     0x00,
                     0x00,
                     0x00,
                     0x00,
                 )
             )
         ),
         "KNX is OK",
     )
Exemplo n.º 2
0
 def test_process(self):
     """Test process telegram."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx,
                                      group_address=GroupAddress("1/2/3"))
     telegram = Telegram(
         group_address=GroupAddress("1/2/3"),
         payload=DPTArray((
             0x41,
             0x41,
             0x41,
             0x41,
             0x41,
             0x42,
             0x42,
             0x42,
             0x42,
             0x42,
             0x43,
             0x43,
             0x43,
             0x43,
         )),
     )
     self.loop.run_until_complete(remote_value.process(telegram))
     self.assertEqual(remote_value.value, "AAAAABBBBBCCCC")
Exemplo n.º 3
0
 def test_set(self):
     """Test setting value."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx,
                                      group_address=GroupAddress("1/2/3"))
     self.loop.run_until_complete(remote_value.set("asdf"))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(
             GroupAddress("1/2/3"),
             payload=DPTArray(
                 (97, 115, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
         ),
     )
     self.loop.run_until_complete(remote_value.set("ASDF"))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(
             GroupAddress("1/2/3"),
             payload=DPTArray(
                 (65, 83, 68, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
         ),
     )
Exemplo n.º 4
0
 def test_to_knx(self):
     """Test to_knx function with normal operation."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueString(xknx)
     self.assertEqual(
         remote_value.to_knx("KNX is OK"),
         DPTArray((0x4B, 0x4E, 0x58, 0x20, 0x69, 0x73, 0x20, 0x4F, 0x4B,
                   0x00, 0x00, 0x00, 0x00, 0x00)))
Exemplo n.º 5
0
    def test_to_knx(self):
        """Test to_knx function with normal operation."""
        xknx = XKNX()
        dpt_array_string = DPTArray((
            0x4B,
            0x4E,
            0x58,
            0x20,
            0x69,
            0x73,
            0x20,
            0x4F,
            0x4B,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
        ))
        remote_value_default = RemoteValueString(xknx)
        assert remote_value_default.dpt_class == DPTString
        assert remote_value_default.to_knx("KNX is OK") == dpt_array_string

        remote_value_ascii = RemoteValueString(xknx, value_type="string")
        assert remote_value_ascii.dpt_class == DPTString
        assert remote_value_ascii.to_knx("KNX is OK") == dpt_array_string

        remote_value_latin1 = RemoteValueString(xknx, value_type="latin_1")
        assert remote_value_latin1.dpt_class == DPTLatin1
        assert remote_value_latin1.to_knx("KNX is OK") == dpt_array_string
Exemplo n.º 6
0
    def __init__(self,
                 xknx,
                 name,
                 group_address=None,
                 group_address_state=None,
                 device_updated_cb=None):
        """Initialize notification class."""
        # pylint: disable=too-many-arguments
        super().__init__(xknx, name, device_updated_cb)

        self._message = RemoteValueString(
            xknx,
            group_address=group_address,
            group_address_state=group_address_state,
            device_name=name,
            after_update_cb=self.after_update)
Exemplo n.º 7
0
 async def test_process(self):
     """Test process telegram."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx,
                                      group_address=GroupAddress("1/2/3"))
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(
             DPTArray((
                 0x41,
                 0x41,
                 0x41,
                 0x41,
                 0x41,
                 0x42,
                 0x42,
                 0x42,
                 0x42,
                 0x42,
                 0x43,
                 0x43,
                 0x43,
                 0x43,
             ))),
     )
     await remote_value.process(telegram)
     assert remote_value.value == "AAAAABBBBBCCCC"
Exemplo n.º 8
0
 def test_to_process_error(self):
     """Test process errornous telegram."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx,
                                      group_address=GroupAddress("1/2/3"))
     with self.assertRaises(CouldNotParseTelegram):
         telegram = Telegram(group_address=GroupAddress("1/2/3"),
                             payload=DPTBinary(1))
         self.loop.run_until_complete(remote_value.process(telegram))
     with self.assertRaises(CouldNotParseTelegram):
         telegram = Telegram(
             group_address=GroupAddress("1/2/3"),
             payload=DPTArray((
                 0x64,
                 0x65,
             )),
         )
         self.loop.run_until_complete(remote_value.process(telegram))
Exemplo n.º 9
0
    def __init__(
        self,
        xknx: XKNX,
        name: str,
        group_address: GroupAddressesType | None = None,
        group_address_state: GroupAddressesType | None = None,
        device_updated_cb: DeviceCallbackType | None = None,
    ):
        """Initialize notification class."""
        super().__init__(xknx, name, device_updated_cb)

        self._message = RemoteValueString(
            xknx,
            group_address=group_address,
            group_address_state=group_address_state,
            device_name=name,
            feature_name="Message",
            after_update_cb=self.after_update,
        )
Exemplo n.º 10
0
 def test_to_knx(self):
     """Test to_knx function with normal operation."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx)
     assert remote_value.to_knx("KNX is OK") == DPTArray((
         0x4B,
         0x4E,
         0x58,
         0x20,
         0x69,
         0x73,
         0x20,
         0x4F,
         0x4B,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
     ))
Exemplo n.º 11
0
    def __init__(
        self,
        xknx: "XKNX",
        name: str,
        group_address: Optional["GroupAddressableType"] = None,
        group_address_state: Optional["GroupAddressableType"] = None,
        device_updated_cb: Optional[DeviceCallbackType] = None,
    ):
        """Initialize notification class."""
        # pylint: disable=too-many-arguments
        super().__init__(xknx, name, device_updated_cb)

        self._message = RemoteValueString(
            xknx,
            group_address=group_address,
            group_address_state=group_address_state,
            device_name=name,
            feature_name="Message",
            after_update_cb=self.after_update,
        )
Exemplo n.º 12
0
 async def test_to_process_error(self):
     """Test process errornous telegram."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx,
                                      group_address=GroupAddress("1/2/3"))
     with pytest.raises(CouldNotParseTelegram):
         telegram = Telegram(
             destination_address=GroupAddress("1/2/3"),
             payload=GroupValueWrite(DPTBinary(1)),
         )
         await remote_value.process(telegram)
     with pytest.raises(CouldNotParseTelegram):
         telegram = Telegram(
             destination_address=GroupAddress("1/2/3"),
             payload=GroupValueWrite(DPTArray((0x64, 0x65))),
         )
         await remote_value.process(telegram)
Exemplo n.º 13
0
class Notification(Device):
    """Class for managing a notification."""
    def __init__(
        self,
        xknx: XKNX,
        name: str,
        group_address: GroupAddressesType | None = None,
        group_address_state: GroupAddressesType | None = None,
        device_updated_cb: DeviceCallbackType | None = None,
    ):
        """Initialize notification class."""
        super().__init__(xknx, name, device_updated_cb)

        self._message = RemoteValueString(
            xknx,
            group_address=group_address,
            group_address_state=group_address_state,
            device_name=name,
            feature_name="Message",
            after_update_cb=self.after_update,
        )

    def _iter_remote_values(self) -> Iterator[RemoteValueString]:
        """Iterate the devices RemoteValue classes."""
        yield self._message

    @property
    def message(self) -> str | None:
        """Return the current message."""
        return self._message.value

    async def set(self, message: str) -> None:
        """Set message."""
        cropped_message = message[:14]
        await self._message.set(cropped_message)

    async def process_group_write(self, telegram: "Telegram") -> None:
        """Process incoming and outgoing GROUP WRITE telegram."""
        await self._message.process(telegram)

    def __str__(self) -> str:
        """Return object as readable string."""
        return '<Notification name="{}" message={} />'.format(
            self.name, self._message.group_addr_str())
Exemplo n.º 14
0
    async def test_to_process_error(self):
        """Test process errornous telegram."""
        xknx = XKNX()
        remote_value = RemoteValueString(xknx,
                                         group_address=GroupAddress("1/2/3"))

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

        telegram = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray((0x64, 0x65))),
        )
        assert await remote_value.process(telegram) is False

        assert remote_value.value is None
Exemplo n.º 15
0
 async def test_set(self):
     """Test setting value."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx,
                                      group_address=GroupAddress("1/2/3"))
     await remote_value.set("asdf")
     assert xknx.telegrams.qsize() == 1
     telegram = xknx.telegrams.get_nowait()
     assert telegram == Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(
             DPTArray((97, 115, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))),
     )
     await remote_value.set("ASDF")
     assert xknx.telegrams.qsize() == 1
     telegram = xknx.telegrams.get_nowait()
     assert telegram == Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(
             DPTArray((65, 83, 68, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))),
     )
Exemplo n.º 16
0
class Notification(Device):
    """Class for managing a notification."""
    def __init__(
        self,
        xknx: "XKNX",
        name: str,
        group_address: Optional["GroupAddressableType"] = None,
        group_address_state: Optional["GroupAddressableType"] = None,
        device_updated_cb: Optional[DeviceCallbackType] = None,
    ):
        """Initialize notification class."""
        # pylint: disable=too-many-arguments
        super().__init__(xknx, name, device_updated_cb)

        self._message = RemoteValueString(
            xknx,
            group_address=group_address,
            group_address_state=group_address_state,
            device_name=name,
            feature_name="Message",
            after_update_cb=self.after_update,
        )

    def _iter_remote_values(self) -> Iterator[RemoteValueString]:
        """Iterate the devices RemoteValue classes."""
        yield self._message

    @classmethod
    def from_config(cls, xknx: "XKNX", name: str,
                    config: Any) -> "Notification":
        """Initialize object from configuration structure."""
        group_address = config.get("group_address")
        group_address_state = config.get("group_address_state")

        return cls(
            xknx,
            name,
            group_address=group_address,
            group_address_state=group_address_state,
        )

    @property
    def message(self) -> Optional[str]:
        """Return the current message."""
        return self._message.value  # type: ignore

    async def set(self, message: str) -> None:
        """Set message."""
        cropped_message = message[:14]
        await self._message.set(cropped_message)

    async def process_group_write(self, telegram: "Telegram") -> None:
        """Process incoming and outgoing GROUP WRITE telegram."""
        await self._message.process(telegram)

    async def do(self, action: str) -> None:
        """Execute 'do' commands."""
        if action.startswith("message:"):
            await self.set(action[8:])
        else:
            logger.warning("Could not understand action %s for device %s",
                           action, self.get_name())

    def __str__(self) -> str:
        """Return object as readable string."""
        return '<Notification name="{}" message="{}" />'.format(
            self.name, self._message.group_addr_str())
Exemplo n.º 17
0
 def test_to_knx_error(self):
     """Test to_knx function with wrong parametern."""
     xknx = XKNX()
     remote_value = RemoteValueString(xknx)
     with self.assertRaises(ConversionError):
         remote_value.to_knx("123456789012345")
Exemplo n.º 18
0
class Notification(Device):
    """Class for managing a notification."""
    def __init__(self,
                 xknx,
                 name,
                 group_address=None,
                 group_address_state=None,
                 device_updated_cb=None):
        """Initialize notification class."""
        # pylint: disable=too-many-arguments
        super().__init__(xknx, name, device_updated_cb)

        self._message = RemoteValueString(
            xknx,
            group_address=group_address,
            group_address_state=group_address_state,
            device_name=name,
            feature_name="Message",
            after_update_cb=self.after_update)

    def _iter_remote_values(self):
        """Iterate the devices RemoteValue classes."""
        yield self._message

    @classmethod
    def from_config(cls, xknx, name, config):
        """Initialize object from configuration structure."""
        group_address = \
            config.get('group_address')
        group_address_state = \
            config.get('group_address_state')

        return cls(xknx,
                   name,
                   group_address=group_address,
                   group_address_state=group_address_state)

    @property
    def message(self):
        """Return the current message."""
        return self._message.value

    async def set(self, message):
        """Set message."""
        cropped_message = message[:14]
        await self._message.set(cropped_message)

    async def process_group_write(self, telegram):
        """Process incoming GROUP WRITE telegram."""
        await self._message.process(telegram)

    async def do(self, action):
        """Execute 'do' commands."""
        if action.startswith("message:"):
            await self.set(action[8:])
        else:
            self.xknx.logger.warning(
                "Could not understand action %s for device %s", action,
                self.get_name())

    def __str__(self):
        """Return object as readable string."""
        return '<Notification name="{0}" message="{1}" />' \
            .format(self.name,
                    self._message.group_addr_str())

    def __eq__(self, other):
        """Equal operator."""
        return self.__dict__ == other.__dict__