Exemplo n.º 1
0
 async def turn_off(self) -> None:
     """
     Send the turn off message
     """
     cls = commandRegistry.get_command(0x01, self._module.get_type())
     msg = cls(self._address)
     msg.relay_channels = [self._num]
     await self._writer(msg)
Exemplo n.º 2
0
 async def set_mode(self, mode) -> None:
     if mode == "heat":
         code = 0xE0
     elif mode == "cool":
         code = 0xDF
     cls = commandRegistry.get_command(code, self._module.get_type())
     msg = cls(self._address)
     await self._writer(msg)
Exemplo n.º 3
0
 async def restore_dimmer_state(self, transitiontime=0) -> None:
     """
     restore dimmer to last known state
     """
     cls = commandRegistry.get_command(0x11, self._module.get_type())
     msg = cls(self._address)
     msg.dimmer_transitiontime = int(transitiontime)
     msg.dimmer_channels = [self._num]
     await self._writer(msg)
Exemplo n.º 4
0
 async def set_dimmer_state(self, slider, transitiontime=0) -> None:
     """
     Set dimmer to slider
     """
     cls = commandRegistry.get_command(0x07, self._module.get_type())
     msg = cls(self._address)
     msg.dimmer_state = slider
     msg.dimmer_transitiontime = int(transitiontime)
     msg.dimmer_channels = [self._num]
     await self._writer(msg)
Exemplo n.º 5
0
    async def handle(self, rawmsg: RawMessage) -> None:
        """
        Handle a received packet
        """
        if rawmsg.address < 1 or rawmsg.address > 254:
            return
        if rawmsg.command is None:
            return

        priority = rawmsg.priority
        address = rawmsg.address
        rtr = rawmsg.rtr
        command_value = rawmsg.command
        data = rawmsg.data_only

        if command_value == 0xFF and not self._scan_complete:
            msg = ModuleTypeMessage()
            msg.populate(priority, address, rtr, data)
            self._log.debug(f"Received {msg}")
            await self._handle_module_type(msg)
        elif command_value == 0xB0 and not self._scan_complete:
            msg = ModuleSubTypeMessage()
            msg.populate(priority, address, rtr, data)
            self._log.debug(f"Received {msg}")
            await self._handle_module_subtype(msg)
        elif command_value in self.pdata["MessagesBroadCast"]:
            self._log.debug(
                "Received broadcast message {} from {}, ignoring".format(
                    self.pdata["MessageBroadCast"][command_value.upper()],
                    address))
        elif address in self._velbus.get_modules().keys():
            module_type = self._velbus.get_module(address).get_type()
            if commandRegistry.has_command(int(command_value), module_type):
                command = commandRegistry.get_command(command_value,
                                                      module_type)
                msg = command()
                msg.populate(priority, address, rtr, data)
                self._log.debug(f"Received {msg}")
                # send the message to the modules
                await (self._velbus.get_module(msg.address)).on_message(msg)
            else:
                self._log.warning(
                    "NOT FOUND IN command_registry: addr={} cmd={} packet={}".
                    format(address, command_value,
                           ":".join(format(x, "02x") for x in data)))
        elif self._scan_complete:
            # this should only happen once the scan is complete, of its not complete suspended the error message
            self._log.warning(
                "UNKNOWN module, you should initialize a full new velbus scan: packet={}, address={}, modules={}"
                .format(
                    ":".join(format(x, "02x") for x in data),
                    address,
                    self._velbus.get_modules().keys(),
                ))
Exemplo n.º 6
0
 async def set(self, txt: str) -> None:
     cls = commandRegistry.get_command(0xAC, self._module.get_type())
     msg = cls(self._address)
     msgcntr = 0
     for char in txt:
         msg.memo_text += char
         if len(msg.memo_text) >= 5:
             msgcntr += 5
             await self._writer(msg)
             msg = cls(self._address)
             msg.start = msgcntr
     await self._writer(msg)
Exemplo n.º 7
0
 async def set_preset(self, mode) -> None:
     if mode == "safe":
         code = 0xDE
     elif mode == "comfort":
         code = 0xDB
     elif mode == "day":
         code = 0xDC
     elif mode == "night":
         code = 0xDD
     cls = commandRegistry.get_command(code, self._module.get_type())
     msg = cls(self._address)
     await self._writer(msg)
Exemplo n.º 8
0
 async def _request_channel_name(self) -> None:
     # request the module channel names
     if keys_exists(self._data, "AllChannelStatus"):
         msg = ChannelNameRequestMessage(self._address)
         msg.priority = PRIORITY_LOW
         msg.channels = 0xFF
         await self._writer(msg)
     else:
         msg_type = commandRegistry.get_command(
             CHANNEL_NAME_REQUEST_COMMAND_CODE, self.get_type()
         )
         msg = msg_type(self._address)
         msg.priority = PRIORITY_LOW
         msg.channels = list(range(1, (self.number_of_channels() + 1)))
         await self._writer(msg)
Exemplo n.º 9
0
    async def press(self) -> None:
        """
        Press the button

        :return: None
        """
        _mod_add = self.get_module_address("Button")
        cls = commandRegistry.get_command(0x00, self._module.get_type())
        msg = cls(_mod_add)
        msg.closed = [self._num]
        await self._writer(msg)
        await asyncio.sleep(1)
        msg = cls(_mod_add)
        msg.opened = [self._num]
        await self._writer(msg)
Exemplo n.º 10
0
    async def set_led_state(self, state: str) -> None:
        """
        Set led

        :return: None
        """
        if state == "on":
            code = 0xF6
        elif state == "slow":
            code = 0xF7
        elif state == "fast":
            code = 0xF8
        elif state == "off":
            code = 0xF5
        else:
            return

        _mod_add = self.get_module_address("Button")
        _chn_num = self._num - self._module.calc_channel_offset(_mod_add)
        cls = commandRegistry.get_command(code, self._module.get_type())
        msg = cls(_mod_add)
        msg.leds = [_chn_num]
        await self._writer(msg)
        await self.update({"led_state": state})
Exemplo n.º 11
0
 async def set_temp(self, temp) -> None:
     cls = commandRegistry.get_command(0xE4, self._module.get_type())
     msg = cls(self._address)
     msg.temp = temp * 2
     await self._writer(msg)
Exemplo n.º 12
0
 async def set_position(self, position: int) -> None:
     cls = commandRegistry.get_command(0x1C, self._module.get_type())
     msg = cls(self._address)
     msg.channel = self._num
     msg.position = position
     await self._writer(msg)
Exemplo n.º 13
0
 async def stop(self) -> None:
     cls = commandRegistry.get_command(0x04, self._module.get_type())
     msg = cls(self._address)
     msg.channel = self._num
     await self._writer(msg)