<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _refresh_aldb_records(self, linkcode, address, group):
 """Refresh the IM and device ALDB records."""

        if self.aldb.status in [ALDBStatus.LOADED, ALDBStatus.PARTIAL]:
            for mem_addr in self.aldb:
                rec = self.aldb[mem_addr]
                if linkcode in [0, 1, 3]:
                    if rec.control_flags.is_high_water_mark:
                        _LOGGER.debug('Removing HWM record %04x', mem_addr)
                        self.aldb.pop(mem_addr)
                    elif not rec.control_flags.is_in_use:
                        _LOGGER.debug('Removing not in use record %04x',
                                      mem_addr)
                        self.aldb.pop(mem_addr)
                else:
                    if rec.address == self.address and rec.group == group:
                        _LOGGER.debug('Removing record %04x with addr %s and '
                                      'group %d', mem_addr, rec.address,
                                      rec.group)
                        self.aldb.pop(mem_addr)
            self.read_aldb()