def test_event_priority_override(self): cmd_priorities = {cmd.CommandType.LOGIN: cmd.Priority.CRITICAL} cmd.PRIORITIES = util.merge_dicts(cmd.PRIORITIES, cmd_priorities) command = cmd.Command(cmd.CommandType.LOGIN.value) event = ev.Event(command, {}) self.assertEqual(cmd.Priority.CRITICAL, event.priority)
def test_zone_partition_data_parse(self): command = cmd.Command("601") data = "1001" parsed = dt.parse(command, data) self.assertEqual(parsed, { "partition": "1", "zone": "001", "data": None })
async def _alarm(self, event: ev.Event) -> None: """ Sends a Software Zone Alarm event to the event manager queue if the given event zone is in the list of alarm zones. :param event: Event sent from EVL device """ if event.zone not in self.zones: return if event.partition is not None and event.partition not in self.partitions: return logger.debug("Silent alarm task triggered") command = cmd.Command(cmd.CommandType.SOFTWARE_ZONE_ALARM.value) data = "{zone}".format(zone=event.zone) await self.event_manager.enqueue(command, data)
async def _process(self): """ Processing loop that receives incoming commands and processes as necessary. """ logger.debug("Initiating process loop...") while True: event = await self._recv_queue.get() if not tpi.validate_checksum(event): logger.error("Invalid checksum detected on incoming data!") continue command = cmd.Command(tpi.parse_command(event)) data = tpi.parse_data(event) if (command.command_type == cmd.CommandType.LOGIN and dt.LoginType(data) == dt.LoginType.PASSWORD_REQUEST): logger.debug("Logging in...") await self.send(cmd.CommandType.NETWORK_LOGIN, self.password) elif command.command_type == cmd.CommandType.COMMAND_ACKNOWLEDGE: await self._ack_queue.put(event) else: await self._event_manager.enqueue(command, data)
def test_data_parse(self): command = cmd.Command("510") data = "83" parsed = dt.parse(command, data) self.assertEqual(parsed, {"data": data})